Loading artist images from navidrome

This commit is contained in:
simojenki
2021-03-03 22:59:15 +11:00
parent ce6c1638fd
commit 4dae907826
8 changed files with 273 additions and 74 deletions

View File

@@ -26,6 +26,11 @@ export type AuthFailure = {
export type Artist = {
id: string;
name: string;
image: {
small: string | undefined,
medium: string | undefined,
large: string | undefined,
}
};
export type Album = {

View File

@@ -38,7 +38,12 @@ export type SubsonicResponse = {
export type GetArtistsResponse = SubsonicResponse & {
artists: {
index: {
artist: { _id: string; _name: string; _albumCount: string }[];
artist: {
_id: string;
_name: string;
_albumCount: string;
_artistImageUrl: string | undefined;
}[];
_name: string;
}[];
};
@@ -51,6 +56,19 @@ export type SubsonicError = SubsonicResponse & {
};
};
export type artistInfo = {
biography: string | undefined;
musicBrainzId: string | undefined;
lastFmUrl: string | undefined;
smallImageUrl: string | undefined;
mediumImageUrl: string | undefined;
largeImageUrl: string | undefined;
};
export type GetArtistInfoResponse = {
artistInfo: artistInfo;
};
export function isError(
subsonicResponse: SubsonicResponse
): subsonicResponse is SubsonicError {
@@ -89,13 +107,15 @@ export class Navidrome implements MusicService {
});
generateToken = async (credentials: Credentials) =>
this.get(credentials, "/rest/ping.view").then(() => ({
authToken: Buffer.from(
JSON.stringify(this.encryption.encrypt(JSON.stringify(credentials)))
).toString("base64"),
userId: credentials.username,
nickname: credentials.username,
})).catch(e => ({ message: `${e}` }));
this.get(credentials, "/rest/ping.view")
.then(() => ({
authToken: Buffer.from(
JSON.stringify(this.encryption.encrypt(JSON.stringify(credentials)))
).toString("base64"),
userId: credentials.username,
nickname: credentials.username,
}))
.catch((e) => ({ message: `${e}` }));
parseToken = (token: string): Credentials =>
JSON.parse(
@@ -113,13 +133,33 @@ export class Navidrome implements MusicService {
.get<GetArtistsResponse>(credentials, "/rest/getArtists")
.then((it) => it.artists.index.flatMap((it) => it.artist))
.then((artists) =>
artists.map((it) => ({ id: it._id, name: it._name }))
Promise.all(
artists.map((artist) =>
navidrome
.get<GetArtistInfoResponse>(
credentials,
"/rest/getArtistInfo",
{ id: artist._id }
)
.then((it) => it.artistInfo)
.then((artistInfo) => ({
id: artist._id,
name: artist._name,
image: {
small: artistInfo.smallImageUrl,
medium: artistInfo.mediumImageUrl,
large: artistInfo.largeImageUrl,
},
}))
)
)
)
.then(slice2(q))
.then(asResult),
artist: (id: string) => ({
id,
name: id,
image: { small: undefined, medium: undefined, large: undefined },
}),
albums: (_: AlbumQuery): Promise<Result<Album>> => {
return Promise.resolve({ results: [], total: 0 });

View File

@@ -6,7 +6,7 @@ import path from "path";
import logger from "./logger";
import { LinkCodes } from "./link_codes";
import { Artist, MusicLibrary, MusicService } from "./music_service";
import { Album, Artist, MusicLibrary, MusicService } from "./music_service";
export const LOGIN_ROUTE = "/login";
export const SOAP_PATH = "/ws/sonos";
@@ -218,8 +218,8 @@ function bindSmapiSoapServiceToExpress(
case "root":
return getMetadataResult({
mediaCollection: [
container({ id: "artists", title: "Artists" }),
container({ id: "albums", title: "Albums" }),
{ itemType: "container", id: "artists", title: "Artists" },
{ itemType: "container", id: "albums", title: "Albums" },
],
index: 0,
total: 2,
@@ -230,9 +230,12 @@ function bindSmapiSoapServiceToExpress(
.then(({ results, total }: { results: Artist[], total: number}) =>
getMetadataResult({
mediaCollection: results.map((it) =>
container({
({
itemType: "artist",
id: `artist:${it.id}`,
artistId: it.id,
title: it.name,
albumArtURI: it.image.small
})
),
index: paging._index,
@@ -242,7 +245,7 @@ function bindSmapiSoapServiceToExpress(
case "albums":
return await musicLibrary
.albums(paging)
.then(({ results, total }: { results: Artist[], total: number}) =>
.then(({ results, total }: { results: Album[], total: number}) =>
getMetadataResult({
mediaCollection: results.map((it) =>
container({