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.
*/
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,8 +240,9 @@ 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);
@ -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;
}
@ -411,17 +412,17 @@ export class SpotifyAlbum {
/**
* Boolean to tell whether it is a searched result or not.
*/
private readonly search : boolean
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,7 +439,8 @@ 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) => {
if (!this.search)
data.tracks.items.forEach((v: any) => {
videos.push(new SpotifyTrack(v));
});
this.fetched_tracks = new Map();
@ -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;
}

View File

@ -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<YouTubeStream>
export async function stream(url: string, options? : StreamOptions) : Promise<YouTubeStream | SoundCloudStream>
export async function stream(
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.
*
@ -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.');
}
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: SoundCloudTrack, options?: StreamOptions): Promise<SoundCloudStream>;
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.
*