From cbe3d779000f844e46a27e27c388d85eab44322a Mon Sep 17 00:00:00 2001 From: itsparasdev <121629415+itsparasdev@users.noreply.github.com> Date: Sat, 24 Feb 2024 08:30:10 +0530 Subject: [PATCH] Update Deezer.ts --- Deezer.ts | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/Deezer.ts b/Deezer.ts index 3808f15..418067f 100644 --- a/Deezer.ts +++ b/Deezer.ts @@ -10,11 +10,11 @@ const DEEZER_REGEX = /^(?:https?:\/\/|)?(?:www\.)?deezer\.com\/(?:\w{2}\/)?(trac const ISRC_PREFIX = "dzisrc:"; export type loadType = - | "TRACK_LOADED" - | "PLAYLIST_LOADED" - | "SEARCH_RESULT" - | "NO_MATCHES" - | "LOAD_FAILED"; + | "track" + | "playlist" + | "search" + | "empty" + | "error"; @@ -101,11 +101,11 @@ export class Deezer extends Plugin { const unresolvedTracks = await this.buildUnresolved(track, requester) - return this.buildResponse("TRACK_LOADED", [unresolvedTracks]); + return this.buildResponse("track", [unresolvedTracks]); } catch (e) { return this.buildResponse( - "LOAD_FAILED", + "error", [], undefined, e.body?.error.message ?? e.message @@ -125,11 +125,11 @@ export class Deezer extends Plugin { playlist.tracks.data.map((x) => this.buildUnresolved(x, requester)) ); - return this.buildResponse("PLAYLIST_LOADED", unresolvedPlaylistTracks, playlist.title); + return this.buildResponse("playlist", unresolvedPlaylistTracks, playlist.title); } catch (e) { return this.buildResponse( - "LOAD_FAILED", + "error", [], undefined, e.body?.error.message ?? e.message @@ -146,17 +146,17 @@ export class Deezer extends Plugin { const artist: any = await this.getData(`/artist/${id}/top`); await this.getArtistTracks(artist) - if (artist.data.length === 0) return this.buildResponse("LOAD_FAILED", [], undefined, "This artist does not have any top songs"); + if (artist.data.length === 0) return this.buildResponse("error", [], undefined, "This artist does not have any top songs"); const unresolvedArtistTracks = await Promise.all( artist.data.map((x) => this.buildUnresolved(x, requester)) ); - return this.buildResponse("PLAYLIST_LOADED", unresolvedArtistTracks, `${artistData.name}'s top songs`); + return this.buildResponse("playlist", unresolvedArtistTracks, `${artistData.name}'s top songs`); } catch (e) { return this.buildResponse( - "LOAD_FAILED", + "error", [], undefined, e.body?.error.message ?? e.message @@ -191,10 +191,10 @@ export class Deezer extends Plugin { const unresolvedTracks = await Promise.all( tracks.data.map((x) => this.buildUnresolved(x, requester)) ); - return this.buildResponse("SEARCH_RESULT", unresolvedTracks); + return this.buildResponse("search", unresolvedTracks); } catch (e) { return this.buildResponse( - "NO_MATCHES", + "empty", [], undefined, e.body?.error.message ?? e.message @@ -215,11 +215,11 @@ export class Deezer extends Plugin { album.tracks.data.map((x) => this.buildUnresolved(x, requester)) ); - return this.buildResponse("PLAYLIST_LOADED", unresolvedAlbumTracks, album.title); + return this.buildResponse("playlist", unresolvedAlbumTracks, album.title); } catch (e) { return this.buildResponse( - "LOAD_FAILED", + "error", [], undefined, e.body?.error.message ?? e.message @@ -256,7 +256,6 @@ export class Deezer extends Plugin { async buildUnresolved(track, requester) { - console.log(track) if (!track) throw new ReferenceError("The Deezer track object was not provided"); @@ -267,7 +266,7 @@ export class Deezer extends Plugin { identifier: track.id, isSeekable: true, author: track.artist ? track.artist.name : "Unknown", - length: track.duration, + length: track.duration*1000, isStream: false, title: track.title, uri: track.link,