Ability to play a playlist

This commit is contained in:
simojenki
2021-05-08 10:33:59 +10:00
parent 5c692f6eb2
commit 4229ad1836
8 changed files with 634 additions and 115 deletions

View File

@@ -13,6 +13,7 @@ import {
ArtistSummary,
Genre,
MusicService,
PlaylistSummary,
slice2,
Track,
} from "./music_service";
@@ -194,7 +195,7 @@ export type Container = {
itemType: ContainerType;
id: string;
title: string;
displayType: string | undefined
displayType: string | undefined;
};
const genre = (genre: Genre) => ({
@@ -203,6 +204,13 @@ const genre = (genre: Genre) => ({
title: genre.name,
});
const playlist = (playlist: PlaylistSummary) => ({
itemType: "album",
id: `playlist:${playlist.id}`,
title: playlist.name,
canPlay: true,
});
export const defaultAlbumArtURI = (
webAddress: string,
accessToken: string,
@@ -487,6 +495,11 @@ function bindSmapiSoapServiceToExpress(
id: "albums",
title: "Albums",
},
{
itemType: "container",
id: "playlists",
title: "Playlists",
},
{
itemType: "container",
id: "genres",
@@ -519,7 +532,7 @@ function bindSmapiSoapServiceToExpress(
},
],
index: 0,
total: 8,
total: 9,
});
case "search":
return getMetadataResult({
@@ -589,6 +602,31 @@ function bindSmapiSoapServiceToExpress(
total,
})
);
case "playlists":
return musicLibrary
.playlists()
.then(slice2(paging))
.then(([page, total]) =>
getMetadataResult({
mediaCollection: page.map(playlist),
index: paging._index,
total,
})
);
case "playlist":
return musicLibrary
.playlist(typeId!)
.then(playlist => playlist.entries)
.then(slice2(paging))
.then(([page, total]) => {
return getMetadataResult({
mediaMetadata: page.map((it) =>
track(webAddress, accessToken, it)
),
index: paging._index,
total,
});
});
case "artist":
return musicLibrary
.artist(typeId!)