Skip to content

Commit

Permalink
feat: Implement remaining recently played endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
FoxxMD committed Feb 5, 2024
1 parent 12ed767 commit c1f8997
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/backend/common/vendor/ListenbrainzApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ export class ListenbrainzApiClient extends AbstractApiClient {
getRecentlyPlayed = async (maxTracks: number, user?: string): Promise<PlayObject[]> => {
try {
const resp = await this.getUserListens(maxTracks, user);
const now = await this.getPlayingNow(user);
return resp.listens.map(x => ListenbrainzApiClient.listenResponseToPlay(x));
} catch (e) {
this.logger.error(`Error encountered while getting User listens | Error => ${e.message}`);
Expand Down
5 changes: 5 additions & 0 deletions src/backend/sources/DeezerSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class DeezerSource extends AbstractSource {
this.workingCredsPath = `${this.configDir}/currentCreds-${name}.json`;
this.canPoll = true;
this.canBacklog = true;
this.supportsUpstreamRecentlyPlayed = true;
}

static formatPlayObj(obj: any, options: FormatPlayObjectOptions = {}): PlayObject {
Expand Down Expand Up @@ -137,6 +138,10 @@ export default class DeezerSource extends AbstractSource {
}
}

getUpstreamRecentlyPlayed = async (options: RecentlyPlayedOptions = {}): Promise<PlayObject[]> => {
return this.getRecentlyPlayed(options);
}

getRecentlyPlayed = async (options: RecentlyPlayedOptions = {}) => {
const resp = await this.callApi(request.get(`${this.baseUrl}/user/me/history?limit=20`));
return resp.data.map((x: any) => DeezerSource.formatPlayObj(x)).sort(sortByOldestPlayDate);
Expand Down
11 changes: 10 additions & 1 deletion src/backend/sources/ListenbrainzSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import MemorySource from "./MemorySource.js";
import {ErrorWithCause} from "pony-cause";
import request from "superagent";
import {isNodeNetworkException} from "../common/errors/NodeErrors.js";
import {SOURCE_SOT} from "../../core/Atomic.js";
import {PlayObject, SOURCE_SOT} from "../../core/Atomic.js";

export default class ListenbrainzSource extends MemorySource {

Expand All @@ -30,6 +30,7 @@ export default class ListenbrainzSource extends MemorySource {
this.canBacklog = true;
this.api = new ListenbrainzApiClient(name, config.data);
this.playerSourceOfTruth = SOURCE_SOT.HISTORY;
this.supportsUpstreamRecentlyPlayed = true;
this.logger.info(`Note: The player for this source is an analogue for the 'Now Playing' status exposed by ${this.type} which is NOT used for scrobbling. Instead, the 'recently played' or 'history' information provided by this source is used for scrobbles.`)
}

Expand Down Expand Up @@ -69,6 +70,14 @@ export default class ListenbrainzSource extends MemorySource {
return await this.api.getRecentlyPlayed(limit);
}

getUpstreamRecentlyPlayed = async (options: RecentlyPlayedOptions = {}): Promise<PlayObject[]> => {
try {
return await this.api.getRecentlyPlayed(20);
} catch (e) {
throw e;
}
}

protected getBackloggedPlays = async () => {
return await this.getRecentlyPlayed({formatted: true});
}
Expand Down

0 comments on commit c1f8997

Please sign in to comment.