Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Deezer.ts #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions Deezer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";



Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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");

Expand All @@ -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,
Expand Down