2021-09-05 18:50:57 +05:30
# Play-dl commands
For source specific commands :-
2021-09-21 13:00:38 +05:30
- [YouTube ](https://github.com/play-dl/play-dl/tree/main/docs/YouTube#youtube )
- [Spotify ](https://github.com/play-dl/play-dl/tree/main/docs/Spotify#spotify )
2021-09-21 14:52:58 +05:30
- [SoundCloud ](https://github.com/play-dl/play-dl/tree/main/docs/SoundCloud )
2021-09-05 18:50:57 +05:30
### Validate
#### validate(url : `string`)
2021-09-21 13:00:38 +05:30
_This checks all type of urls that are supported by play-dl._
2021-10-31 16:26:36 +01:00
**Returns :** `so_playlist` | `so_track` | `sp_track` | `sp_album` | `sp_playlist` | `dz_track` | `dz_playlist` | `dz_album` | `yt_video` | `yt_playlist` | `search` | `false`
2021-09-21 13:00:38 +05:30
`so` = **SoundCloud**
2021-09-05 18:50:57 +05:30
2021-09-21 13:00:38 +05:30
`sp` = **Spotify**
`yt` = **YouTube**
2021-09-05 18:50:57 +05:30
2021-10-27 22:09:53 +02:00
`dz` = **Deezer**
2021-09-05 18:50:57 +05:30
```js
2021-09-21 13:00:38 +05:30
let check = await validate(url)
2021-09-05 18:50:57 +05:30
if(!check) // Invalid URL
if(check === 'yt_video') // YouTube Video
if(check === 'sp_track') // Spotify Track
2021-09-21 13:00:38 +05:30
if(check === 'so_track') // SoundCloud Track
2021-10-09 18:59:16 +05:30
2021-10-27 22:09:53 +02:00
if(check === 'dz_track') // Deezer Track
2021-10-09 18:59:16 +05:30
if(check === "search") // Given term is not a url. Search this term somewhere.
2021-09-21 13:00:38 +05:30
```
### authorization()
2021-10-08 15:05:25 +05:30
_This creates basic spotify / soundcloud / youtube data to be stored locally._
2021-09-21 13:00:38 +05:30
```js
authorization() //After then you will be asked about type of data you want to create and then follow the steps properly.
```
2021-10-12 14:09:14 +05:30
### setToken(options : `TokenOptions`)
_This sets token without using file._
```js
setToken({
spotify : {
2021-10-13 17:34:42 +05:30
client_id : "ID",
client_secret : "Secret",
refresh_token : "Token",
2021-10-12 14:09:14 +05:30
market : "Country Code"
}
}) // Setting Spotify Token [ To get refresh_token, just run through authorization, and set file save to No ]
setToken({
soundcloud : {
client_id : "ID"
}
}) // Setting SoundCloud Token
setToken({
youtube : {
cookie : "Cookies"
}
}) // Warning : Using setToken for youtube cookies will only update cookies present in memory only.
```
2021-09-24 15:13:45 +05:30
### Search
#### SearchOptions :
- limit : `number` :- Sets total amount of results you want.
- source : {
youtube: `video` | `playlist` | `channel` ;
spotify: `album` | `playlist` | `track` ;
soundcloud: `tracks` | `playlists` | `albums` ;
2021-10-27 22:09:53 +02:00
deezer: `track` | `playlist` | `album` ;
2021-09-24 15:13:45 +05:30
}
2021-09-24 15:27:12 +05:30
#### search(query : `string`, options? : [`SearchOptions`](https://github.com/play-dl/play-dl/tree/main/docs#searchoptions-))
2021-09-24 15:13:45 +05:30
_This is basic to search with any source._
2021-09-24 16:02:03 +05:30
**NOTE :-** If options.source is not specified, then it will default to youtube video search.
2021-09-24 15:13:45 +05:30
```js
2021-09-24 16:02:03 +05:30
let data = await search('Rick Roll', { limit : 1 }) // Searches for youtube video
2021-09-24 18:13:30 +05:30
let data = await search('Rick Roll', { limit : 1, source : { youtube : "video" } }) // Searches for youtube video
2021-09-24 15:13:45 +05:30
2021-09-24 18:13:30 +05:30
let data = await search('Rick Roll', { limit: 1, source : { spotify : "track" } }) // Searches for spotify track.
2021-09-24 15:13:45 +05:30
2021-09-24 18:13:30 +05:30
let data = await search('Rick Roll', { limit: 1, source : { soundcloud : "tracks" } }) // Searches for soundcloud track.
2021-10-27 22:09:53 +02:00
let data = await search('Rick Roll', { limit: 1, source : { deezer : "track" } }) // Searches for a Deezer track.
2021-09-24 15:13:45 +05:30
```
2021-09-21 13:00:38 +05:30
### Stream
2021-10-08 15:05:25 +05:30
**Attaching events to player is important for stream to work.**
2021-10-27 22:09:53 +02:00
#### attachListeners(player : `AudioPlayer`, resource : `YouTubeStream | SoundCloudStream`)
2021-10-08 15:05:25 +05:30
_This is used for attaching pause and playing events to audioPlayer._
```js
let resource = await stream("url")
let player = createAudioPlayer()
attachListeners(player, resource)
```
2021-09-24 15:13:45 +05:30
#### StreamOptions :
2021-09-21 13:00:38 +05:30
2021-09-24 12:49:39 +05:30
- quality : `number` :- Sets quality of stream [ 0 = Lowest, 1 = Medium ]. Leave this empty to get highest audio quality.
2021-09-28 21:25:41 +05:30
- proxy : `Proxy` :- Optional parameter to add support of proxies. As of now, HTTPS proxies are only supported. So make sure to get HTTPS proxies only.
2021-09-24 12:49:39 +05:30
2021-09-24 15:27:12 +05:30
#### stream(url : `string`, options? : [`StreamOptions`](https://github.com/play-dl/play-dl/tree/main/docs#streamoptions-))
2021-09-21 13:00:38 +05:30
2021-09-24 12:49:39 +05:30
_This is basic to create a stream from a youtube or soundcloud url._
2021-09-21 13:00:38 +05:30
```js
2021-09-24 15:56:30 +05:30
let source = await stream("url") // This will create a stream Class. Highest Quality
let source = await stream("url", { quality : 0 }) // Lowest quality
let source = await stream("url", { quality : 1 }) // Next to Lowest quality.
2021-10-01 12:50:40 +05:30
let source = await stream(url, { proxy : ['url'] }) // Accepts a url which has port in it.
2021-09-28 21:25:41 +05:30
let source = await stream(url. {proxy : [{
host : "IP or hostname",
port : 8080
}]
}) // Or add a json containing hostname and port.
2021-09-21 22:04:45 +05:30
let resource = createAudioResource(source.stream, {
2021-09-21 13:00:38 +05:30
inputType : source.type
}) // This creates resource for playing
```
2021-09-24 15:27:12 +05:30
#### stream_from_info(info : `infoData`, options? : [`StreamOptions`](https://github.com/play-dl/play-dl/tree/main/docs#streamoptions-))
2021-09-21 13:00:38 +05:30
2021-09-24 15:27:12 +05:30
_This is basic to create a stream from a info [ from [video_info ](https://github.com/play-dl/play-dl#video_infourl--string ) function or [soundcloud ](https://github.com/play-dl/play-dl/tree/main/docs/SoundCloud#soundcloudurl--string ) function [**Only SoundCloudTrack class is allowed**] ]._
2021-09-21 13:00:38 +05:30
**Note :** Here, cookies are required only for retrying purposes.
```js
2021-09-24 15:56:30 +05:30
let source = await stream_from_info(info) // This will create a stream Class from video_info or SoundCoudTrack Class. Highest Quality
2021-09-28 21:25:41 +05:30
2021-09-24 15:56:30 +05:30
let source = await stream_from_info(info, { quality : 0 }) // Lowest quality
2021-09-21 22:04:45 +05:30
2021-09-24 15:56:30 +05:30
let source = await stream_from_info(info, { quality : 1 }) // Next to Lowest quality.
2021-09-24 15:14:49 +05:30
2021-10-01 12:50:40 +05:30
let source = await stream_from_info(info, { proxy : ['url'] }) // Accepts a url which has port in it.
2021-09-28 21:25:41 +05:30
2021-10-01 12:48:33 +05:30
let source = await stream_from_info(info, {proxy : [{
2021-09-28 21:25:41 +05:30
host : "IP or hostname",
port : 8080
}]
}) // Or add a json containing hostname and port.
let resource = createAudioResource(source.stream, {
2021-09-21 13:00:38 +05:30
inputType : source.type
}) // This creates resource for playing
2021-09-05 18:54:16 +05:30
```
2021-11-01 15:32:51 +05:30
#### cookieHeaders(headersCookie : `string[]`)
_This is function to update youtube cookies when using external https module._
```js
const res = ... // You need to get response.
play.cookieHeaders(res.headers['set-cookie']) // Updates YouTube Cookies if cookies exists.
```