diff --git a/play-dl/Deezer/classes.ts b/play-dl/Deezer/classes.ts index 959b5e5..5fa85c0 100644 --- a/play-dl/Deezer/classes.ts +++ b/play-dl/Deezer/classes.ts @@ -491,6 +491,21 @@ export class DeezerAlbum { return this; } + /** + * Fetches all the tracks in the album and returns them + * + * ```ts + * const album = await play.deezer('album url') + * + * const tracks = await album.all_tracks() + * ``` + * @returns An array of {@link DeezerTrack} + */ + async all_tracks(): Promise { + await this.fetch() + + return this.tracks as DeezerTrack[] + } /** * Converts instances of this class to JSON data * @returns JSON data. @@ -746,6 +761,21 @@ export class DeezerPlaylist { return this; } + /** + * Fetches all the tracks in the playlist and returns them + * + * ```ts + * const playlist = await play.deezer('playlist url') + * + * const tracks = await playlist.all_tracks() + * ``` + * @returns An array of {@link DeezerTrack} + */ + async all_tracks(): Promise { + await this.fetch() + + return this.tracks as DeezerTrack[] + } /** * Converts instances of this class to JSON data * @returns JSON data. diff --git a/play-dl/SoundCloud/classes.ts b/play-dl/SoundCloud/classes.ts index 958378b..ec92cf0 100644 --- a/play-dl/SoundCloud/classes.ts +++ b/play-dl/SoundCloud/classes.ts @@ -314,6 +314,7 @@ export class SoundCloudPlaylist { } /** * Get total no. of fetched tracks + * @see {@link SoundCloudPlaylist.all_tracks} */ get total_tracks(): number { let count = 0; @@ -324,25 +325,19 @@ export class SoundCloudPlaylist { return count; } /** - * Get all fetched tracks as a array. - * - * For getting all feetched tracks - * + * Fetches all the tracks in the playlist and returns them + * * ```ts - * const playlist = await play.soundcloud("playlist url") - * - * await playlist.fetch() - * - * const result = playlist.fetched_tracks + * const playlist = await play.soundcloud('playlist url') + * + * const tracks = await playlist.all_tracks() * ``` + * @returns An array of {@link SoundCloudTrack} */ - get fetched_tracks(): SoundCloudTrack[] { - let result: SoundCloudTrack[] = []; - this.tracks.forEach((track) => { - if (track instanceof SoundCloudTrack) result.push(track); - else return; - }); - return result; + async all_tracks(): Promise { + await this.fetch() + + return this.tracks as SoundCloudTrack[] } /** * Converts Class to JSON data diff --git a/play-dl/Spotify/classes.ts b/play-dl/Spotify/classes.ts index 6f03dd4..79a7b9a 100644 --- a/play-dl/Spotify/classes.ts +++ b/play-dl/Spotify/classes.ts @@ -309,21 +309,8 @@ export class SpotifyPlaylist { return this.fetched_tracks.get(`${num}`) as SpotifyTrack[]; } /** - * Spotify Playlist total no of pages in a playlist - * - * For getting all songs in a playlist, - * - * ```ts - * const playlist = await play.spotify('playlist url') - * - * await playlist.fetch() - * - * const result = [] - * - * for (let i = 0; i <= playlist.tota_pages; i++) { - * result.push(playlist.page(i)) - * } - * ``` + * Gets total number of pages in that playlist class. + * @see {@link SpotifyPlaylist.all_tracks} */ get total_pages() { return this.fetched_tracks.size; @@ -336,6 +323,25 @@ export class SpotifyPlaylist { const page_number: number = this.total_pages; return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length; } + /** + * Fetches all the tracks in the playlist and returns them + * + * ```ts + * const playlist = await play.spotify('playlist url') + * + * const tracks = await playlist.all_tracks() + * ``` + * @returns An array of {@link SpotifyTrack} + */ + async all_tracks() : Promise{ + await this.fetch() + + const tracks : SpotifyTrack[] = [] + + for(const page of this.fetched_tracks.values()) tracks.push(...page); + + return tracks + } /** * Converts Class to JSON * @returns JSON data @@ -508,21 +514,8 @@ export class SpotifyAlbum { return this.fetched_tracks.get(`${num}`); } /** - * Spotify Album total no of pages in a album - * - * For getting all songs in a album, - * - * ```ts - * const album = await play.spotify('album url') - * - * await album.fetch() - * - * const result = [] - * - * for (let i = 0; i <= album.tota_pages; i++) { - * result.push(album.page(i)) - * } - * ``` + * Gets total number of pages in that album class. + * @see {@link SpotifyAlbum.all_tracks} */ get total_pages() { return this.fetched_tracks.size; @@ -535,7 +528,29 @@ export class SpotifyAlbum { const page_number: number = this.total_pages; return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length; } + /** + * Fetches all the tracks in the album and returns them + * + * ```ts + * const album = await play.spotify('album url') + * + * const tracks = await album.all_tracks() + * ``` + * @returns An array of {@link SpotifyTrack} + */ + async all_tracks() : Promise{ + await this.fetch() + const tracks : SpotifyTrack[] = [] + + for( const page of this.fetched_tracks.values() ) tracks.push(...page); + + return tracks + } + /** + * Converts Class to JSON + * @returns JSON data + */ toJSON(): AlbumJSON { return { name: this.name, diff --git a/play-dl/YouTube/classes/Playlist.ts b/play-dl/YouTube/classes/Playlist.ts index 6dcda34..00c171c 100644 --- a/play-dl/YouTube/classes/Playlist.ts +++ b/play-dl/YouTube/classes/Playlist.ts @@ -218,6 +218,12 @@ export class YouTubePlayList { } /** * Fetches all the videos in the playlist and returns them + * + * ```ts + * const playlist = await play.playlist_info('playlist url') + * + * const videos = await playlist.all_videos() + * ``` * @returns An array of {@link YouTubeVideo} objects * @see {@link YouTubePlayList.fetch} */ @@ -226,9 +232,7 @@ export class YouTubePlayList { const videos = []; - for (const [, page] of this.fetched_videos.entries()) { - videos.push(...page); - } + for (const page of this.fetched_videos.values()) videos.push(...page); return videos; }