prettier Code

This commit is contained in:
killer069
2021-12-15 13:43:55 +05:30
parent 6fbb0e96de
commit 74ed5fb002
2 changed files with 33 additions and 28 deletions

View File

@@ -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<string, SpotifyTrack[]>;
/**
* 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
};
}
}
}