mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-06 04:32:40 +00:00
Some more changes
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { request } from '../Request';
|
||||
import { SpotifyDataOptions } from '.';
|
||||
import { TrackJSON } from './constants';
|
||||
|
||||
interface SpotifyTrackAlbum {
|
||||
export interface SpotifyTrackAlbum {
|
||||
/**
|
||||
* Spotify Track Album name
|
||||
*/
|
||||
@@ -18,40 +19,104 @@ interface SpotifyTrackAlbum {
|
||||
* Spotify Track Album release date
|
||||
*/
|
||||
release_date: string;
|
||||
/**
|
||||
* Spotify Track Album release date **precise**
|
||||
*/
|
||||
release_date_precision: string;
|
||||
/**
|
||||
* Spotify Track Album total tracks number
|
||||
*/
|
||||
total_tracks: number;
|
||||
}
|
||||
|
||||
interface SpotifyArtists {
|
||||
export interface SpotifyArtists {
|
||||
/**
|
||||
* Spotify Artist Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Spotify Artist Url
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* Spotify Artist ID
|
||||
*/
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface SpotifyThumbnail {
|
||||
export interface SpotifyThumbnail {
|
||||
/**
|
||||
* Spotify Thumbnail height
|
||||
*/
|
||||
height: number;
|
||||
/**
|
||||
* Spotify Thumbnail width
|
||||
*/
|
||||
width: number;
|
||||
/**
|
||||
* Spotify Thumbnail url
|
||||
*/
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface SpotifyCopyright {
|
||||
export interface SpotifyCopyright {
|
||||
/**
|
||||
* Spotify Copyright Text
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Spotify Copyright Type
|
||||
*/
|
||||
type: string;
|
||||
}
|
||||
/**
|
||||
* Class for Spotify Track
|
||||
* Spotify Track Class
|
||||
*/
|
||||
export class SpotifyTrack {
|
||||
/**
|
||||
* Spotify Track Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Spotify Class type. == "track"
|
||||
*/
|
||||
type: 'track' | 'playlist' | 'album';
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Constructor for Spotify Track
|
||||
* @param data
|
||||
*/
|
||||
constructor(data: any) {
|
||||
this.name = data.name;
|
||||
this.id = data.id;
|
||||
@@ -84,11 +149,10 @@ export class SpotifyTrack {
|
||||
else this.thumbnail = data.album.images[0];
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
toJSON() : TrackJSON {
|
||||
return {
|
||||
name: this.name,
|
||||
id: this.id,
|
||||
type: this.type,
|
||||
url: this.url,
|
||||
explicit: this.explicit,
|
||||
durationInMs: this.durationInMs,
|
||||
@@ -100,20 +164,62 @@ export class SpotifyTrack {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Class for Spotify Playlist
|
||||
* Spotify Playlist Class
|
||||
*/
|
||||
export class SpotifyPlaylist {
|
||||
/**
|
||||
* Spotify Playlist Name
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Spotify Class type. == "playlist"
|
||||
*/
|
||||
type: 'track' | 'playlist' | 'album';
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* Spotify Playlist Spotify data
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private spotifyData: SpotifyDataOptions;
|
||||
/**
|
||||
* Spotify Playlist fetched tracks Map
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private fetched_tracks: Map<string, SpotifyTrack[]>;
|
||||
/**
|
||||
* 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) {
|
||||
this.name = data.name;
|
||||
this.type = 'playlist';
|
||||
@@ -136,7 +242,12 @@ export class SpotifyPlaylist {
|
||||
this.fetched_tracks.set('1', videos);
|
||||
this.spotifyData = spotifyData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches Spotify Playlist tracks more than 100 tracks.
|
||||
*
|
||||
* For getting whole data, see `total_pages` property.
|
||||
* @returns Playlist Class.
|
||||
*/
|
||||
async fetch() {
|
||||
let fetching: number;
|
||||
if (this.tracksCount > 1000) fetching = 1000;
|
||||
@@ -170,7 +281,13 @@ export class SpotifyPlaylist {
|
||||
await Promise.allSettled(work);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spotify Playlist tracks are divided in pages.
|
||||
*
|
||||
* For example getting data
|
||||
* @param num
|
||||
* @returns
|
||||
*/
|
||||
page(num: number) {
|
||||
if (!num) throw new Error('Page number is not provided');
|
||||
if (!this.fetched_tracks.has(`${num}`)) throw new Error('Given Page number is invalid');
|
||||
|
||||
40
play-dl/Spotify/constants.ts
Normal file
40
play-dl/Spotify/constants.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { SpotifyArtists, SpotifyThumbnail, SpotifyTrackAlbum } from './classes'
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user