pretty code

This commit is contained in:
killer069
2021-11-23 09:56:08 +05:30
parent 6fe9372989
commit 32b9fdbf65
19 changed files with 601 additions and 515 deletions

View File

@@ -115,7 +115,7 @@ export class SpotifyTrack {
thumbnail: SpotifyThumbnail | undefined;
/**
* Constructor for Spotify Track
* @param data
* @param data
*/
constructor(data: any) {
this.name = data.name;
@@ -149,7 +149,7 @@ export class SpotifyTrack {
else this.thumbnail = data.album.images[0];
}
toJSON() : TrackJSON {
toJSON(): TrackJSON {
return {
name: this.name,
id: this.id,
@@ -205,13 +205,13 @@ export class SpotifyPlaylist {
tracksCount: number;
/**
* Spotify Playlist Spotify data
*
*
* @private
*/
private spotifyData: SpotifyDataOptions;
/**
* Spotify Playlist fetched tracks Map
*
*
* @private
*/
private fetched_tracks: Map<string, SpotifyTrack[]>;
@@ -244,7 +244,7 @@ export class SpotifyPlaylist {
}
/**
* Fetches Spotify Playlist tracks more than 100 tracks.
*
*
* For getting all tracks in playlist, see `total_pages` property.
* @returns Playlist Class.
*/
@@ -283,18 +283,18 @@ export class SpotifyPlaylist {
}
/**
* Spotify Playlist tracks are divided in pages.
*
*
* For example getting data of 101 - 200 videos in a playlist,
*
*
* ```ts
* const playlist = await play.spotify('playlist url')
*
*
* await playlist.fetch()
*
*
* const result = playlist.page(2)
* ```
* @param num Page Number
* @returns
* @returns
*/
page(num: number) {
if (!num) throw new Error('Page number is not provided');
@@ -303,16 +303,16 @@ export class SpotifyPlaylist {
}
/**
* 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))
* }
@@ -332,7 +332,7 @@ export class SpotifyPlaylist {
* Converts Class to JSON
* @returns JSON data
*/
toJSON() : PlaylistJSON{
toJSON(): PlaylistJSON {
return {
name: this.name,
collaborative: this.collaborative,
@@ -341,7 +341,7 @@ export class SpotifyPlaylist {
id: this.id,
thumbnail: this.thumbnail,
owner: this.owner,
tracksCount : this.tracksCount
tracksCount: this.tracksCount
};
}
}
@@ -391,21 +391,21 @@ export class SpotifyAlbum {
tracksCount: number;
/**
* Spotify Album Spotify data
*
*
* @private
*/
private spotifyData: SpotifyDataOptions;
/**
* Spotify Album fetched tracks Map
*
* @private
*/
private fetched_tracks: Map<string, SpotifyTrack[]>;
/**
* Constructor for Spotify Album Class
* @param data Json parsed album data
* @param spotifyData Spotify credentials
*/
private spotifyData: SpotifyDataOptions;
/**
* Spotify Album fetched tracks Map
*
* @private
*/
private fetched_tracks: Map<string, SpotifyTrack[]>;
/**
* Constructor for Spotify Album Class
* @param data Json parsed album data
* @param spotifyData Spotify credentials
*/
constructor(data: any, spotifyData: SpotifyDataOptions) {
this.name = data.name;
this.type = 'album';
@@ -435,7 +435,7 @@ export class SpotifyAlbum {
}
/**
* Fetches Spotify Album tracks more than 50 tracks.
*
*
* For getting all tracks in album, see `total_pages` property.
* @returns Album Class.
*/
@@ -474,18 +474,18 @@ export class SpotifyAlbum {
}
/**
* Spotify Album tracks are divided in pages.
*
*
* For example getting data of 51 - 100 videos in a album,
*
*
* ```ts
* const album = await play.spotify('album url')
*
*
* await album.fetch()
*
*
* const result = album.page(2)
* ```
* @param num Page Number
* @returns
* @returns
*/
page(num: number) {
if (!num) throw new Error('Page number is not provided');
@@ -494,16 +494,16 @@ export class SpotifyAlbum {
}
/**
* 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))
* }
@@ -520,10 +520,10 @@ export class SpotifyAlbum {
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
}
toJSON() : AlbumJSON {
toJSON(): AlbumJSON {
return {
name: this.name,
id : this.id,
id: this.id,
type: this.type,
url: this.url,
thumbnail: this.thumbnail,
@@ -531,7 +531,7 @@ export class SpotifyAlbum {
copyrights: this.copyrights,
release_date: this.release_date,
release_date_precision: this.release_date_precision,
tracksCount : this.tracksCount
tracksCount: this.tracksCount
};
}
}

View File

@@ -1,118 +1,118 @@
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes'
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes';
export interface TrackJSON{
export interface TrackJSON {
/**
* Spotify Track Name
*/
name: string;
/**
* Spotify Track ID
*/
id: string;
/**
* Spotify Track url
*/
url: string;
/**
* Spotify Track explicit info.
*/
explicit: boolean;
/**
* Spotify Track Duration in seconds
*/
durationInSec: number;
/**
* Spotify Track Duration in milli seconds
*/
durationInMs: number;
/**
* Spotify Track Artists data [ array ]
*/
artists: SpotifyArtists[];
/**
* Spotify Track Album data
*/
album: SpotifyTrackAlbum | undefined;
/**
* Spotify Track Thumbnail Data
*/
thumbnail: SpotifyThumbnail | undefined;
name: string;
/**
* Spotify Track ID
*/
id: string;
/**
* Spotify Track url
*/
url: string;
/**
* Spotify Track explicit info.
*/
explicit: boolean;
/**
* Spotify Track Duration in seconds
*/
durationInSec: number;
/**
* Spotify Track Duration in milli seconds
*/
durationInMs: number;
/**
* Spotify Track Artists data [ array ]
*/
artists: SpotifyArtists[];
/**
* Spotify Track Album data
*/
album: SpotifyTrackAlbum | undefined;
/**
* Spotify Track Thumbnail Data
*/
thumbnail: SpotifyThumbnail | undefined;
}
export interface PlaylistJSON {
/**
* Spotify Playlist Name
*/
name: string;
/**
* Spotify Playlist collaborative boolean.
*/
collaborative: boolean;
/**
* Spotify Playlist Description
*/
description: string;
/**
* Spotify Playlist URL
*/
url: string;
/**
* Spotify Playlist ID
*/
id: string;
/**
* Spotify Playlist Thumbnail Data
*/
thumbnail: SpotifyThumbnail;
/**
* Spotify Playlist Owner Artist data
*/
owner: SpotifyArtists;
/**
* Spotify Playlist total tracks Count
*/
tracksCount: number;
name: string;
/**
* Spotify Playlist collaborative boolean.
*/
collaborative: boolean;
/**
* Spotify Playlist Description
*/
description: string;
/**
* Spotify Playlist URL
*/
url: string;
/**
* Spotify Playlist ID
*/
id: string;
/**
* Spotify Playlist Thumbnail Data
*/
thumbnail: SpotifyThumbnail;
/**
* Spotify Playlist Owner Artist data
*/
owner: SpotifyArtists;
/**
* Spotify Playlist total tracks Count
*/
tracksCount: number;
}
export interface AlbumJSON{
export interface AlbumJSON {
/**
* Spotify Album Name
*/
name: string;
/**
* Spotify Class type. == "album"
*/
type: 'track' | 'playlist' | 'album';
/**
* Spotify Album url
*/
url: string;
/**
* Spotify Album id
*/
id: string;
/**
* Spotify Album Thumbnail data
*/
thumbnail: SpotifyThumbnail;
/**
* Spotify Album artists [ array ]
*/
artists: SpotifyArtists[];
/**
* Spotify Album copyright data [ array ]
*/
copyrights: SpotifyCopyright[];
/**
* Spotify Album Release date
*/
release_date: string;
/**
* Spotify Album Release Date **precise**
*/
release_date_precision: string;
/**
* Spotify Album total no of tracks
*/
tracksCount: number;
}
name: string;
/**
* Spotify Class type. == "album"
*/
type: 'track' | 'playlist' | 'album';
/**
* Spotify Album url
*/
url: string;
/**
* Spotify Album id
*/
id: string;
/**
* Spotify Album Thumbnail data
*/
thumbnail: SpotifyThumbnail;
/**
* Spotify Album artists [ array ]
*/
artists: SpotifyArtists[];
/**
* Spotify Album copyright data [ array ]
*/
copyrights: SpotifyCopyright[];
/**
* Spotify Album Release date
*/
release_date: string;
/**
* Spotify Album Release Date **precise**
*/
release_date_precision: string;
/**
* Spotify Album total no of tracks
*/
tracksCount: number;
}

View File

@@ -27,12 +27,12 @@ export interface SpotifyDataOptions {
const pattern = /^((https:)?\/\/)?open.spotify.com\/(track|album|playlist)\//;
/**
* Gets Spotify url details.
*
*
* ```ts
* let spot = await play.spotify('spotify url')
*
*
* // spot.type === "track" | "playlist" | "album"
*
*
* if (spot.type === "track") {
* spot = spot as play.SpotifyTrack
* // Code with spotify track class.
@@ -85,7 +85,7 @@ export async function spotify(url: string): Promise<Spotify> {
/**
* Validate Spotify url
* @param url Spotify URL
* @returns
* @returns
* ```ts
* 'track' | 'playlist' | 'album' | 'search' | false
* ```
@@ -144,7 +144,7 @@ export async function SpotifyAuthorize(data: SpotifyDataOptions, file: boolean):
}
/**
* Checks if spotify token is expired or not.
*
*
* Update token if returned false.
* ```ts
* if (!play.is_expired()) {
@@ -206,7 +206,7 @@ export async function sp_search(
}
/**
* Refreshes Token
*
*
* ```ts
* if (!play.is_expired()) {
* await play.refreshToken()
@@ -243,4 +243,4 @@ export function setSpotifyToken(options: SpotifyDataOptions) {
refreshToken();
}
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist }
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist };