Added property to get all tracks in playlist, album

This commit is contained in:
killer069
2022-01-03 15:02:52 +05:30
parent 2e1476745d
commit 433ec4976b
4 changed files with 93 additions and 49 deletions

View File

@@ -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<SoundCloudTrack[]> {
await this.fetch()
return this.tracks as SoundCloudTrack[]
}
/**
* Converts Class to JSON data