From f5f69ca7d4b923e997d1221b1acd9faa3836b811 Mon Sep 17 00:00:00 2001
From: adrifcastr
Date: Wed, 21 Jun 2023 15:14:48 +0200
Subject: [PATCH] default to season 1, with specials still playable
---
src/backend/metadata/getmeta.ts | 28 +++++++++++++---------------
src/components/media/MediaCard.tsx | 17 +++++++++++------
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/src/backend/metadata/getmeta.ts b/src/backend/metadata/getmeta.ts
index 21b6843a..b2166c34 100644
--- a/src/backend/metadata/getmeta.ts
+++ b/src/backend/metadata/getmeta.ts
@@ -96,24 +96,22 @@ export async function getMetaFromId(
if (type === MWMediaType.SERIES) {
const seasons = (details as TMDBShowData).seasons;
- const season =
- seasons?.find((v) => v.id.toString() === seasonId) ?? seasons?.[0];
- const episodes = await getEpisodes(
- details.id.toString(),
- season.season_number === null || season.season_number === 0
- ? 1
- : season.season_number
- );
+ let selectedSeason = seasons.find((v) => v.id.toString() === seasonId);
+ if (!selectedSeason) {
+ selectedSeason = seasons.find((v) => v.season_number === 1);
+ }
+
+ if (selectedSeason) {
+ const episodes = await getEpisodes(
+ details.id.toString(),
+ selectedSeason.season_number
+ );
- if (season && episodes) {
seasonData = {
- id: season.id.toString(),
- season_number:
- season.season_number === null || season.season_number === 0
- ? 1
- : season.season_number,
- title: season.name,
+ id: selectedSeason.id.toString(),
+ season_number: selectedSeason.season_number,
+ title: selectedSeason.name,
episodes,
};
}
diff --git a/src/components/media/MediaCard.tsx b/src/components/media/MediaCard.tsx
index c38b4a2b..a153d8b4 100644
--- a/src/components/media/MediaCard.tsx
+++ b/src/components/media/MediaCard.tsx
@@ -13,7 +13,7 @@ export interface MediaCardProps {
linkable?: boolean;
series?: {
episode: number;
- season: number;
+ season?: number;
episodeId: string;
seasonId: string;
};
@@ -72,7 +72,7 @@ function MediaCardContent({
].join(" ")}
>
{t("seasons.seasonAndEpisode", {
- season: series.season,
+ season: series.season || 1,
episode: series.episode,
})}
@@ -134,10 +134,15 @@ export function MediaCard(props: MediaCardProps) {
let link = canLink
? `/media/${encodeURIComponent(TMDBMediaToId(props.media))}`
: "#";
- if (canLink && props.series)
- link += `/${encodeURIComponent(props.series.seasonId)}/${encodeURIComponent(
- props.series.episodeId
- )}`;
+ if (canLink && props.series) {
+ if (props.series.season === 0 && !props.series.episodeId) {
+ link += `/${encodeURIComponent(props.series.seasonId)}`;
+ } else {
+ link += `/${encodeURIComponent(
+ props.series.seasonId
+ )}/${encodeURIComponent(props.series.episodeId)}`;
+ }
+ }
if (!props.linkable) return {content};
return (