move scrobble into subsonic

This commit is contained in:
simon
2025-02-15 22:56:22 +00:00
parent ddde55d02b
commit 5009732da2
4 changed files with 86 additions and 127 deletions

View File

@@ -522,6 +522,8 @@ export class Subsonic {
});
// todo: make private
// todo: should I put a catch in here and force a subsonic fail status?
// or there is a catch above, that then throws, perhaps can go in there?
getJSON = async <T>(
{ username, password }: Credentials,
path: string,
@@ -739,7 +741,13 @@ export class Subsonic {
this.getJSON<SubsonicResponse>(credentials, `/rest/setRating`, {
id,
rating,
}).then(it =>
it.status == "ok"
);
})
.then(it => it.status == "ok");
scrobble = (credentials: Credentials, id: string, submission: boolean) =>
this.getJSON<SubsonicResponse>(credentials, `/rest/scrobble`, {
id,
submission,
})
.then(it => it.status == "ok")
}

View File

@@ -266,23 +266,12 @@ export class SubsonicMusicLibrary implements MusicLibrary {
return undefined;
});
// todo: unit test the difference between scrobble and nowPlaying
scrobble = async (id: string) =>
this.subsonic
.getJSON(this.credentials, `/rest/scrobble`, {
id,
submission: true,
})
.then((_) => true)
.catch(() => false);
this.subsonic.scrobble(this.credentials, id, true);
nowPlaying = async (id: string) =>
this.subsonic
.getJSON(this.credentials, `/rest/scrobble`, {
id,
submission: false,
})
.then((_) => true)
.catch(() => false);
this.subsonic.scrobble(this.credentials, id, false);
searchArtists = async (query: string) =>
this.subsonic