commit
ba4979dd94
@ -29,4 +29,6 @@ import * as play from 'play-dl' // ES-6 import or TS import
|
||||
const play = require('play-dl') //JS importing
|
||||
```
|
||||
|
||||
## [Documentation](https://play-dl.github.io/modules.html)
|
||||
### [Documentation](https://play-dl.github.io/modules.html)
|
||||
### [Examples](./examples)
|
||||
### [Instructions](./instructions)
|
||||
|
||||
@ -1,56 +0,0 @@
|
||||
const https = require('https')
|
||||
const play = require('play-dl');
|
||||
|
||||
(async() => {
|
||||
let data = await request('https://soundcloud.com/')
|
||||
let splitted = data.split('<script crossorigin src="')
|
||||
let urls = []
|
||||
splitted.forEach((r) => {
|
||||
if(r.startsWith('https')) {
|
||||
urls.push(r.split('"')[0])
|
||||
}
|
||||
})
|
||||
let data2 = await request(urls[urls.length - 1])
|
||||
let client_id = data2.split(',client_id:"')[1].split('"')[0]
|
||||
console.log('Free SoundCloud Client ID : ' + client_id)
|
||||
play.authorization()
|
||||
})();
|
||||
|
||||
function https_getter(req_url, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const s = new URL(req_url);
|
||||
options.method ??= 'GET';
|
||||
const req_options = {
|
||||
host: s.hostname,
|
||||
path: s.pathname + s.search,
|
||||
headers: options.headers ?? {},
|
||||
method: options.method
|
||||
};
|
||||
|
||||
const req = https.request(req_options, resolve);
|
||||
req.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
if (options.method === 'POST') req.write(options.body);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function request(url, options){
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let data = '';
|
||||
let res = await https_getter(url, options).catch((err) => err);
|
||||
if (res instanceof Error) {
|
||||
reject(res);
|
||||
return;
|
||||
}
|
||||
if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) {
|
||||
res = await https_getter(res.headers.location, options);
|
||||
} else if (Number(res.statusCode) > 400) {
|
||||
reject(new Error(`Got ${res.statusCode} from the request`));
|
||||
}
|
||||
res.setEncoding('utf-8');
|
||||
res.on('data', (c) => (data += c));
|
||||
res.on('end', () => resolve(data));
|
||||
});
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
const { authorization } = require('play-dl');
|
||||
|
||||
authorization()
|
||||
78
instructions/README.md
Normal file
78
instructions/README.md
Normal file
@ -0,0 +1,78 @@
|
||||
|
||||
## YouTube Cookies
|
||||
|
||||
Steps : -
|
||||
|
||||
- Open your browser, then open dev-tools [ Option + ⌘ + J (on macOS), or Shift + CTRL + J (on Windows/Linux). ]
|
||||
|
||||
- Then go to Network Tab
|
||||

|
||||
|
||||
- Go to any YouTube URL and find the first request and open it
|
||||
First Request :-
|
||||

|
||||
|
||||
**The first request would be watch?v="Your video ID"**
|
||||
|
||||
- Now go to Request Headers
|
||||

|
||||
|
||||
- find cookie in request headers
|
||||

|
||||
|
||||
- Now just create a new file with this code :
|
||||
```ts
|
||||
const play = require('play-dl');
|
||||
|
||||
play.authorization();
|
||||
```
|
||||
And run this file. You will get a interface asking some question.
|
||||
|
||||
## Spotify
|
||||
|
||||
1. Go to [ Spotify Dashboard ](https://developer.spotify.com/dashboard/login) and create a new application or use old one.
|
||||

|
||||
|
||||
2. Open that application. You will be given 2 things [ Client ID and Client Secret ( click on `Show Client Secret` to get info ) ]. Note these 2 things somewhere.
|
||||
|
||||
3. Click on Edit Settings and go to Redirect URIs
|
||||

|
||||
|
||||
4. Add this Redirect URI : `http://127.0.0.1/index.html` or any url according to you. [ Also note this somewhere ]
|
||||
|
||||
5. Now create a `authorize.js` file and add this code :
|
||||
```ts
|
||||
const play = require('play-dl');
|
||||
|
||||
play.authorization();
|
||||
```
|
||||
and run it `node authorize.js`
|
||||
|
||||
6. You will be asked :-
|
||||
- Saving INFO in file or not. [ If selected no, you will have to use `setToken` function after you get refresh-Token ]
|
||||
- Client ID
|
||||
- Client Secret
|
||||
- Redirect URI or Redirect URL
|
||||
- Market [ Choose 2 letter code on left side of your country name from [url](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) ]
|
||||
- You will be given a link for authorizing. Just paste it in your browser and click on authorize and copy the link that you are redirected to. [ Redirected Link should start with Redirect URI / Redirect URL that you have provided ]
|
||||
- Paste the url in Redirected URL
|
||||
|
||||
7. You have completed Authorization part. Now you can delete authorize js file.
|
||||
|
||||
You will notice that a folder named `.data` has been created. **Do not delete this**, this contains all your spotify data. [ Only applicable if save in file is set to yes. ]
|
||||
|
||||
## SoundCloud
|
||||
|
||||
## Getting Free Client ID
|
||||
|
||||
``` ts
|
||||
const play = require('play-dl')
|
||||
|
||||
play.getFreeClientID().then((clientID) => {
|
||||
play.setToken({
|
||||
soundcloud : {
|
||||
client_id : clientID
|
||||
}
|
||||
})
|
||||
})
|
||||
```
|
||||
@ -256,4 +256,4 @@ export async function dz_advanced_track_search(options: DeezerAdvancedSearchOpti
|
||||
return results;
|
||||
}
|
||||
|
||||
export { DeezerTrack, DeezerAlbum, DeezerPlaylist }
|
||||
export { DeezerTrack, DeezerAlbum, DeezerPlaylist };
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from "./classes";
|
||||
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from './classes';
|
||||
|
||||
export interface SoundTrackJSON {
|
||||
/**
|
||||
|
||||
@ -192,4 +192,4 @@ export function setSoundCloudToken(options: SoundDataOptions) {
|
||||
soundData = options;
|
||||
}
|
||||
|
||||
export { SoundCloudTrack, SoundCloudPlaylist, SoundCloudStream }
|
||||
export { SoundCloudTrack, SoundCloudPlaylist, SoundCloudStream };
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes'
|
||||
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes';
|
||||
|
||||
export interface TrackJSON {
|
||||
/**
|
||||
|
||||
@ -243,4 +243,4 @@ export function setSpotifyToken(options: SpotifyDataOptions) {
|
||||
refreshToken();
|
||||
}
|
||||
|
||||
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist }
|
||||
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist };
|
||||
|
||||
@ -60,7 +60,7 @@ export class YouTubeChannel {
|
||||
this.artist = !!data.artist || false;
|
||||
this.id = data.id || null;
|
||||
this.url = data.url || null;
|
||||
this.icons = data.icon || [{ url: null, width: 0, height: 0 }];
|
||||
this.icons = data.icons || [{ url: null, width: 0, height: 0 }];
|
||||
this.subscribers = data.subscribers || null;
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ export class YouTubePlayList {
|
||||
/**
|
||||
* YouTube Playlist thumbnail Data
|
||||
*/
|
||||
thumbnail?: YouTubeThumbnail
|
||||
thumbnail?: YouTubeThumbnail;
|
||||
/**
|
||||
* Videos array containing data of first 100 videos
|
||||
*/
|
||||
@ -289,5 +289,5 @@ interface PlaylistJSON{
|
||||
/**
|
||||
* first 100 videos in that playlist
|
||||
*/
|
||||
videos? : YouTubeVideo[]
|
||||
videos?: YouTubeVideo[];
|
||||
}
|
||||
@ -5,10 +5,10 @@ export class YouTubeThumbnail {
|
||||
height: number;
|
||||
|
||||
constructor(data: any) {
|
||||
this.id = data.id
|
||||
this.url = data.url
|
||||
this.width = data.width
|
||||
this.height = data.height
|
||||
this.id = data.id;
|
||||
this.url = data.url;
|
||||
this.width = data.width;
|
||||
this.height = data.height;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
@ -17,6 +17,6 @@ export class YouTubeThumbnail {
|
||||
url: this.url,
|
||||
width: this.width,
|
||||
height: this.height
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
export { stream, stream_from_info, YouTubeStream } from './stream';
|
||||
export * from './utils';
|
||||
export { YouTube } from './search';
|
||||
export { cookieHeaders } from './utils/cookie';
|
||||
export { YouTubeVideo } from './classes/Video'
|
||||
export { YouTubePlayList } from './classes/Playlist'
|
||||
export { YouTubeChannel } from './classes/Channel'
|
||||
export { YouTubeVideo } from './classes/Video';
|
||||
export { YouTubePlayList } from './classes/Playlist';
|
||||
export { YouTubeChannel } from './classes/Channel';
|
||||
|
||||
@ -1,29 +1,29 @@
|
||||
import { YouTubeVideo } from "../classes/Video";
|
||||
import { YouTubeVideo } from '../classes/Video';
|
||||
|
||||
export interface LiveStreamData {
|
||||
isLive: boolean;
|
||||
dashManifestUrl: string | null
|
||||
hlsManifestUrl: string | null
|
||||
dashManifestUrl: string | null;
|
||||
hlsManifestUrl: string | null;
|
||||
}
|
||||
|
||||
export interface formatData {
|
||||
itag: number;
|
||||
mimeType: string
|
||||
bitrate: number
|
||||
width: number
|
||||
height: number
|
||||
lastModified: string
|
||||
contentLength: string
|
||||
quality: string
|
||||
fps: number
|
||||
qualityLabel: string
|
||||
projectionType: string
|
||||
averageBitrate: number
|
||||
audioQuality: string
|
||||
approxDurationMs: string
|
||||
audioSampleRate: string
|
||||
audioChannels: number
|
||||
url : string
|
||||
mimeType: string;
|
||||
bitrate: number;
|
||||
width: number;
|
||||
height: number;
|
||||
lastModified: string;
|
||||
contentLength: string;
|
||||
quality: string;
|
||||
fps: number;
|
||||
qualityLabel: string;
|
||||
projectionType: string;
|
||||
averageBitrate: number;
|
||||
audioQuality: string;
|
||||
approxDurationMs: string;
|
||||
audioSampleRate: string;
|
||||
audioChannels: number;
|
||||
url: string;
|
||||
signatureCipher: string;
|
||||
cipher: string;
|
||||
loudnessDb: number;
|
||||
@ -31,9 +31,9 @@ export interface formatData {
|
||||
}
|
||||
|
||||
export interface InfoData {
|
||||
LiveStreamData : LiveStreamData
|
||||
html5player : string
|
||||
format : Partial<formatData>[]
|
||||
video_details : YouTubeVideo
|
||||
related_videos: string[]
|
||||
LiveStreamData: LiveStreamData;
|
||||
html5player: string;
|
||||
format: Partial<formatData>[];
|
||||
video_details: YouTubeVideo;
|
||||
related_videos: string[];
|
||||
}
|
||||
@ -46,6 +46,7 @@ export function setCookieToken(options: { cookie: string }) {
|
||||
youtubeData = { cookie };
|
||||
youtubeData.file = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates cookies locally either in file or in memory.
|
||||
*
|
||||
|
||||
@ -147,11 +147,10 @@ export async function video_basic_info(url: string, options: InfoOptions = {}) :
|
||||
player_response.playabilityStatus.errorScreen.playerKavRenderer?.reason.simpleText
|
||||
}`
|
||||
);
|
||||
const ownerInfo = initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer
|
||||
?.owner?.videoOwnerRenderer
|
||||
const badge =
|
||||
ownerInfo?.badges &&
|
||||
ownerInfo?.badges[0];
|
||||
const ownerInfo =
|
||||
initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer
|
||||
?.owner?.videoOwnerRenderer;
|
||||
const badge = ownerInfo?.badges && ownerInfo?.badges[0];
|
||||
const html5player = `https://www.youtube.com${body.split('"jsUrl":"')[1].split('"')[0]}`;
|
||||
const related: string[] = [];
|
||||
initial_response.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results.forEach(
|
||||
|
||||
234
play-dl/index.ts
234
play-dl/index.ts
@ -7,14 +7,38 @@ export {
|
||||
extractID,
|
||||
YouTube,
|
||||
YouTubeStream,
|
||||
cookieHeaders,
|
||||
YouTubeChannel,
|
||||
YouTubePlayList,
|
||||
YouTubeVideo
|
||||
} from './YouTube';
|
||||
export { spotify, sp_validate, refreshToken, is_expired, SpotifyAlbum, SpotifyPlaylist, SpotifyTrack, Spotify } from './Spotify';
|
||||
export { soundcloud, so_validate, SoundCloud, SoundCloudStream, getFreeClientID, SoundCloudPlaylist, SoundCloudTrack } from './SoundCloud';
|
||||
export { deezer, dz_validate, dz_advanced_track_search, Deezer, DeezerTrack, DeezerPlaylist, DeezerAlbum } from './Deezer';
|
||||
export {
|
||||
spotify,
|
||||
sp_validate,
|
||||
refreshToken,
|
||||
is_expired,
|
||||
SpotifyAlbum,
|
||||
SpotifyPlaylist,
|
||||
SpotifyTrack,
|
||||
Spotify
|
||||
} from './Spotify';
|
||||
export {
|
||||
soundcloud,
|
||||
so_validate,
|
||||
SoundCloud,
|
||||
SoundCloudStream,
|
||||
getFreeClientID,
|
||||
SoundCloudPlaylist,
|
||||
SoundCloudTrack
|
||||
} from './SoundCloud';
|
||||
export {
|
||||
deezer,
|
||||
dz_validate,
|
||||
dz_advanced_track_search,
|
||||
Deezer,
|
||||
DeezerTrack,
|
||||
DeezerPlaylist,
|
||||
DeezerAlbum
|
||||
} from './Deezer';
|
||||
export { setToken } from './token';
|
||||
|
||||
enum AudioPlayerStatus {
|
||||
@ -63,10 +87,25 @@ import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './Spotify/classes';
|
||||
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes';
|
||||
|
||||
/**
|
||||
* Main stream Command for streaming through various sources
|
||||
* @param url The video / track url to make stream of
|
||||
* @param options contains quality, cookie and proxy to set for stream
|
||||
* @returns YouTube / SoundCloud Stream to play
|
||||
* Creates a Stream [ YouTube or SoundCloud ] class from a url for playing.
|
||||
*
|
||||
* Example
|
||||
* ```ts
|
||||
* const source = await play.stream('youtube video URL') // YouTube Video Stream
|
||||
*
|
||||
* const source = await play.stream('soundcloud track URL') // SoundCloud Track Stream
|
||||
*
|
||||
* const resource = createAudioResource(source.stream, {
|
||||
* inputType : source.type
|
||||
* }) // Use discordjs voice createAudioResource function.
|
||||
* ```
|
||||
* @param url Video / Track URL
|
||||
* @param options
|
||||
*
|
||||
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
|
||||
* - `Proxy[]` proxy : sends data through a proxy
|
||||
* - `boolean` htmldata : given data is html data or not
|
||||
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
|
||||
*/
|
||||
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> {
|
||||
if (url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.');
|
||||
@ -85,26 +124,113 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Search Command for searching through various sources
|
||||
* Searches through a particular source and gives respective info.
|
||||
*
|
||||
* Example
|
||||
* ```ts
|
||||
* const searched = await play.search('Rick Roll', { source : { youtube : "video" } }) // YouTube Video Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { limit : 1 }) // YouTube Video Search but returns only 1 video.
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { spotify : "track" } }) // Spotify Track Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { soundcloud : "tracks" } }) // SoundCloud Track Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { deezer : "track" } }) // Deezer Track Search
|
||||
* ```
|
||||
* @param query string to search.
|
||||
* @param options contains limit and source to choose.
|
||||
* @returns Array of YouTube or Spotify or SoundCloud or Deezer
|
||||
deezer?: 'track' | 'playlist' | 'album';
|
||||
* @param options
|
||||
*
|
||||
* - `number` limit : No of searches you want to have.
|
||||
* - `boolean` fuzzy : Whether the search should be fuzzy or only return exact matches. Defaults to `true`. [ for `Deezer` Only ]
|
||||
* - `Object` source : Contains type of source and type of result you want to have
|
||||
* ```ts
|
||||
* - youtube : 'video' | 'playlist' | 'channel';
|
||||
- spotify : 'album' | 'playlist' | 'track';
|
||||
- soundcloud : 'tracks' | 'playlists' | 'albums';
|
||||
- deezer : 'track' | 'playlist' | 'album';
|
||||
```
|
||||
* @returns Array of {@link YouTube} or {@link Spotify} or {@link SoundCloud} or {@link Deezer} type
|
||||
*/
|
||||
export async function search( query: string, options: { source : { deezer : "album" } } & SearchOptions) : Promise<DeezerAlbum[]>;
|
||||
export async function search( query: string, options: { source : { deezer : "playlist" } } & SearchOptions) : Promise<DeezerPlaylist[]>;
|
||||
export async function search( query: string, options: { source : { deezer : "track" } } & SearchOptions) : Promise<DeezerTrack[]>;
|
||||
export async function search( query: string, options: { source : { soundcloud : "albums" } } & SearchOptions) : Promise<SoundCloudPlaylist[]>;
|
||||
export async function search( query: string, options: { source : { soundcloud : "playlists" } } & SearchOptions) : Promise<SoundCloudPlaylist[]>;
|
||||
export async function search( query: string, options: { source : { soundcloud : "tracks" } } & SearchOptions) : Promise<SoundCloudTrack[]>;
|
||||
export async function search( query: string, options: { source : { spotify : "album" } } & SearchOptions) : Promise<SpotifyAlbum[]>;
|
||||
export async function search( query: string, options: { source : { spotify : "playlist" } } & SearchOptions) : Promise<SpotifyPlaylist[]>;
|
||||
export async function search( query: string, options: { source : { spotify : "track" } } & SearchOptions) : Promise<SpotifyTrack[]>;
|
||||
export async function search( query: string, options: { source : { youtube : "channel" } } & SearchOptions) : Promise<YouTubeChannel[]>;
|
||||
export async function search( query: string, options: { source : { youtube : "playlist" } } & SearchOptions) : Promise<YouTubePlayList[]>;
|
||||
export async function search( query: string, options: { source : { youtube : "video" } } & SearchOptions) : Promise<YouTubeVideo[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { deezer: 'album' } } & SearchOptions
|
||||
): Promise<DeezerAlbum[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { deezer: 'playlist' } } & SearchOptions
|
||||
): Promise<DeezerPlaylist[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { deezer: 'track' } } & SearchOptions
|
||||
): Promise<DeezerTrack[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { soundcloud: 'albums' } } & SearchOptions
|
||||
): Promise<SoundCloudPlaylist[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { soundcloud: 'playlists' } } & SearchOptions
|
||||
): Promise<SoundCloudPlaylist[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { soundcloud: 'tracks' } } & SearchOptions
|
||||
): Promise<SoundCloudTrack[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { spotify: 'album' } } & SearchOptions
|
||||
): Promise<SpotifyAlbum[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { spotify: 'playlist' } } & SearchOptions
|
||||
): Promise<SpotifyPlaylist[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { spotify: 'track' } } & SearchOptions
|
||||
): Promise<SpotifyTrack[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { youtube: 'channel' } } & SearchOptions
|
||||
): Promise<YouTubeChannel[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { youtube: 'playlist' } } & SearchOptions
|
||||
): Promise<YouTubePlayList[]>;
|
||||
export async function search(
|
||||
query: string,
|
||||
options: { source: { youtube: 'video' } } & SearchOptions
|
||||
): Promise<YouTubeVideo[]>;
|
||||
export async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>;
|
||||
export async function search(query: string, options? : SearchOptions ): Promise<YouTubeVideo[]>;
|
||||
/**
|
||||
* Searches through a particular source and gives respective info.
|
||||
*
|
||||
* Example
|
||||
* ```ts
|
||||
* const searched = await play.search('Rick Roll', { source : { youtube : "video" } }) // YouTube Video Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { limit : 1 }) // YouTube Video Search but returns only 1 video.
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { spotify : "track" } }) // Spotify Track Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { soundcloud : "tracks" } }) // SoundCloud Track Search
|
||||
*
|
||||
* const searched = await play.search('Rick Roll', { source : { deezer : "track" } }) // Deezer Track Search
|
||||
* ```
|
||||
* @param query string to search.
|
||||
* @param options
|
||||
*
|
||||
* - `number` limit : No of searches you want to have.
|
||||
* - `boolean` fuzzy : Whether the search should be fuzzy or only return exact matches. Defaults to `true`. [ for `Deezer` Only ]
|
||||
* - `Object` source : Contains type of source and type of result you want to have
|
||||
* ```ts
|
||||
* - youtube : 'video' | 'playlist' | 'channel';
|
||||
- spotify : 'album' | 'playlist' | 'track';
|
||||
- soundcloud : 'tracks' | 'playlists' | 'albums';
|
||||
- deezer : 'track' | 'playlist' | 'album';
|
||||
```
|
||||
* @returns Array of {@link YouTube} or {@link Spotify} or {@link SoundCloud} or {@link Deezer} type
|
||||
*/
|
||||
export async function search(
|
||||
query: string,
|
||||
options: SearchOptions = {}
|
||||
@ -120,11 +246,27 @@ export async function search(
|
||||
}
|
||||
|
||||
/**
|
||||
* stream Command for streaming through various sources using data from video_info or soundcloud
|
||||
* SoundCloud Track is only supported
|
||||
* @param info video_info data or SoundCloud Track data.
|
||||
* @param options contains quality, cookie and proxy to set for stream
|
||||
* @returns YouTube / SoundCloud Stream to play
|
||||
* Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing.
|
||||
*
|
||||
* Example
|
||||
* ```ts
|
||||
* const info = await video_info('youtube URL')
|
||||
* const source = await play.stream_from_info(info) // YouTube Video Stream
|
||||
*
|
||||
* const soundInfo = await play.soundcloud('SoundCloud URL')
|
||||
* const source = await play.stream_from_info(soundInfo) // SoundCloud Track Stream
|
||||
*
|
||||
* const resource = createAudioResource(source.stream, {
|
||||
* inputType : source.type
|
||||
* }) // Use discordjs voice createAudioResource function.
|
||||
* ```
|
||||
* @param info YouTube video info OR SoundCloud track Class
|
||||
* @param options
|
||||
*
|
||||
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
|
||||
* - `Proxy[]` proxy : sends data through a proxy
|
||||
* - `boolean` htmldata : given data is html data or not
|
||||
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
|
||||
*/
|
||||
export async function stream_from_info(
|
||||
info: InfoData | SoundCloudTrack,
|
||||
@ -134,9 +276,17 @@ export async function stream_from_info(
|
||||
else return await yt_stream_info(info, options);
|
||||
}
|
||||
/**
|
||||
* Command to validate the provided url. It checks whether it supports play-dl or not.
|
||||
* @param url url to validate
|
||||
* @returns On failure, returns false else type of url.
|
||||
* Validates url that play-dl supports.
|
||||
*
|
||||
* - `so` - SoundCloud
|
||||
* - `sp` - Spotify
|
||||
* - `dz` - Deezer
|
||||
* - `yt` - YouTube
|
||||
* @param url URL
|
||||
* @returns
|
||||
* ```ts
|
||||
* 'so_playlist' / 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'dz_track' | 'dz_playlist' | 'dz_album' | 'yt_video' | 'yt_playlist' | 'search' | false
|
||||
* ```
|
||||
*/
|
||||
export async function validate(
|
||||
url: string
|
||||
@ -171,7 +321,17 @@ export async function validate(
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Authorization interface for Spotify and SoundCloud.
|
||||
* Authorization interface for Spotify, SoundCloud and YouTube.
|
||||
*
|
||||
* Either stores info in `.data` folder or shows relevant data to be used in `setToken` function.
|
||||
*
|
||||
* ```ts
|
||||
* const play = require('play-dl')
|
||||
*
|
||||
* play.authorization()
|
||||
* ```
|
||||
*
|
||||
* Just run the above command and you will get a interface asking some questions.
|
||||
*/
|
||||
export function authorization(): void {
|
||||
const ask = readline.createInterface({
|
||||
@ -285,7 +445,13 @@ export function authorization(): void {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches paused, playing, autoPaused Listeners to discordjs voice AudioPlayer.
|
||||
*
|
||||
* Useful if you don't want extra data to be downloaded by play-dl.
|
||||
* @param player discordjs voice AudioPlayer
|
||||
* @param resource A {@link YouTubeStream} or {@link SoundCloudStream}
|
||||
*/
|
||||
export function attachListeners(player: EventEmitter, resource: YouTubeStream | SoundCloudStream) {
|
||||
const pauseListener = () => resource.pause();
|
||||
const resumeListener = () => resource.resume();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user