commit
eba90bc92a
@ -218,16 +218,16 @@ export class SpotifyPlaylist {
|
|||||||
/**
|
/**
|
||||||
* Boolean to tell whether it is a searched result or not.
|
* Boolean to tell whether it is a searched result or not.
|
||||||
*/
|
*/
|
||||||
private readonly search : boolean
|
private readonly search: boolean;
|
||||||
/**
|
/**
|
||||||
* Constructor for Spotify Playlist Class
|
* Constructor for Spotify Playlist Class
|
||||||
* @param data JSON parsed data of playlist
|
* @param data JSON parsed data of playlist
|
||||||
* @param spotifyData Data about sporify token for furhter fetching.
|
* @param spotifyData Data about sporify token for furhter fetching.
|
||||||
*/
|
*/
|
||||||
constructor(data: any, spotifyData: SpotifyDataOptions, search : boolean) {
|
constructor(data: any, spotifyData: SpotifyDataOptions, search: boolean) {
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
this.type = 'playlist';
|
this.type = 'playlist';
|
||||||
this.search = search
|
this.search = search;
|
||||||
this.collaborative = data.collaborative;
|
this.collaborative = data.collaborative;
|
||||||
this.description = data.description;
|
this.description = data.description;
|
||||||
this.url = data.external_urls.spotify;
|
this.url = data.external_urls.spotify;
|
||||||
@ -240,9 +240,10 @@ export class SpotifyPlaylist {
|
|||||||
};
|
};
|
||||||
this.tracksCount = Number(data.tracks.total);
|
this.tracksCount = Number(data.tracks.total);
|
||||||
const videos: SpotifyTrack[] = [];
|
const videos: SpotifyTrack[] = [];
|
||||||
if(!this.search) data.tracks.items.forEach((v: any) => {
|
if (!this.search)
|
||||||
if(v.track) videos.push(new SpotifyTrack(v.track));
|
data.tracks.items.forEach((v: any) => {
|
||||||
});
|
if (v.track) videos.push(new SpotifyTrack(v.track));
|
||||||
|
});
|
||||||
this.fetched_tracks = new Map();
|
this.fetched_tracks = new Map();
|
||||||
this.fetched_tracks.set('1', videos);
|
this.fetched_tracks.set('1', videos);
|
||||||
this.spotifyData = spotifyData;
|
this.spotifyData = spotifyData;
|
||||||
@ -254,7 +255,7 @@ export class SpotifyPlaylist {
|
|||||||
* @returns Playlist Class.
|
* @returns Playlist Class.
|
||||||
*/
|
*/
|
||||||
async fetch() {
|
async fetch() {
|
||||||
if(this.search) return this;
|
if (this.search) return this;
|
||||||
let fetching: number;
|
let fetching: number;
|
||||||
if (this.tracksCount > 1000) fetching = 1000;
|
if (this.tracksCount > 1000) fetching = 1000;
|
||||||
else fetching = this.tracksCount;
|
else fetching = this.tracksCount;
|
||||||
@ -331,7 +332,7 @@ export class SpotifyPlaylist {
|
|||||||
* Spotify Playlist total no of tracks that have been fetched so far.
|
* Spotify Playlist total no of tracks that have been fetched so far.
|
||||||
*/
|
*/
|
||||||
get total_tracks() {
|
get total_tracks() {
|
||||||
if(this.search) return this.tracksCount;
|
if (this.search) return this.tracksCount;
|
||||||
const page_number: number = this.total_pages;
|
const page_number: number = this.total_pages;
|
||||||
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
|
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
|
||||||
}
|
}
|
||||||
@ -409,19 +410,19 @@ export class SpotifyAlbum {
|
|||||||
*/
|
*/
|
||||||
private fetched_tracks: Map<string, SpotifyTrack[]>;
|
private fetched_tracks: Map<string, SpotifyTrack[]>;
|
||||||
/**
|
/**
|
||||||
* Boolean to tell whether it is a searched result or not.
|
* Boolean to tell whether it is a searched result or not.
|
||||||
*/
|
*/
|
||||||
private readonly search : boolean
|
private readonly search: boolean;
|
||||||
/**
|
/**
|
||||||
* Constructor for Spotify Album Class
|
* Constructor for Spotify Album Class
|
||||||
* @param data Json parsed album data
|
* @param data Json parsed album data
|
||||||
* @param spotifyData Spotify credentials
|
* @param spotifyData Spotify credentials
|
||||||
*/
|
*/
|
||||||
constructor(data: any, spotifyData: SpotifyDataOptions, search : boolean) {
|
constructor(data: any, spotifyData: SpotifyDataOptions, search: boolean) {
|
||||||
this.name = data.name;
|
this.name = data.name;
|
||||||
this.type = 'album';
|
this.type = 'album';
|
||||||
this.id = data.id;
|
this.id = data.id;
|
||||||
this.search = search
|
this.search = search;
|
||||||
this.url = data.external_urls.spotify;
|
this.url = data.external_urls.spotify;
|
||||||
this.thumbnail = data.images[0];
|
this.thumbnail = data.images[0];
|
||||||
const artists: SpotifyArtists[] = [];
|
const artists: SpotifyArtists[] = [];
|
||||||
@ -438,9 +439,10 @@ export class SpotifyAlbum {
|
|||||||
this.release_date_precision = data.release_date_precision;
|
this.release_date_precision = data.release_date_precision;
|
||||||
this.tracksCount = data.total_tracks;
|
this.tracksCount = data.total_tracks;
|
||||||
const videos: SpotifyTrack[] = [];
|
const videos: SpotifyTrack[] = [];
|
||||||
if(!this.search) data.tracks.items.forEach((v: any) => {
|
if (!this.search)
|
||||||
videos.push(new SpotifyTrack(v));
|
data.tracks.items.forEach((v: any) => {
|
||||||
});
|
videos.push(new SpotifyTrack(v));
|
||||||
|
});
|
||||||
this.fetched_tracks = new Map();
|
this.fetched_tracks = new Map();
|
||||||
this.fetched_tracks.set('1', videos);
|
this.fetched_tracks.set('1', videos);
|
||||||
this.spotifyData = spotifyData;
|
this.spotifyData = spotifyData;
|
||||||
@ -452,7 +454,7 @@ export class SpotifyAlbum {
|
|||||||
* @returns Album Class.
|
* @returns Album Class.
|
||||||
*/
|
*/
|
||||||
async fetch() {
|
async fetch() {
|
||||||
if(this.search) return this
|
if (this.search) return this;
|
||||||
let fetching: number;
|
let fetching: number;
|
||||||
if (this.tracksCount > 500) fetching = 500;
|
if (this.tracksCount > 500) fetching = 500;
|
||||||
else fetching = this.tracksCount;
|
else fetching = this.tracksCount;
|
||||||
@ -529,7 +531,7 @@ export class SpotifyAlbum {
|
|||||||
* Spotify Album total no of tracks that have been fetched so far.
|
* Spotify Album total no of tracks that have been fetched so far.
|
||||||
*/
|
*/
|
||||||
get total_tracks() {
|
get total_tracks() {
|
||||||
if(this.search) return this.tracksCount
|
if (this.search) return this.tracksCount;
|
||||||
const page_number: number = this.total_pages;
|
const page_number: number = this.total_pages;
|
||||||
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
|
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
|
||||||
}
|
}
|
||||||
@ -548,4 +550,4 @@ export class SpotifyAlbum {
|
|||||||
tracksCount: this.tracksCount
|
tracksCount: this.tracksCount
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,8 +86,11 @@ import { YouTubeChannel } from './YouTube/classes/Channel';
|
|||||||
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './Spotify/classes';
|
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './Spotify/classes';
|
||||||
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes';
|
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes';
|
||||||
|
|
||||||
export async function stream(url: string, options: { seek? : number , seekMode?: 'precise' | 'granular'} & StreamOptions) : Promise<YouTubeStream>
|
export async function stream(
|
||||||
export async function stream(url: string, options? : StreamOptions) : Promise<YouTubeStream | SoundCloudStream>
|
url: string,
|
||||||
|
options: { seek?: number; seekMode?: 'precise' | 'granular' } & StreamOptions
|
||||||
|
): Promise<YouTubeStream>;
|
||||||
|
export async function stream(url: string, options?: StreamOptions): Promise<YouTubeStream | SoundCloudStream>;
|
||||||
/**
|
/**
|
||||||
* Creates a Stream [ YouTube or SoundCloud ] class from a url for playing.
|
* Creates a Stream [ YouTube or SoundCloud ] class from a url for playing.
|
||||||
*
|
*
|
||||||
@ -96,14 +99,14 @@ export async function stream(url: string, options? : StreamOptions) : Promise<Yo
|
|||||||
* const source = await play.stream('youtube video URL') // YouTube Video Stream
|
* const source = await play.stream('youtube video URL') // YouTube Video Stream
|
||||||
*
|
*
|
||||||
* const source = await play.stream('soundcloud track URL') // SoundCloud Track Stream
|
* const source = await play.stream('soundcloud track URL') // SoundCloud Track Stream
|
||||||
*
|
*
|
||||||
* const source = await play.stream('youtube video URL', { seek : 45 }) // Seeks 45 seconds (approx.) in YouTube Video Stream [ seekMode = "granular" ]
|
* const source = await play.stream('youtube video URL', { seek : 45 }) // Seeks 45 seconds (approx.) in YouTube Video Stream [ seekMode = "granular" ]
|
||||||
* // Granular = 1 - 9 seconds before given time. [ Fast ]
|
* // Granular = 1 - 9 seconds before given time. [ Fast ]
|
||||||
* // Precise = Exact seek [ Little bit Slow ]
|
* // Precise = Exact seek [ Little bit Slow ]
|
||||||
* // Above command seeks to 45 seconds approximately while below command seeks to 45 seconds precisely
|
* // Above command seeks to 45 seconds approximately while below command seeks to 45 seconds precisely
|
||||||
*
|
*
|
||||||
* const source = await play.stream('youtube video URL', { seek : 45, seekMode: "precise" }) // Seeks precisely to 45 seconds in YouTube Video Stream
|
* const source = await play.stream('youtube video URL', { seek : 45, seekMode: "precise" }) // Seeks precisely to 45 seconds in YouTube Video Stream
|
||||||
*
|
*
|
||||||
* const resource = createAudioResource(source.stream, {
|
* const resource = createAudioResource(source.stream, {
|
||||||
* inputType : source.type
|
* inputType : source.type
|
||||||
* }) // Use discordjs voice createAudioResource function.
|
* }) // Use discordjs voice createAudioResource function.
|
||||||
@ -224,8 +227,8 @@ export async function search(
|
|||||||
else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.');
|
else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.');
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stream_from_info(info: SoundCloudTrack, options? : StreamOptions) : Promise<SoundCloudStream>
|
export async function stream_from_info(info: SoundCloudTrack, options?: StreamOptions): Promise<SoundCloudStream>;
|
||||||
export async function stream_from_info(info: InfoData, options? : StreamOptions) : Promise<YouTubeStream>
|
export async function stream_from_info(info: InfoData, options?: StreamOptions): Promise<YouTubeStream>;
|
||||||
/**
|
/**
|
||||||
* Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing.
|
* Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing.
|
||||||
*
|
*
|
||||||
@ -236,12 +239,12 @@ export async function stream_from_info(info: InfoData, options? : StreamOptions)
|
|||||||
*
|
*
|
||||||
* const soundInfo = await play.soundcloud('SoundCloud URL')
|
* const soundInfo = await play.soundcloud('SoundCloud URL')
|
||||||
* const source = await play.stream_from_info(soundInfo) // SoundCloud Track Stream
|
* const source = await play.stream_from_info(soundInfo) // SoundCloud Track Stream
|
||||||
*
|
*
|
||||||
* const source = await play.stream_from_info(info, { seek : 45 }) // Seeks 45 seconds (approx.) in YouTube Video Stream [ seekMode = "granular" ]
|
* const source = await play.stream_from_info(info, { seek : 45 }) // Seeks 45 seconds (approx.) in YouTube Video Stream [ seekMode = "granular" ]
|
||||||
* // Granular = 1 - 9 seconds before given time. [ Fast ]
|
* // Granular = 1 - 9 seconds before given time. [ Fast ]
|
||||||
* // Precise = Exact seek [ Little bit Slow ]
|
* // Precise = Exact seek [ Little bit Slow ]
|
||||||
* // Above command seeks to 45 seconds approximately while below command seeks to 45 seconds precisely
|
* // Above command seeks to 45 seconds approximately while below command seeks to 45 seconds precisely
|
||||||
*
|
*
|
||||||
* const source = await play.stream_from_info(info, { seek : 45, seekMode: "precise" }) // Seeks precisely to 45 seconds in YouTube Video Stream
|
* const source = await play.stream_from_info(info, { seek : 45, seekMode: "precise" }) // Seeks precisely to 45 seconds in YouTube Video Stream
|
||||||
*
|
*
|
||||||
* const resource = createAudioResource(source.stream, {
|
* const resource = createAudioResource(source.stream, {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user