Docs + search validate updated
This commit is contained in:
parent
6698a87983
commit
f6a91254aa
@ -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()
|
||||
|
||||
@ -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 ]
|
||||
|
||||
@ -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
|
||||
```
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
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';
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user