diff --git a/server/lib/services.ts b/server/lib/services.ts index 39d9773..f14c240 100644 --- a/server/lib/services.ts +++ b/server/lib/services.ts @@ -2195,63 +2195,73 @@ export async function requestMovie(config: AppConfig, tmdbId: number): Promise(`${config.radarr.baseUrl}/api/v3/movie`, { + method: 'POST', + headers: { + 'X-Api-Key': config.radarr.apiKey, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + title: details.title || details.original_title || 'Movie', + qualityProfileId: radarrRequestConfig.qualityProfileId, + rootFolderPath: radarrRequestConfig.rootFolderPath, + tmdbId: details.id, + year: Number(String(details.release_date || '').slice(0, 4)) || 0, + minimumAvailability: 'released', + addOptions: { + monitored: config.radarr.monitor !== 'none', + searchForMovie: false + } + }) + }); + } catch (error) { + const message = error instanceof Error ? error.message.toLowerCase() : ''; + const looksLikeAlreadyExists = message.includes('already') || message.includes('exists') || message.includes('duplicate'); + + if (looksLikeAlreadyExists) { + // Race condition: movie was added between our check and our add call. Get it again. + movie = await getRadarrMovieRecord(config, tmdbId); + } else { + throw error; // Rethrow other errors + } + } } - try { - await fetchJson(`${config.radarr.baseUrl}/api/v3/movie`, { - method: 'POST', - headers: { - 'X-Api-Key': config.radarr.apiKey, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - title: details.title || details.original_title || 'Movie', - qualityProfileId: radarrRequestConfig.qualityProfileId, - rootFolderPath: radarrRequestConfig.rootFolderPath, - tmdbId: details.id, - year: Number(String(details.release_date || '').slice(0, 4)) || 0, - minimumAvailability: 'released', - addOptions: { - monitored: config.radarr.monitor !== 'none', - searchForMovie: true - } - }) - }); - } catch (error) { - const message = error instanceof Error ? error.message.toLowerCase() : ''; - const looksLikeAlreadyExists = message.includes('already') || message.includes('exists') || message.includes('duplicate'); - - if (!looksLikeAlreadyExists) { - throw error; - } - - const existingMovie = await getRadarrMovieRecord(config, tmdbId); - if (!existingMovie?.id) { - throw error; - } - - if (existingMovie.hasFile) { - return; - } - - await fetchJson(`${config.radarr.baseUrl}/api/v3/command`, { - method: 'POST', - headers: { - 'X-Api-Key': config.radarr.apiKey, - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - name: 'MoviesSearch', - movieIds: [existingMovie.id], - qualityProfileId: radarrRequestConfig.qualityProfileId - }) - }); + // If we still don't have a movie record, something is wrong. + if (!movie?.id) { + throw new Error('Failed to add or find movie in Radarr.'); } + + // If movie is already downloaded, we're done. + if (movie.hasFile) { + return; + } + + // If movie is not downloaded, trigger a search. + await fetchJson(`${config.radarr.baseUrl}/api/v3/command`, { + method: 'POST', + headers: { + 'X-Api-Key': config.radarr.apiKey, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + name: 'MoviesSearch', + movieIds: [movie.id] + }) + }); } export async function requestSeries(config: AppConfig, tmdbId: number): Promise { diff --git a/src/App.tsx b/src/App.tsx index 330dc48..5378abd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1586,8 +1586,12 @@ function TitleDetailsModal(props: { || effectiveActiveSeasonMeta?.canDownload || (canRequest && !details?.sonarrSeriesId && typeof activeSeasonNumber === 'number') ) - const canDeleteSeasonAction = Boolean(effectiveActiveSeasonMeta?.canDelete) - const shouldShowDownloadSeasonAction = canDownloadSeasonAction && !canDeleteSeasonAction + const episodesForSeason = visibleEpisodes.filter(episode => episode.seasonId === seasonValue); + const isSeasonFullyDownloadedExceptUnaired = episodesForSeason.length > 0 && episodesForSeason.every( + (episode) => episode.availability === 'available' || episode.availability === 'unaired' + ); + const canDeleteSeasonAction = (Boolean(effectiveActiveSeasonMeta?.canDelete) || isSeasonFullyDownloadedExceptUnaired); + const shouldShowDownloadSeasonAction = canDownloadSeasonAction && !canDeleteSeasonAction; useEffect(() => { if (!details || details.mediaType !== 'series') { @@ -2296,7 +2300,11 @@ function TitleDetailsModal(props: { ) : null} - {formatEpisodeMeta(episode.subtitle)} + + {episode.availability === 'unaired' && episode.airDate + ? `${formatEpisodeMeta(episode.subtitle)} - Airs ${new Date(episode.airDate).toLocaleDateString('en-US', { day: 'numeric', month: 'short' })}` + : formatEpisodeMeta(episode.subtitle)} + ))} diff --git a/src/index.css b/src/index.css index f6dc064..c2c1256 100644 --- a/src/index.css +++ b/src/index.css @@ -723,7 +723,7 @@ img { gap: 1rem; overflow-x: auto; overflow-y: visible; - padding: 0 1rem; + padding: 0.5rem 1.5rem; scrollbar-width: none; }