Docs and examples updated

This commit is contained in:
killer069
2021-09-21 13:00:38 +05:30
parent c68a57aaf4
commit 3528f89607
14 changed files with 436 additions and 192 deletions

View File

@@ -14,9 +14,11 @@ const results = await youtube.search('post malone sunflower', options);
## Validate
### yt_validate(url : `string`)
*This will validate url and return type or boolean*
_This will validate url and return type or boolean_
**Returns :** `video` | `playlist` | `false`
```js
let check = yt_validate(url)
@@ -30,7 +32,8 @@ if(check === "playlist") //URL is a playlist url
## Extract ID
### extractID(url : `string`)
*This will return videoID or playlistID from a url*
_This will return videoID or playlistID from a url_
**Note :** URL like [this](https://www.youtube.com/watch?v=E2gHczUOCGI&list=PLUt3leKZfbZqLzLwcQMYPBdbe7i7KRCOP&index=2) will return a playlist ID only.
@@ -38,42 +41,11 @@ if(check === "playlist") //URL is a playlist url
let id = extractID(url)
```
## Stream
### stream(url : `string`, cookie? : `string`)
*This is basic to create a youtube stream from a url or videoID.*
**[Cookies](https://github.com/play-dl/play-dl/discussions/34) are optional and are required for playing age restricted videos.**
```js
let source = await stream("url") // This will create a stream Class which contains type and stream to be played.
let resource = createAudioResource(source.stream, {
inputType : source.type
}) // This creates resource for playing
```
### stream_from_info(info : `infoData`, cookie? : `string`)
*This is basic to create a youtube stream from a info [ from [video_info](https://github.com/play-dl/play-dl#video_infourl--string) function ].*
**[Cookies](https://github.com/play-dl/play-dl/discussions/34) are optional and are required for playing age restricted videos.**
**Note :** Here, cookies are required only for retrying purposes.
```js
let info = await video_info("url")
let source = await stream_from_info(info) // This will create a stream Class which contains type and stream to be played.
/* OR
let source = await stream_from_info(info, cookie) This will create a stream Class which contains type and stream to be played and also give cookies if retrying.
*/
let resource = createAudioResource(source.stream, {
inputType : source.type
}) // This creates resource for playing
```
## Search
### search(url : `string`, options? : [SearchOptions](https://github.com/play-dl/play-dl/tree/main/play-dl/YouTube#searchoptions))
*This enables all searching mechanism (video, channel, playlist)*
_This enables all searching mechanism (video, channel, playlist)_
```js
const options = {
@@ -83,46 +55,49 @@ const results = await youtube.search('never gonna give you up', options);
console.log(results[0].url);
```
- #### SearchOptions
- *type* : `video` | `channel` | `playlist`
- *limit* : `integer`
- #### SearchOptions
- _type_ : `video` | `channel` | `playlist`
- _limit_ : `integer`
## Video
### video_basic_info(url : `string`, cookie? : `string`)
*The basic video details `play-dl` fetches at first from url or videoID.*
_The basic video details `play-dl` fetches at first from url or videoID._
**[Cookies](https://github.com/play-dl/play-dl/discussions/34) are optional and are required for playing age restricted videos.**
```js
const video = await video_basic_info(url)
```
### video_info(url : `string`, cookie? : `string`)
*This contains everything with deciphered formats along with `video_details`. It can fetech data from url or videoID.*
_This contains everything with deciphered formats along with `video_details`. It can fetech data from url or videoID._
**[Cookies](https://github.com/play-dl/play-dl/discussions/34) are optional and are required for playing age restricted videos.**
```js
const video = await video_info(url)
```
- #### format `property`
*This returns all the formats available for a video.*
```js
const video = await video_info(url)
console.log(video.format)
```
- #### format `property`
_This returns all the formats available for a video._
```js
const video = await video_info(url)
console.log(video.format)
```
## Playlist
### playlist_info(url : `string`, parseIncomplete : `boolean`)
*This fetches all details about a playlist from a url or playlistID.*
_This fetches all details about a playlist from a url or playlistID._
**parseIncomplete** is optional parameter if you want to parse playlist with hidden videos.
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist
@@ -131,77 +106,82 @@ const playlist = await playlist_info(url, true)
//This only fetches first 100 videos from a playlist and also parses playlist with hidden videos
```
- #### fetch() `method`
*This fetches and returns all videos from the whole provided playlist .*
- #### fetch() `method`
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist
await playlist.fetch()
// This one fetches all videos from a playlist.
```
_This fetches and returns all videos from the whole provided playlist ._
- #### page(page_number : `number`)
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist
*This returns no. of videos from a page.*
await playlist.fetch()
// This one fetches all videos from a playlist.
```
> Every 100 videos have been divided into pages.
> Example: There are 782 videos in a playlist, so there will be 8 pages.
- #### page(page_number : `number`)
```js
const playlist = await playlist_info(url);
// This only fetches first 100 videos from a playlist.
await playlist.fetch();
// This one fetches all videos from a playlist.
console.log(playlist.page(1));
// This displays first 100 videos of a playlist
_This returns no. of videos from a page._
- #### total_pages `property`
*This returns total no. of pages that have been fetched so far.*
> Every 100 videos have been divided into pages.
> Example: There are 782 videos in a playlist, so there will be 8 pages.
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.total_pages)
// This displays total no. of pages fetched so far.
```js
const playlist = await playlist_info(url);
// This only fetches first 100 videos from a playlist.
for(let i = 1; i <= playlist.total_pages; i++){
queue.push(...playlist.page(i))
} // This will push every video in that playlist to your queue
```
await playlist.fetch();
// This one fetches all videos from a playlist.
- #### total_videos `property`
*This returns total no. of videos that have been fetched so far.*
console.log(playlist.page(1));
// This displays first 100 videos of a playlist
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.total_videos)
// This displays total no. of videos fetched so far.
```
```
- #### videoCount `property`
- #### total_pages `property`
*This returns total no. of videos in the provided playlist.*
_This returns total no. of pages that have been fetched so far._
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.videoCount)
// This displays total no. of videos in a playlist.
```
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.total_pages)
// This displays total no. of pages fetched so far.
for(let i = 1; i <= playlist.total_pages; i++){
queue.push(...playlist.page(i))
} // This will push every video in that playlist to your queue
```
- #### total_videos `property`
_This returns total no. of videos that have been fetched so far._
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.total_videos)
// This displays total no. of videos fetched so far.
```
- #### videoCount `property`
_This returns total no. of videos in the provided playlist._
```js
const playlist = await playlist_info(url)
//This only fetches first 100 videos from a playlist.
await playlist.fetch()
// This one fetches all videos from a playlist.
console.log(playlist.videoCount)
// This displays total no. of videos in a playlist.
```