mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 09:53:32 +01:00
Ability to browse Random Albums
This commit is contained in:
@@ -94,7 +94,10 @@ export const asResult = <T>([results, total]: [T[], number]) => ({
|
||||
|
||||
export type ArtistQuery = Paging;
|
||||
|
||||
export type AlbumQueryType = 'alphabeticalByArtist' | 'byGenre' | 'random' | 'recent' | 'frequent';
|
||||
|
||||
export type AlbumQuery = Paging & {
|
||||
type: AlbumQueryType;
|
||||
genre?: string;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import {
|
||||
} from "./music_service";
|
||||
import X2JS from "x2js";
|
||||
import sharp from "sharp";
|
||||
import { pick } from "underscore";
|
||||
|
||||
import axios, { AxiosRequestConfig } from "axios";
|
||||
import { Encryption } from "./encryption";
|
||||
import randomString from "./random_string";
|
||||
import { fold } from "fp-ts/lib/Option";
|
||||
|
||||
export const BROWSER_HEADERS = {
|
||||
accept:
|
||||
@@ -391,17 +391,9 @@ export class Navidrome implements MusicService {
|
||||
albums: (q: AlbumQuery): Promise<Result<AlbumSummary>> =>
|
||||
navidrome
|
||||
.getJSON<GetAlbumListResponse>(credentials, "/rest/getAlbumList", {
|
||||
...fold(
|
||||
() => ({
|
||||
type: "alphabeticalByArtist",
|
||||
}),
|
||||
(genre) => ({
|
||||
type: "byGenre",
|
||||
genre,
|
||||
})
|
||||
)(O.fromNullable(q.genre)),
|
||||
size: MAX_ALBUM_LIST,
|
||||
offset: 0,
|
||||
...pick(q, 'type', 'genre'),
|
||||
size: Math.min(MAX_ALBUM_LIST, q._count),
|
||||
offset: q._index,
|
||||
})
|
||||
.then((response) => response.albumList.album || [])
|
||||
.then((albumList) =>
|
||||
|
||||
60
src/smapi.ts
60
src/smapi.ts
@@ -449,9 +449,10 @@ function bindSmapiSoapServiceToExpress(
|
||||
container({ id: "artists", title: "Artists" }),
|
||||
container({ id: "albums", title: "Albums" }),
|
||||
container({ id: "genres", title: "Genres" }),
|
||||
container({ id: "randomAlbums", title: "Random" }),
|
||||
],
|
||||
index: 0,
|
||||
total: 3,
|
||||
total: 4,
|
||||
});
|
||||
case "artists":
|
||||
return await musicLibrary.artists(paging).then((result) => {
|
||||
@@ -465,16 +466,31 @@ function bindSmapiSoapServiceToExpress(
|
||||
});
|
||||
});
|
||||
case "albums":
|
||||
return await musicLibrary.albums(paging).then((result) => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
return getMetadataResult({
|
||||
mediaCollection: result.results.map((it) =>
|
||||
album(webAddress, accessToken, it)
|
||||
),
|
||||
index: paging._index,
|
||||
total: result.total,
|
||||
return await musicLibrary
|
||||
.albums({ type: "alphabeticalByArtist", ...paging })
|
||||
.then((result) => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
return getMetadataResult({
|
||||
mediaCollection: result.results.map((it) =>
|
||||
album(webAddress, accessToken, it)
|
||||
),
|
||||
index: paging._index,
|
||||
total: result.total,
|
||||
});
|
||||
});
|
||||
case "randomAlbums":
|
||||
return await musicLibrary
|
||||
.albums({ type: "random", ...paging })
|
||||
.then((result) => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
return getMetadataResult({
|
||||
mediaCollection: result.results.map((it) =>
|
||||
album(webAddress, accessToken, it)
|
||||
),
|
||||
index: paging._index,
|
||||
total: result.total,
|
||||
});
|
||||
});
|
||||
});
|
||||
case "genres":
|
||||
return await musicLibrary
|
||||
.genres()
|
||||
@@ -530,18 +546,20 @@ function bindSmapiSoapServiceToExpress(
|
||||
total,
|
||||
});
|
||||
});
|
||||
case "genre":
|
||||
return await musicLibrary.albums({ ...paging, genre: typeId }).then((result) => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
return getMetadataResult({
|
||||
mediaCollection: result.results.map((it) =>
|
||||
album(webAddress, accessToken, it)
|
||||
),
|
||||
index: paging._index,
|
||||
total: result.total,
|
||||
});
|
||||
case "genre":
|
||||
return await musicLibrary
|
||||
.albums({ type: "byGenre", genre: typeId, ...paging })
|
||||
.then((result) => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
return getMetadataResult({
|
||||
mediaCollection: result.results.map((it) =>
|
||||
album(webAddress, accessToken, it)
|
||||
),
|
||||
index: paging._index,
|
||||
total: result.total,
|
||||
});
|
||||
default:
|
||||
});
|
||||
default:
|
||||
throw `Unsupported id:${id}`;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user