MCPcopy
hub / github.com/eritislami/evobot / from

Method from

structs/Song.ts:25–61  ·  view source on GitHub ↗
(url: string = "", search: string = "")

Source from the content-addressed store, hash-verified

23 }
24
25 public static async from(url: string = "", search: string = "") {
26 const isYoutubeUrl = videoPattern.test(url);
27
28 let songInfo;
29
30 if (isYoutubeUrl) {
31 songInfo = await video_basic_info(url);
32
33 return new this({
34 url: songInfo.video_details.url,
35 title: songInfo.video_details.title,
36 duration: parseInt(songInfo.video_details.durationInSec)
37 });
38 } else {
39 const result = await youtube.searchOne(search);
40
41 result ? null : console.log(`No results found for ${search}`);
42
43 if (!result) {
44 let err = new Error(`No search results found for ${search}`);
45
46 err.name = "NoResults";
47
48 if (isURL.test(url)) err.name = "InvalidURL";
49
50 throw err;
51 }
52
53 songInfo = await video_basic_info(`https://youtube.com/watch?v=${result.id}`);
54
55 return new this({
56 url: songInfo.video_details.url,
57 title: songInfo.video_details.title,
58 duration: parseInt(songInfo.video_details.durationInSec)
59 });
60 }
61 }
62
63 public async makeResource(): Promise<AudioResource<Song> | void> {
64 let playStream;

Callers 2

executeFunction · 0.45
executeFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected