diff --git a/play-dl/Spotify/classes.ts b/play-dl/Spotify/classes.ts index 3ab4bd9..6f03dd4 100644 --- a/play-dl/Spotify/classes.ts +++ b/play-dl/Spotify/classes.ts @@ -218,16 +218,16 @@ export class SpotifyPlaylist { /** * Boolean to tell whether it is a searched result or not. */ - private readonly search : boolean + private readonly search: boolean; /** * Constructor for Spotify Playlist Class * @param data JSON parsed data of playlist * @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.type = 'playlist'; - this.search = search + this.search = search; this.collaborative = data.collaborative; this.description = data.description; this.url = data.external_urls.spotify; @@ -240,9 +240,10 @@ export class SpotifyPlaylist { }; this.tracksCount = Number(data.tracks.total); const videos: SpotifyTrack[] = []; - if(!this.search) data.tracks.items.forEach((v: any) => { - if(v.track) videos.push(new SpotifyTrack(v.track)); - }); + if (!this.search) + data.tracks.items.forEach((v: any) => { + if (v.track) videos.push(new SpotifyTrack(v.track)); + }); this.fetched_tracks = new Map(); this.fetched_tracks.set('1', videos); this.spotifyData = spotifyData; @@ -254,7 +255,7 @@ export class SpotifyPlaylist { * @returns Playlist Class. */ async fetch() { - if(this.search) return this; + if (this.search) return this; let fetching: number; if (this.tracksCount > 1000) fetching = 1000; else fetching = this.tracksCount; @@ -331,7 +332,7 @@ export class SpotifyPlaylist { * Spotify Playlist total no of tracks that have been fetched so far. */ get total_tracks() { - if(this.search) return this.tracksCount; + if (this.search) return this.tracksCount; const page_number: number = this.total_pages; 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; /** - * Boolean to tell whether it is a searched result or not. - */ - private readonly search : boolean + * Boolean to tell whether it is a searched result or not. + */ + private readonly search: boolean; /** * Constructor for Spotify Album Class * @param data Json parsed album data * @param spotifyData Spotify credentials */ - constructor(data: any, spotifyData: SpotifyDataOptions, search : boolean) { + constructor(data: any, spotifyData: SpotifyDataOptions, search: boolean) { this.name = data.name; this.type = 'album'; this.id = data.id; - this.search = search + this.search = search; this.url = data.external_urls.spotify; this.thumbnail = data.images[0]; const artists: SpotifyArtists[] = []; @@ -438,9 +439,10 @@ export class SpotifyAlbum { this.release_date_precision = data.release_date_precision; this.tracksCount = data.total_tracks; const videos: SpotifyTrack[] = []; - if(!this.search) data.tracks.items.forEach((v: any) => { - videos.push(new SpotifyTrack(v)); - }); + if (!this.search) + data.tracks.items.forEach((v: any) => { + videos.push(new SpotifyTrack(v)); + }); this.fetched_tracks = new Map(); this.fetched_tracks.set('1', videos); this.spotifyData = spotifyData; @@ -452,7 +454,7 @@ export class SpotifyAlbum { * @returns Album Class. */ async fetch() { - if(this.search) return this + if (this.search) return this; let fetching: number; if (this.tracksCount > 500) fetching = 500; else fetching = this.tracksCount; @@ -529,7 +531,7 @@ export class SpotifyAlbum { * Spotify Album total no of tracks that have been fetched so far. */ get total_tracks() { - if(this.search) return this.tracksCount + if (this.search) return this.tracksCount; const page_number: number = this.total_pages; return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length; } @@ -548,4 +550,4 @@ export class SpotifyAlbum { tracksCount: this.tracksCount }; } -} \ No newline at end of file +} diff --git a/play-dl/index.ts b/play-dl/index.ts index ed91eeb..9a71b85 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -86,8 +86,11 @@ import { YouTubeChannel } from './YouTube/classes/Channel'; import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './Spotify/classes'; import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes'; -export async function stream(url: string, options: { seek? : number , seekMode?: 'precise' | 'granular'} & StreamOptions) : Promise -export async function stream(url: string, options? : StreamOptions) : Promise +export async function stream( + url: string, + options: { seek?: number; seekMode?: 'precise' | 'granular' } & StreamOptions +): Promise; +export async function stream(url: string, options?: StreamOptions): Promise; /** * 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 -export async function stream_from_info(info: InfoData, options? : StreamOptions) : Promise +export async function stream_from_info(info: SoundCloudTrack, options?: StreamOptions): Promise; +export async function stream_from_info(info: InfoData, options?: StreamOptions): Promise; /** * 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 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" ] * // Granular = 1 - 9 seconds before given time. [ Fast ] * // Precise = Exact seek [ Little bit Slow ] * // 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 resource = createAudioResource(source.stream, {