From f6a91254aa85334b8e168f6c34f7e0c7f2a02ab2 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Sat, 9 Oct 2021 18:59:16 +0530 Subject: [PATCH] Docs + search validate updated --- docs/README.md | 4 +++- docs/SoundCloud/README.md | 4 +++- docs/Spotify/README.md | 35 ++++++++++++++++-------------- docs/YouTube/README.md | 4 +++- play-dl/YouTube/utils/extractor.ts | 9 ++++---- play-dl/index.ts | 19 +++++----------- 6 files changed, 37 insertions(+), 38 deletions(-) diff --git a/docs/README.md b/docs/README.md index dcc1c88..75dd14b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,7 +12,7 @@ For source specific commands :- _This checks all type of urls that are supported by play-dl._ -**Returns :** `so_playlist` | `so_track` | `sp_track` | `sp_album` | `sp_playlist` | `yt_video` | `yt_playlist` | `false` +**Returns :** `so_playlist` | `so_track` | `sp_track` | `sp_album` | `sp_playlist` | `yt_video` | `yt_playlist` | `search` | `false` `so` = **SoundCloud** @@ -30,6 +30,8 @@ if(check === 'yt_video') // YouTube Video if(check === 'sp_track') // Spotify Track if(check === 'so_track') // SoundCloud Track + +if(check === "search") // Given term is not a url. Search this term somewhere. ``` ### authorization() diff --git a/docs/SoundCloud/README.md b/docs/SoundCloud/README.md index 47358d3..6b2b2bf 100644 --- a/docs/SoundCloud/README.md +++ b/docs/SoundCloud/README.md @@ -18,7 +18,7 @@ console.log(data.type) // Console logs the type of data that you got. _This checks that given url is soundcloud url or not._ -**Returns :** `track` | `playlist` | `false` +**Returns :** `track` | `playlist` | `search` | `false` ```js let check = await so_validate(url) @@ -26,6 +26,8 @@ let check = await so_validate(url) if(!check) // Invalid SoundCloud URL if(check === 'track') // SoundCloud Track URL + +if(check === "search") // Given term is not a SoundCloud URL. Search this somewhere. ``` ## Classes [ Returned by `soundcloud(url)` function ] diff --git a/docs/Spotify/README.md b/docs/Spotify/README.md index 7f7c6a8..47c353d 100644 --- a/docs/Spotify/README.md +++ b/docs/Spotify/README.md @@ -12,6 +12,25 @@ let data = await spotify(url) //Gets the data console.log(data.type) // Console logs the type of data that you got. ``` + +## Validate + +### sp_validate(url : `string`) + +_This checks that given url is spotify url or not._ + +**Returns :** `track` | `album` | `playlist` | `search` | `false` + +```js +let check = sp_validate(url) + +if(!check) // Invalid Spotify URL + +if(check === 'track') // Spotify Track URL + +if(check === "search") // Given term is a spotify url. Search it somewhere. +``` + ### is_expired() _This tells that whether the access token is expired or not_ @@ -183,19 +202,3 @@ _This will always return as "album" for this class._ ##### toJSON() `function` _converts class into a json format_ - -## Validate - -### sp_validate(url : `string`) - -_This checks that given url is spotify url or not._ - -**Returns :** `track` | `album` | `playlist` | `false` - -```js -let check = sp_validate(url) - -if(!check) // Invalid Spotify URL - -if(check === 'track') // Spotify Track URL -``` diff --git a/docs/YouTube/README.md b/docs/YouTube/README.md index 91164e7..46698b4 100644 --- a/docs/YouTube/README.md +++ b/docs/YouTube/README.md @@ -17,7 +17,7 @@ const results = await youtube.search('post malone sunflower', options); _This will validate url and return type or boolean_ -**Returns :** `video` | `playlist` | `false` +**Returns :** `video` | `playlist` | `search` | `false` ```js let check = yt_validate(url) @@ -27,6 +27,8 @@ if(!check) // Invalid URL if(check === "video") //URL is video url if(check === "playlist") //URL is a playlist url + +if(check === "search") // Given term is not a video ID and PlayList ID. ``` ## Extract ID diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index ebda8d6..d615d45 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -28,11 +28,10 @@ export function yt_validate(url: string): 'playlist' | 'video' | 'search' | fals if (url.indexOf('list=') === -1) { if (url.startsWith('https')) { if (url.match(video_pattern)) { - const id = url.split('v=')[1].split('&')[0] - if(id.match(video_id_pattern)) return "video" - else return false - } - else return false; + const id = url.split('v=')[1].split('&')[0]; + if (id.match(video_id_pattern)) return 'video'; + else return false; + } else return false; } else { if (url.match(video_id_pattern)) return 'video'; else if (url.match(playlist_id_pattern)) return 'playlist'; diff --git a/play-dl/index.ts b/play-dl/index.ts index 825da70..5830fa1 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -91,28 +91,19 @@ export async function stream_from_info( export async function validate( url: string ): Promise< - | 'so_playlist' - | 'so_track' - | 'so_search' - | 'sp_track' - | 'sp_album' - | 'sp_playlist' - | 'sp_search' - | 'yt_video' - | 'yt_playlist' - | 'yt_search' - | false + 'so_playlist' | 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'yt_video' | 'yt_playlist' | 'search' | false > { let check; + if (!url.startsWith('https')) return 'search'; if (url.indexOf('spotify') !== -1) { check = sp_validate(url); - return check !== false ? (('sp_' + check) as 'sp_track' | 'sp_album' | 'sp_playlist' | 'sp_search') : false; + return check !== false ? (('sp_' + check) as 'sp_track' | 'sp_album' | 'sp_playlist') : false; } else if (url.indexOf('soundcloud') !== -1) { check = await so_validate(url); - return check !== false ? (('so_' + check) as 'so_playlist' | 'so_track' | 'so_search') : false; + return check !== false ? (('so_' + check) as 'so_playlist' | 'so_track') : false; } else { check = yt_validate(url); - return check !== false ? (('yt_' + check) as 'yt_video' | 'yt_playlist' | 'yt_search') : false; + return check !== false ? (('yt_' + check) as 'yt_video' | 'yt_playlist') : false; } } /**