mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Genre with id and name, rather than just name
This commit is contained in:
@@ -49,18 +49,23 @@ export type AlbumSummary = {
|
||||
id: string;
|
||||
name: string;
|
||||
year: string | undefined;
|
||||
genre: string | undefined;
|
||||
genre: Genre | undefined;
|
||||
};
|
||||
|
||||
export type Album = AlbumSummary & {};
|
||||
|
||||
export type Genre = {
|
||||
name: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export type Track = {
|
||||
id: string;
|
||||
name: string;
|
||||
mimeType: string;
|
||||
duration: number;
|
||||
number: number | undefined;
|
||||
genre: string | undefined;
|
||||
genre: Genre | undefined;
|
||||
album: AlbumSummary;
|
||||
artist: ArtistSummary;
|
||||
};
|
||||
@@ -137,7 +142,7 @@ export interface MusicLibrary {
|
||||
album(id: string): Promise<Album>;
|
||||
tracks(albumId: string): Promise<Track[]>;
|
||||
track(trackId: string): Promise<Track>;
|
||||
genres(): Promise<string[]>;
|
||||
genres(): Promise<Genre[]>;
|
||||
stream({
|
||||
trackId,
|
||||
range,
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
Images,
|
||||
AlbumSummary,
|
||||
NO_IMAGES,
|
||||
Genre,
|
||||
} from "./music_service";
|
||||
import X2JS from "x2js";
|
||||
import sharp from "sharp";
|
||||
@@ -193,7 +194,7 @@ const asTrack = (album: Album, song: song) => ({
|
||||
mimeType: song._contentType,
|
||||
duration: parseInt(song._duration || "0"),
|
||||
number: parseInt(song._track || "0"),
|
||||
genre: song._genre,
|
||||
genre: maybeAsGenre(song._genre),
|
||||
album,
|
||||
artist: {
|
||||
id: song._artistId,
|
||||
@@ -206,9 +207,18 @@ const asAlbum = (album: album) => ({
|
||||
id: album._id,
|
||||
name: album._name,
|
||||
year: album._year,
|
||||
genre: album._genre,
|
||||
genre: maybeAsGenre(album._genre),
|
||||
});
|
||||
|
||||
export const asGenre = (genreName: string) => ({ id: genreName, name: genreName });
|
||||
|
||||
const maybeAsGenre = (genreName: string | undefined): Genre | undefined =>
|
||||
pipe(
|
||||
O.fromNullable(genreName),
|
||||
O.map(asGenre),
|
||||
O.getOrElseW(() => undefined)
|
||||
);
|
||||
|
||||
export class Navidrome implements MusicService {
|
||||
url: string;
|
||||
encryption: Encryption;
|
||||
@@ -318,7 +328,7 @@ export class Navidrome implements MusicService {
|
||||
id: album._id,
|
||||
name: album._name,
|
||||
year: album._year,
|
||||
genre: album._genre,
|
||||
genre: maybeAsGenre(album._genre),
|
||||
}));
|
||||
|
||||
getArtist = (
|
||||
@@ -336,7 +346,7 @@ export class Navidrome implements MusicService {
|
||||
id: album._id,
|
||||
name: album._name,
|
||||
year: album._year,
|
||||
genre: album._genre,
|
||||
genre: maybeAsGenre(album._genre),
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -399,7 +409,7 @@ export class Navidrome implements MusicService {
|
||||
id: album._id,
|
||||
name: album._name,
|
||||
year: album._year,
|
||||
genre: album._genre,
|
||||
genre: maybeAsGenre(album._genre),
|
||||
}))
|
||||
)
|
||||
.then(slice2(q))
|
||||
@@ -416,7 +426,8 @@ export class Navidrome implements MusicService {
|
||||
pipe(
|
||||
it.genres.genre,
|
||||
A.map((it) => it.__text),
|
||||
A.sort(ordString)
|
||||
A.sort(ordString),
|
||||
A.map((it) => ({ id: it, name: it }))
|
||||
)
|
||||
),
|
||||
tracks: (albumId: string) =>
|
||||
|
||||
11
src/smapi.ts
11
src/smapi.ts
@@ -10,6 +10,7 @@ import {
|
||||
Album,
|
||||
AlbumSummary,
|
||||
ArtistSummary,
|
||||
Genre,
|
||||
MusicLibrary,
|
||||
MusicService,
|
||||
slice2,
|
||||
@@ -184,10 +185,10 @@ const container = ({
|
||||
title,
|
||||
});
|
||||
|
||||
const genre = (genre: string) => ({
|
||||
const genre = (genre: Genre) => ({
|
||||
itemType: "container",
|
||||
id: `genre:${genre}`,
|
||||
title: genre,
|
||||
id: `genre:${genre.id}`,
|
||||
title: genre.name,
|
||||
});
|
||||
|
||||
export const defaultAlbumArtURI = (
|
||||
@@ -235,8 +236,8 @@ export const track = (
|
||||
artist: track.artist.name,
|
||||
artistId: track.artist.id,
|
||||
duration: track.duration,
|
||||
genre: track.album.genre,
|
||||
// genreId
|
||||
genre: track.album.genre?.name,
|
||||
genreId: track.album.genre?.id,
|
||||
trackNumber: track.number,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user