6
6
getBuffer,
7
7
toAudio,
8
8
getJson,
9
+ validateQuality,
9
10
} = require ( "../../lib" ) ;
10
11
const { yta, ytv, ytsdl } = require ( "../../lib/ytdl" ) ;
11
12
@@ -35,7 +36,6 @@ command(
35
36
} ,
36
37
"audio"
37
38
) ;
38
-
39
39
}
40
40
) ;
41
41
@@ -47,9 +47,29 @@ command(
47
47
} ,
48
48
async ( message , match ) => {
49
49
match = match || message . reply_message . text ;
50
- if ( ! match ) return await message . reply ( "Give me a youtube link" ) ;
51
- if ( ! isUrl ( match ) ) return await message . reply ( "Give me a youtube link" ) ;
52
- let { dlink, title } = await ytv ( match , "360p" ) ;
50
+ let url = getUrl ( match ) [ 0 ] ;
51
+ if ( ! url )
52
+ return await message . reply (
53
+ "Give me a youtube link\n\nExample: ytv youtube.com/watch?v=xxxxx 480p"
54
+ ) ;
55
+ let quality = match . split ( ";" ) [ 1 ] ;
56
+ if ( quality && ! validateQuality ( quality ) ) {
57
+ return await message . reply (
58
+ "Invalid Resolution \nSupported: 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p"
59
+ ) ;
60
+ } else if ( ! quality ) quality = "360p" ;
61
+ if ( ! match )
62
+ return await message . reply (
63
+ "Give me a youtube link\n\nExample: ytv youtube.com/watch?v=xxxxx 480p"
64
+ ) ;
65
+ if ( ! isUrl ( match ) )
66
+ return await message . reply (
67
+ "Give me a youtube link\n\nExample: ytv youtube.com/watch?v=xxxxx 480p"
68
+ ) ;
69
+ let requrl = `https://api.thexapi.xyz/api/v1/download/youtube/video?url=${ url } &quality=${ quality } ` ;
70
+ let response = ( await getJson ( requrl ) ) . data ;
71
+ const { dlink, title } = response ;
72
+ console . log ( response ) ;
53
73
await message . reply ( `_Downloading ${ title } _` ) ;
54
74
return await message . sendMessage (
55
75
message . jid ,
0 commit comments