Add playlist image to type
This commit is contained in:
parent
d0e2a798fe
commit
d6dc880ef4
5 changed files with 66 additions and 10 deletions
|
@ -582,6 +582,22 @@ const getSongCoverArtUrl = (args: { baseUrl: string; item: JFSong; size: number
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getPlaylistCoverArtUrl = (args: { baseUrl: string; item: JFPlaylist; size: number }) => {
|
||||||
|
const size = args.size ? args.size : 300;
|
||||||
|
|
||||||
|
if (!args.item.ImageTags?.Primary) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
`${args.baseUrl}/Items` +
|
||||||
|
`/${args.item.Id}` +
|
||||||
|
'/Images/Primary' +
|
||||||
|
`?width=${size}&height=${size}` +
|
||||||
|
'&quality=96'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const normalizeSong = (
|
const normalizeSong = (
|
||||||
item: JFSong,
|
item: JFSong,
|
||||||
server: ServerListItem,
|
server: ServerListItem,
|
||||||
|
@ -698,10 +714,28 @@ const normalizeAlbumArtist = (
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalizePlaylist = (item: JFPlaylist): Playlist => {
|
const normalizePlaylist = (
|
||||||
|
item: JFPlaylist,
|
||||||
|
server: ServerListItem,
|
||||||
|
imageSize?: number,
|
||||||
|
): Playlist => {
|
||||||
|
const imageUrl = getPlaylistCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
item,
|
||||||
|
size: imageSize || 300,
|
||||||
|
});
|
||||||
|
|
||||||
|
const imagePlaceholderUrl = getPlaylistCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
item,
|
||||||
|
size: 1,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration: item.RunTimeTicks / 10000000,
|
duration: item.RunTimeTicks / 10000000,
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
|
imagePlaceholderUrl,
|
||||||
|
imageUrl,
|
||||||
name: item.Name,
|
name: item.Name,
|
||||||
public: null,
|
public: null,
|
||||||
rules: null,
|
rules: null,
|
||||||
|
|
|
@ -512,14 +512,14 @@ const normalizeSong = (
|
||||||
const normalizeAlbum = (item: NDAlbum, server: ServerListItem, imageSize?: number): Album => {
|
const normalizeAlbum = (item: NDAlbum, server: ServerListItem, imageSize?: number): Album => {
|
||||||
const imageUrl = getCoverArtUrl({
|
const imageUrl = getCoverArtUrl({
|
||||||
baseUrl: server.url,
|
baseUrl: server.url,
|
||||||
coverArtId: item.coverArtId,
|
coverArtId: item.coverArtId || item.id,
|
||||||
credential: server.credential,
|
credential: server.credential,
|
||||||
size: imageSize || 300,
|
size: imageSize || 300,
|
||||||
});
|
});
|
||||||
|
|
||||||
const imagePlaceholderUrl = getCoverArtUrl({
|
const imagePlaceholderUrl = getCoverArtUrl({
|
||||||
baseUrl: server.url,
|
baseUrl: server.url,
|
||||||
coverArtId: item.coverArtId,
|
coverArtId: item.coverArtId || item.id,
|
||||||
credential: server.credential,
|
credential: server.credential,
|
||||||
size: 1,
|
size: 1,
|
||||||
});
|
});
|
||||||
|
@ -571,10 +571,30 @@ const normalizeAlbumArtist = (item: NDAlbumArtist): AlbumArtist => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalizePlaylist = (item: NDPlaylist): Playlist => {
|
const normalizePlaylist = (
|
||||||
|
item: NDPlaylist,
|
||||||
|
server: ServerListItem,
|
||||||
|
imageSize?: number,
|
||||||
|
): Playlist => {
|
||||||
|
const imageUrl = getCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
coverArtId: item.id,
|
||||||
|
credential: server.credential,
|
||||||
|
size: imageSize || 300,
|
||||||
|
});
|
||||||
|
|
||||||
|
const imagePlaceholderUrl = getCoverArtUrl({
|
||||||
|
baseUrl: server.url,
|
||||||
|
coverArtId: item.id,
|
||||||
|
credential: server.credential,
|
||||||
|
size: 1,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
duration: item.duration,
|
duration: item.duration,
|
||||||
id: item.id,
|
id: item.id,
|
||||||
|
imagePlaceholderUrl,
|
||||||
|
imageUrl,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
public: item.public,
|
public: item.public,
|
||||||
rules: item?.rules || null,
|
rules: item?.rules || null,
|
||||||
|
|
|
@ -20,8 +20,8 @@ export type NDAlbum = {
|
||||||
artist: string;
|
artist: string;
|
||||||
artistId: string;
|
artistId: string;
|
||||||
compilation: boolean;
|
compilation: boolean;
|
||||||
coverArtId: string;
|
coverArtId?: string; // Removed after v0.48.0
|
||||||
coverArtPath: string;
|
coverArtPath?: string; // Removed after v0.48.0
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
duration: number;
|
duration: number;
|
||||||
fullText: string;
|
fullText: string;
|
||||||
|
|
|
@ -176,10 +176,10 @@ const playlistList = (data: RawPlaylistListResponse | undefined, server: ServerL
|
||||||
let playlists;
|
let playlists;
|
||||||
switch (server?.type) {
|
switch (server?.type) {
|
||||||
case 'jellyfin':
|
case 'jellyfin':
|
||||||
playlists = data?.items.map((item) => jfNormalize.playlist(item as JFPlaylist));
|
playlists = data?.items.map((item) => jfNormalize.playlist(item as JFPlaylist, server));
|
||||||
break;
|
break;
|
||||||
case 'navidrome':
|
case 'navidrome':
|
||||||
playlists = data?.items.map((item) => ndNormalize.playlist(item as NDPlaylist));
|
playlists = data?.items.map((item) => ndNormalize.playlist(item as NDPlaylist, server));
|
||||||
break;
|
break;
|
||||||
case 'subsonic':
|
case 'subsonic':
|
||||||
break;
|
break;
|
||||||
|
@ -199,10 +199,10 @@ const playlistDetail = (
|
||||||
let playlist;
|
let playlist;
|
||||||
switch (server?.type) {
|
switch (server?.type) {
|
||||||
case 'jellyfin':
|
case 'jellyfin':
|
||||||
playlist = jfNormalize.playlist(data as JFPlaylist);
|
playlist = jfNormalize.playlist(data as JFPlaylist, server);
|
||||||
break;
|
break;
|
||||||
case 'navidrome':
|
case 'navidrome':
|
||||||
playlist = ndNormalize.playlist(data as NDPlaylist);
|
playlist = ndNormalize.playlist(data as NDPlaylist, server);
|
||||||
break;
|
break;
|
||||||
case 'subsonic':
|
case 'subsonic':
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -237,6 +237,8 @@ export type MusicFolder = {
|
||||||
export type Playlist = {
|
export type Playlist = {
|
||||||
duration: number | null;
|
duration: number | null;
|
||||||
id: string;
|
id: string;
|
||||||
|
imagePlaceholderUrl: string | null;
|
||||||
|
imageUrl: string | null;
|
||||||
name: string;
|
name: string;
|
||||||
public: boolean | null;
|
public: boolean | null;
|
||||||
rules?: Record<string, any> | null;
|
rules?: Record<string, any> | null;
|
||||||
|
|
Reference in a new issue