fix: posters

This commit is contained in:
Fredrik Burmester
2024-08-26 08:30:12 +02:00
parent d962507749
commit c12b58e5cb
10 changed files with 179 additions and 29 deletions

View File

@@ -36,6 +36,10 @@ export const getBackdropUrl = ({
params.append("fillWidth", width.toString());
}
if (item.Type === "Episode") {
return getPrimaryImageUrl({ api, item, quality, width });
}
if (backdropImageTags) {
params.append("tag", backdropImageTags);
return `${api.basePath}/Items/${

View File

@@ -21,15 +21,29 @@ export const getLogoImageUrlById = ({
return null;
}
const imageTags = item.ImageTags?.["Logo"];
if (!imageTags) return null;
const params = new URLSearchParams();
params.append("tag", imageTags);
params.append("quality", "90");
params.append("fillHeight", height.toString());
if (item.Type === "Episode") {
const imageTag = item.ParentLogoImageTag;
const parentId = item.ParentLogoItemId;
if (!parentId || !imageTag) {
return null;
}
params.append("tag", imageTag);
return `${api.basePath}/Items/${parentId}/Images/Logo?${params.toString()}`;
}
const imageTag = item.ImageTags?.["Logo"];
if (!imageTag) return null;
params.append("tag", imageTag);
return `${api.basePath}/Items/${item.Id}/Images/Logo?${params.toString()}`;
};

View File

@@ -0,0 +1,42 @@
import { Api } from "@jellyfin/sdk";
import {
BaseItemDto,
BaseItemPerson,
} from "@jellyfin/sdk/lib/generated-client/models";
import { isBaseItemDto } from "../jellyfin";
/**
* Retrieves the primary image URL for a given item.
*
* @param api - The Jellyfin API instance.
* @param item - The media item to retrieve the backdrop image URL for.
* @param quality - The desired image quality (default: 90).
*/
export const getParentBackdropImageUrl = ({
api,
item,
quality = 80,
width = 400,
}: {
api?: Api | null;
item?: BaseItemDto | null;
quality?: number | null;
width?: number | null;
}) => {
if (!item || !api) {
return null;
}
const parentId = item.ParentBackdropItemId;
const tag = item.ParentBackdropImageTags?.[0] || "";
const params = new URLSearchParams({
fillWidth: width ? String(width) : "500",
quality: quality ? String(quality) : "80",
tag: tag,
});
return `${
api?.basePath
}/Items/${parentId}/Images/Backdrop/0?${params.toString()}`;
};

View File

@@ -0,0 +1,42 @@
import { Api } from "@jellyfin/sdk";
import {
BaseItemDto,
BaseItemPerson,
} from "@jellyfin/sdk/lib/generated-client/models";
import { isBaseItemDto } from "../jellyfin";
/**
* Retrieves the primary image URL for a given item.
*
* @param api - The Jellyfin API instance.
* @param item - The media item to retrieve the backdrop image URL for.
* @param quality - The desired image quality (default: 90).
*/
export const getPrimaryParentImageUrl = ({
api,
item,
quality = 80,
width = 400,
}: {
api?: Api | null;
item?: BaseItemDto | null;
quality?: number | null;
width?: number | null;
}) => {
if (!item || !api) {
return null;
}
const parentId = item.ParentId;
const primaryTag = item.ParentPrimaryImageTag?.[0];
const params = new URLSearchParams({
fillWidth: width ? String(width) : "500",
quality: quality ? String(quality) : "80",
tag: primaryTag || "",
});
return `${
api?.basePath
}/Items/${parentId}/Images/Primary?${params.toString()}`;
};