mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Split Album into AlbumSummary and Album as per Artist
This commit is contained in:
@@ -38,11 +38,14 @@ export type Artist = ArtistSummary & {
|
|||||||
albums: Album[]
|
albums: Album[]
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Album = {
|
export type AlbumSummary = {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
year: string | undefined;
|
year: string | undefined;
|
||||||
genre: string | undefined;
|
genre: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Album = AlbumSummary & {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Paging = {
|
export type Paging = {
|
||||||
@@ -80,5 +83,6 @@ export interface MusicService {
|
|||||||
export interface MusicLibrary {
|
export interface MusicLibrary {
|
||||||
artists(q: ArtistQuery): Promise<Result<ArtistSummary>>;
|
artists(q: ArtistQuery): Promise<Result<ArtistSummary>>;
|
||||||
artist(id: string): Promise<Artist>;
|
artist(id: string): Promise<Artist>;
|
||||||
albums(q: AlbumQuery): Promise<Result<Album>>;
|
albums(q: AlbumQuery): Promise<Result<AlbumSummary>>;
|
||||||
|
// album(id: string): Promise<Album>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import {
|
|||||||
ArtistSummary,
|
ArtistSummary,
|
||||||
Result,
|
Result,
|
||||||
slice2,
|
slice2,
|
||||||
asResult,
|
|
||||||
AlbumQuery,
|
AlbumQuery,
|
||||||
ArtistQuery,
|
ArtistQuery,
|
||||||
MusicLibrary,
|
MusicLibrary,
|
||||||
Images,
|
Images,
|
||||||
|
AlbumSummary,
|
||||||
} from "./music_service";
|
} from "./music_service";
|
||||||
import X2JS from "x2js";
|
import X2JS from "x2js";
|
||||||
|
|
||||||
@@ -203,14 +203,13 @@ export class Navidrome implements MusicService {
|
|||||||
navidrome
|
navidrome
|
||||||
.getArtists(credentials)
|
.getArtists(credentials)
|
||||||
.then(slice2(q))
|
.then(slice2(q))
|
||||||
.then(asResult)
|
.then(([page, total]) =>
|
||||||
.then((result) =>
|
|
||||||
Promise.all(
|
Promise.all(
|
||||||
result.results.map((idName: IdName) =>
|
page.map((idName: IdName) =>
|
||||||
navidrome
|
navidrome
|
||||||
.getArtistInfo(credentials, idName.id)
|
.getArtistInfo(credentials, idName.id)
|
||||||
.then((artistInfo) => ({
|
.then((artistInfo) => ({
|
||||||
total: result.total,
|
total,
|
||||||
result: {
|
result: {
|
||||||
id: idName.id,
|
id: idName.id,
|
||||||
name: idName.name,
|
name: idName.name,
|
||||||
@@ -236,7 +235,7 @@ export class Navidrome implements MusicService {
|
|||||||
image: artistInfo.image,
|
image: artistInfo.image,
|
||||||
albums: artist.albums,
|
albums: artist.albums,
|
||||||
})),
|
})),
|
||||||
albums: (_: AlbumQuery): Promise<Result<Album>> => {
|
albums: (_: AlbumQuery): Promise<Result<AlbumSummary>> => {
|
||||||
return Promise.resolve({ results: [], total: 0 });
|
return Promise.resolve({ results: [], total: 0 });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -113,21 +113,21 @@ function server(
|
|||||||
res.send("");
|
res.send("");
|
||||||
});
|
});
|
||||||
|
|
||||||
// app.get("/artist/:artistId/image", (req, res) => {
|
// app.get("/album/:albumId/art", (req, res) => {
|
||||||
// console.log(`Trying to load image for ${req.params["artistId"]}, token ${JSON.stringify(req.cookies)}`)
|
// console.log(`Trying to load image for ${req.params["albumId"]}, token ${JSON.stringify(req.cookies)}`)
|
||||||
// const authToken = req.headers["X-AuthToken"]! as string;
|
// const authToken = req.headers["X-AuthToken"]! as string;
|
||||||
// const artistId = req.params["artistId"]!;
|
// const albumId = req.params["albumId"]!;
|
||||||
// musicService
|
// musicService
|
||||||
// .login(authToken)
|
// .login(authToken)
|
||||||
// .then((it) => it.artist(artistId))
|
// // .then((it) => it.artist(artistId))
|
||||||
// .then(artist => artist.image.small)
|
// // .then(artist => artist.image.small)
|
||||||
// .then((url) => {
|
// .then((url) => {
|
||||||
// if (url) {
|
// if (url) {
|
||||||
// console.log(`${artistId} sending 307 -> ${url}`)
|
// console.log(`${albumId} sending 307 -> ${url}`)
|
||||||
// res.setHeader("Location", url);
|
// // res.setHeader("Location", url);
|
||||||
// res.status(307).send();
|
// res.status(307).send();
|
||||||
// } else {
|
// } else {
|
||||||
// console.log(`${artistId} sending 404`)
|
// console.log(`${albumId} sending 404`)
|
||||||
// res.status(404).send();
|
// res.status(404).send();
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|||||||
26
src/smapi.ts
26
src/smapi.ts
@@ -6,7 +6,7 @@ import path from "path";
|
|||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
|
|
||||||
import { LinkCodes } from "./link_codes";
|
import { LinkCodes } from "./link_codes";
|
||||||
import { Album, MusicLibrary, MusicService, slice2 } from "./music_service";
|
import { AlbumSummary, MusicLibrary, MusicService, slice2 } from "./music_service";
|
||||||
|
|
||||||
export const LOGIN_ROUTE = "/login";
|
export const LOGIN_ROUTE = "/login";
|
||||||
export const SOAP_PATH = "/ws/sonos";
|
export const SOAP_PATH = "/ws/sonos";
|
||||||
@@ -159,10 +159,16 @@ const container = ({
|
|||||||
title,
|
title,
|
||||||
});
|
});
|
||||||
|
|
||||||
const album = (album: Album) => ({
|
const album = (album: AlbumSummary) => ({
|
||||||
itemType: "album",
|
itemType: "album",
|
||||||
id: `album:${album.id}`,
|
id: `album:${album.id}`,
|
||||||
title: album.name,
|
title: album.name,
|
||||||
|
// albumArtURI: {
|
||||||
|
// attributes: {
|
||||||
|
// requiresAuthentication: "true"
|
||||||
|
// },
|
||||||
|
// $value: `${webAddress}/album/${album.id}/art`
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
type SoapyHeaders = {
|
type SoapyHeaders = {
|
||||||
@@ -244,6 +250,14 @@ function bindSmapiSoapServiceToExpress(
|
|||||||
total: result.total,
|
total: result.total,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
case "albums":
|
||||||
|
return await musicLibrary.albums(paging).then((result) =>
|
||||||
|
getMetadataResult({
|
||||||
|
mediaCollection: result.results.map(album),
|
||||||
|
index: paging._index,
|
||||||
|
total: result.total,
|
||||||
|
})
|
||||||
|
);
|
||||||
case "artist":
|
case "artist":
|
||||||
return await musicLibrary
|
return await musicLibrary
|
||||||
.artist(typeId!)
|
.artist(typeId!)
|
||||||
@@ -256,14 +270,6 @@ function bindSmapiSoapServiceToExpress(
|
|||||||
total,
|
total,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
case "albums":
|
|
||||||
return await musicLibrary.albums(paging).then((result) =>
|
|
||||||
getMetadataResult({
|
|
||||||
mediaCollection: result.results.map(album),
|
|
||||||
index: paging._index,
|
|
||||||
total: result.total,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
default:
|
default:
|
||||||
throw `Unsupported id:${id}`;
|
throw `Unsupported id:${id}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import {
|
|||||||
slice2,
|
slice2,
|
||||||
asResult,
|
asResult,
|
||||||
ArtistSummary,
|
ArtistSummary,
|
||||||
|
Album,
|
||||||
|
AlbumSummary
|
||||||
} from "../src/music_service";
|
} from "../src/music_service";
|
||||||
|
|
||||||
export const artistToArtistSummary = (
|
export const artistToArtistSummary = (
|
||||||
@@ -24,6 +26,15 @@ export const artistToArtistSummary = (
|
|||||||
image: it.image,
|
image: it.image,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const albumToAlbumSummary = (
|
||||||
|
it: Album
|
||||||
|
): AlbumSummary => ({
|
||||||
|
id: it.id,
|
||||||
|
name: it.name,
|
||||||
|
year: it.year,
|
||||||
|
genre: it.genre,
|
||||||
|
});
|
||||||
|
|
||||||
type P<T> = (t: T) => boolean;
|
type P<T> = (t: T) => boolean;
|
||||||
const all: P<any> = (_: any) => true;
|
const all: P<any> = (_: any) => true;
|
||||||
const artistWithId = (id: string): P<Artist> => (artist: Artist) =>
|
const artistWithId = (id: string): P<Artist> => (artist: Artist) =>
|
||||||
@@ -79,8 +90,10 @@ export class InMemoryMusicService implements MusicService {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
.then((artists) => artists.flatMap((it) => it.albums))
|
.then((artists) => artists.flatMap((it) => it.albums))
|
||||||
|
.then(it => it.map(albumToAlbumSummary))
|
||||||
.then(slice2(q))
|
.then(slice2(q))
|
||||||
.then(asResult),
|
.then(asResult),
|
||||||
|
// album: (id: albumId) => Promise.resolve(this.artists.flatMap(it => it.albums).find(it => it.id === id))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user