Merge pull request #203 from play-dl/developer

Prettier Code
This commit is contained in:
Killer069 2021-12-15 13:44:44 +05:30 committed by GitHub
commit eba90bc92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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. * 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;
} }

View File

@ -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.
* *
@ -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.
* *