fix(requests): handle when tvdbid is null (#657)

Co-authored-by: sct <sctsnipe@gmail.com>
pull/720/head
Jakob Ankarhem 3 years ago committed by GitHub
parent a3fe4e6321
commit 2da0da826a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1143,6 +1143,135 @@ components:
type: array
items:
$ref: '#/components/schemas/MovieResult'
SonarrSeries:
type: object
properties:
title:
type: string
example: COVID-25
sortTitle:
type: string
example: covid 25
seasonCount:
type: number
example: 1
status:
type: string
example: upcoming
overview:
type: string
example: The thread is picked up again by Marianne Schmidt which ...
network:
type: string
example: CBS
airTime:
type: string
example: 02:15
images:
type: array
items:
type: object
properties:
coverType:
type: string
example: banner
url:
type: string
example: /sonarr/MediaCoverProxy/6467f05d9872726ad08cbf920e5fee4bf69198682260acab8eab5d3c2c958e92/5c8f116c6aa5c.jpg
remotePoster:
type: string
example: https://artworks.thetvdb.com/banners/posters/5c8f116129983.jpg
seasons:
type: array
items:
type: object
properties:
seasonNumber:
type: number
example: 1
monitored:
type: boolean
example: true
year:
type: number
example: 2015
path:
type: string
profileId:
type: number
languageProfileId:
type: number
seasonFolder:
type: boolean
monitored:
type: boolean
useSceneNumbering:
type: boolean
runtime:
type: number
tvdbId:
type: number
example: 12345
tvRageId:
type: number
tvMazeId:
type: number
firstAired:
type: string
lastInfoSync:
type: string
nullable: true
seriesType:
type: string
cleanTitle:
type: string
imdbId:
type: string
titleSlug:
type: string
certification:
type: string
genres:
type: array
items:
type: string
tags:
type: array
items:
type: string
added:
type: string
ratings:
type: array
items:
type: object
properties:
votes:
type: number
value:
type: number
qualityProfileId:
type: number
id:
type: number
nullable: true
rootFolderPath:
type: string
nullable: true
addOptions:
type: array
items:
type: object
properties:
ignoreEpisodesWithFiles:
type: boolean
nullable: true
ignoreEpisodesWithoutFiles:
type: boolean
nullable: true
searchForMissingEpisodes:
type: boolean
nullable: true
securitySchemes:
cookieAuth:
type: apiKey
@ -3193,6 +3322,28 @@ paths:
$ref: '#/components/schemas/SonarrSettings'
profiles:
$ref: '#/components/schemas/ServiceProfile'
/service/sonarr/lookup/{tmdbId}:
get:
summary: Returns a list of series from sonarr
description: Returns a list of series returned by searching for the name in sonarr
tags:
- service
parameters:
- in: path
name: tmdbId
required: true
schema:
type: number
example: 0
responses:
'200':
description: Request successful
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/SonarrSeries'
security:
- cookieAuth: []

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

@ -94,6 +94,28 @@ class SonarrAPI {
});
}
public async getSeriesByTitle(title: string): Promise<SonarrSeries[]> {
try {
const response = await this.axios.get<SonarrSeries[]>('/series/lookup', {
params: {
term: title,
},
});
if (!response.data[0]) {
throw new Error('No series found');
}
return response.data;
} catch (e) {
logger.error('Error retrieving series by series title', {
label: 'Sonarr API',
message: e.message,
});
throw new Error('No series found');
}
}
public async getSeriesByTvdbId(id: number): Promise<SonarrSeries> {
try {
const response = await this.axios.get<SonarrSeries[]>('/series/lookup', {

@ -427,9 +427,12 @@ export class MediaRequest {
});
logger.info('Sent request to Radarr', { label: 'Media Request' });
} catch (e) {
throw new Error(
`[MediaRequest] Request failed to send to radarr: ${e.message}`
);
const errorMessage = `Request failed to send to radarr: ${e.message}`;
logger.error('Request failed to send to Radarr', {
label: 'Media Request',
errorMessage,
});
throw new Error(errorMessage);
}
}
}
@ -501,8 +504,10 @@ export class MediaRequest {
}:${sonarrSettings.port}${sonarrSettings.baseUrl ?? ''}/api`,
});
const series = await tmdb.getTvShow({ tvId: media.tmdbId });
const tvdbId = series.external_ids.tvdb_id ?? media.tvdbId;
if (!series.external_ids.tvdb_id) {
if (!tvdbId) {
this.handleRemoveParentUpdate();
throw new Error('Series was missing tvdb id');
}
@ -550,7 +555,7 @@ export class MediaRequest {
profileId: qualityProfile,
rootFolderPath: rootFolder,
title: series.name,
tvdbid: series.external_ids.tvdb_id,
tvdbid: tvdbId,
seasons: this.seasons.map((season) => season.seasonNumber),
seasonFolder: sonarrSettings.enableSeasonFolders,
seriesType,
@ -590,9 +595,12 @@ export class MediaRequest {
});
logger.info('Sent request to Sonarr', { label: 'Media Request' });
} catch (e) {
throw new Error(
`[MediaRequest] Request failed to send to sonarr: ${e.message}`
);
const errorMessage = `Request failed to send to sonarr: ${e.message}`;
logger.error('Request failed to send to Sonarr', {
label: 'Media Request',
errorMessage,
});
throw new Error(errorMessage);
}
}
}

@ -109,7 +109,7 @@ requestRoutes.post(
if (!media) {
media = new Media({
tmdbId: tmdbMedia.id,
tvdbId: tmdbMedia.external_ids.tvdb_id,
tvdbId: req.body.tvdbId ?? tmdbMedia.external_ids.tvdb_id,
status: !req.body.is4k ? MediaStatus.PENDING : MediaStatus.UNKNOWN,
status4k: req.body.is4k ? MediaStatus.PENDING : MediaStatus.UNKNOWN,
mediaType: req.body.mediaType,

@ -6,6 +6,8 @@ import {
ServiceCommonServerWithDetails,
} from '../interfaces/api/serviceInterfaces';
import { getSettings } from '../lib/settings';
import TheMovieDb from '../api/themoviedb';
import logger from '../logger';
const serviceRoutes = Router();
@ -100,13 +102,13 @@ serviceRoutes.get<{ sonarrId: string }>(
const settings = getSettings();
const sonarrSettings = settings.sonarr.find(
(radarr) => radarr.id === Number(req.params.sonarrId)
(sonarr) => sonarr.id === Number(req.params.sonarrId)
);
if (!sonarrSettings) {
return next({
status: 404,
message: 'Radarr server with provided ID does not exist.',
message: 'Sonarr server with provided ID does not exist.',
});
}
@ -145,4 +147,52 @@ serviceRoutes.get<{ sonarrId: string }>(
}
);
serviceRoutes.get<{ tmdbId: string }>(
'/sonarr/lookup/:tmdbId',
async (req, res, next) => {
const settings = getSettings();
const tmdb = new TheMovieDb();
const sonarrSettings = settings.sonarr[0];
if (!sonarrSettings) {
logger.error('No sonarr server has been setup', {
label: 'Media Request',
});
return next({
status: 404,
message: 'No sonarr server has been setup',
});
}
const sonarr = new SonarrAPI({
apiKey: sonarrSettings.apiKey,
url: `${sonarrSettings.useSsl ? 'https' : 'http'}://${
sonarrSettings.hostname
}:${sonarrSettings.port}${sonarrSettings.baseUrl ?? ''}/api`,
});
try {
const tv = await tmdb.getTvShow({
tvId: Number(req.params.tmdbId),
language: req.query.language as string,
});
const response = await sonarr.getSeriesByTitle(tv.name);
return res.status(200).json(response);
} catch (e) {
logger.error('Failed to fetch tvdb search results', {
label: 'Media Request',
message: e.message,
});
return next({
status: 500,
message: 'Something went wrong trying to fetch series information',
});
}
}
);
export default serviceRoutes;

@ -165,7 +165,11 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
<div className="flex flex-col items-center pt-4 lg:flex-row lg:items-end">
<div className="lg:mr-4">
<img
src={`//image.tmdb.org/t/p/w600_and_h900_bestv2${data.posterPath}`}
src={
data.posterPath
? `//image.tmdb.org/t/p/w600_and_h900_bestv2${data.posterPath}`
: '/images/overseerr_poster_not_found.png'
}
alt=""
className="w-32 rounded shadow md:rounded-lg md:shadow-2xl md:w-44 lg:w-52"
/>

@ -39,6 +39,7 @@ const messages = defineMessages({
errorediting: 'Something went wrong editing the request.',
requestedited: 'Request edited.',
autoapproval: 'Auto Approval',
requesterror: 'Something went wrong when trying to request media.',
});
interface RequestModalProps extends React.HTMLAttributes<HTMLDivElement> {
@ -78,41 +79,50 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
const sendRequest = useCallback(async () => {
setIsUpdating(true);
let overrideParams = {};
if (requestOverrides) {
overrideParams = {
serverId: requestOverrides.server,
profileId: requestOverrides.profile,
rootFolder: requestOverrides.folder,
};
}
const response = await axios.post<MediaRequest>('/api/v1/request', {
mediaId: data?.id,
mediaType: 'movie',
is4k,
...overrideParams,
});
if (response.data) {
if (onComplete) {
onComplete(
hasPermission(Permission.AUTO_APPROVE) ||
hasPermission(Permission.AUTO_APPROVE_MOVIE)
? MediaStatus.PROCESSING
: MediaStatus.PENDING
try {
let overrideParams = {};
if (requestOverrides) {
overrideParams = {
serverId: requestOverrides.server,
profileId: requestOverrides.profile,
rootFolder: requestOverrides.folder,
};
}
const response = await axios.post<MediaRequest>('/api/v1/request', {
mediaId: data?.id,
mediaType: 'movie',
is4k,
...overrideParams,
});
if (response.data) {
if (onComplete) {
onComplete(
hasPermission(Permission.AUTO_APPROVE) ||
hasPermission(Permission.AUTO_APPROVE_MOVIE)
? MediaStatus.PROCESSING
: MediaStatus.PENDING
);
}
addToast(
<span>
{intl.formatMessage(messages.requestSuccess, {
title: data?.title,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
);
}
addToast(
<span>
{intl.formatMessage(messages.requestSuccess, {
title: data?.title,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
);
} catch (e) {
addToast(intl.formatMessage(messages.requesterror), {
appearance: 'error',
autoDismiss: true,
});
} finally {
setIsUpdating(false);
}
}, [data, onComplete, addToast, requestOverrides]);
@ -123,25 +133,29 @@ const MovieRequestModal: React.FC<RequestModalProps> = ({
const cancelRequest = async () => {
setIsUpdating(true);
const response = await axios.delete<MediaRequest>(
`/api/v1/request/${activeRequest?.id}`
);
if (response.status === 204) {
if (onComplete) {
onComplete(MediaStatus.UNKNOWN);
}
addToast(
<span>
{intl.formatMessage(messages.requestCancel, {
title: data?.title,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
try {
const response = await axios.delete<MediaRequest>(
`/api/v1/request/${activeRequest?.id}`
);
if (response.status === 204) {
if (onComplete) {
onComplete(MediaStatus.UNKNOWN);
}
addToast(
<span>
{intl.formatMessage(messages.requestCancel, {
title: data?.title,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
);
}
} catch (e) {
setIsUpdating(false);
}
};

@ -0,0 +1,114 @@
import React from 'react';
import Alert from '../../Common/Alert';
import Modal from '../../Common/Modal';
import { SmallLoadingSpinner } from '../../Common/LoadingSpinner';
import useSWR from 'swr';
import { defineMessages, useIntl } from 'react-intl';
import { SonarrSeries } from '../../../../server/api/sonarr';
const messages = defineMessages({
next: 'Next',
notvdbid: 'Manual match required',
notvdbiddescription:
"We couldn't automatically match your request. Please select the correct match from the list below.",
nosummary: 'No summary for this title was found.',
});
interface SearchByNameModalProps {
setTvdbId: (id: number) => void;
tvdbId: number | undefined;
loading: boolean;
onCancel?: () => void;
closeModal: () => void;
modalTitle: string;
tmdbId: number;
}
const SearchByNameModal: React.FC<SearchByNameModalProps> = ({
setTvdbId,
tvdbId,
loading,
onCancel,
closeModal,
modalTitle,
tmdbId,
}) => {
const intl = useIntl();
const { data, error } = useSWR<SonarrSeries[]>(
`/api/v1/service/sonarr/lookup/${tmdbId}`
);
const handleClick = (tvdbId: number) => {
setTvdbId(tvdbId);
};
return (
<Modal
loading={loading && !error}
backgroundClickable
onCancel={onCancel}
onOk={closeModal}
title={modalTitle}
okText={intl.formatMessage(messages.next)}
okDisabled={!tvdbId}
okButtonType="primary"
iconSvg={
<svg
className="w-6 h-6"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"
/>
</svg>
}
>
<Alert title={intl.formatMessage(messages.notvdbid)} type="info">
{intl.formatMessage(messages.notvdbiddescription)}
</Alert>
{!data && !error && <SmallLoadingSpinner />}
<div className="grid grid-cols-1 gap-4 pb-2 md:grid-cols-2">
{data?.slice(0, 6).map((item) => (
<button
key={item.tvdbId}
className="container flex flex-col items-center justify-center h-40 mx-auto space-y-4 transition scale-100 outline-none cursor-pointer focus:ring focus:ring-indigo-500 focus:ring-opacity-70 focus:outline-none rounded-xl transform-gpu hover:scale-105"
onClick={() => handleClick(item.tvdbId)}
>
<div
className={`bg-gray-600 h-40 overflow-hidden w-full flex items-center p-2 rounded-xl shadow transition ${
tvdbId === item.tvdbId ? 'ring ring-indigo-500' : ''
} `}
>
<div className="flex items-center flex-none w-24 space-x-4">
<img
src={
item.remotePoster ??
'/images/overseerr_poster_not_found.png'
}
alt={item.title}
className="w-auto rounded-md h-100"
/>
</div>
<div className="self-start flex-grow p-3 text-left">
<div className="text-sm font-medium text-grey-200">
{item.title}
</div>
<div className="h-24 overflow-hidden text-sm text-gray-400">
{item.overview ?? intl.formatMessage(messages.nosummary)}
</div>
</div>
</div>
</button>
))}
</div>
</Modal>
);
};
export default SearchByNameModal;

@ -18,6 +18,7 @@ import globalMessages from '../../i18n/globalMessages';
import SeasonRequest from '../../../server/entity/SeasonRequest';
import Alert from '../Common/Alert';
import AdvancedRequester, { RequestOverrides } from './AdvancedRequester';
import SearchByNameModal from './SearchByNameModal';
const messages = defineMessages({
requestadmin: 'Your request will be immediately approved.',
@ -40,6 +41,12 @@ const messages = defineMessages({
requestedited: 'Request edited.',
requestcancelled: 'Request cancelled.',
autoapproval: 'Auto Approval',
requesterror: 'Something went wrong when trying to request media.',
next: 'Next',
notvdbid: 'No TVDB id was found connected on TMDB',
notvdbiddescription:
'Either add the TVDB id to TMDB and come back later, or select the correct match below.',
backbutton: 'Back',
});
interface RequestModalProps extends React.HTMLAttributes<HTMLDivElement> {
@ -73,6 +80,12 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
);
const intl = useIntl();
const { hasPermission } = useUser();
const [searchModal, setSearchModal] = useState<{
show: boolean;
}>({
show: true,
});
const [tvdbId, setTvdbId] = useState<number | undefined>(undefined);
const updateRequest = async () => {
if (!editRequest) {
@ -129,38 +142,47 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
if (onUpdating) {
onUpdating(true);
}
let overrideParams = {};
if (requestOverrides) {
overrideParams = {
serverId: requestOverrides.server,
profileId: requestOverrides.profile,
rootFolder: requestOverrides.folder,
};
}
const response = await axios.post<MediaRequest>('/api/v1/request', {
mediaId: data?.id,
tvdbId: data?.externalIds.tvdbId,
mediaType: 'tv',
is4k,
seasons: selectedSeasons,
...overrideParams,
});
if (response.data) {
if (onComplete) {
onComplete(response.data.media.status);
try {
let overrideParams = {};
if (requestOverrides) {
overrideParams = {
serverId: requestOverrides.server,
profileId: requestOverrides.profile,
rootFolder: requestOverrides.folder,
};
}
addToast(
<span>
{intl.formatMessage(messages.requestSuccess, {
title: data?.name,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
);
const response = await axios.post<MediaRequest>('/api/v1/request', {
mediaId: data?.id,
tvdbId: tvdbId ?? data?.externalIds.tvdbId,
mediaType: 'tv',
is4k,
seasons: selectedSeasons,
...overrideParams,
});
if (response.data) {
if (onComplete) {
onComplete(response.data.media.status);
}
addToast(
<span>
{intl.formatMessage(messages.requestSuccess, {
title: data?.name,
strong: function strong(msg) {
return <strong>{msg}</strong>;
},
})}
</span>,
{ appearance: 'success', autoDismiss: true }
);
}
} catch (e) {
addToast(intl.formatMessage(messages.requesterror), {
appearance: 'error',
autoDismiss: true,
});
} finally {
if (onUpdating) {
onUpdating(false);
}
@ -279,11 +301,24 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
return seasonRequest;
};
return (
return !data?.externalIds.tvdbId && searchModal.show ? (
<SearchByNameModal
tvdbId={tvdbId}
setTvdbId={setTvdbId}
closeModal={() => setSearchModal({ show: false })}
loading={!data && !error}
onCancel={onCancel}
modalTitle={intl.formatMessage(
is4k ? messages.request4ktitle : messages.requesttitle,
{ title: data?.name }
)}
tmdbId={tmdbId}
/>
) : (
<Modal
loading={!data && !error}
backgroundClickable
onCancel={onCancel}
onCancel={tvdbId ? () => setSearchModal({ show: true }) : onCancel}
onOk={() => (editRequest ? updateRequest() : sendRequest())}
title={intl.formatMessage(
is4k ? messages.request4ktitle : messages.requesttitle,
@ -302,6 +337,11 @@ const TvRequestModal: React.FC<RequestModalProps> = ({
okButtonType={
editRequest && selectedSeasons.length === 0 ? 'danger' : `primary`
}
cancelText={
tvdbId
? intl.formatMessage(messages.backbutton)
: intl.formatMessage(globalMessages.cancel)
}
iconSvg={
<svg
className="w-6 h-6"

@ -80,7 +80,9 @@ const TitleCard: React.FC<TitleCardProps> = ({
showDetail ? 'scale-105' : ''
}`}
style={{
backgroundImage: `url(//image.tmdb.org/t/p/w300_and_h450_face${image})`,
backgroundImage: image
? `url(//image.tmdb.org/t/p/w300_and_h450_face${image})`
: `url('/images/overseerr_poster_not_found_logo_top.png')`,
}}
onMouseEnter={() => {
if (!isTouch) {

@ -134,14 +134,22 @@
"components.RequestModal.AdvancedRequester.loadingprofiles": "Loading profiles…",
"components.RequestModal.AdvancedRequester.qualityprofile": "Quality Profile",
"components.RequestModal.AdvancedRequester.rootfolder": "Root Folder",
"components.RequestModal.SearchByNameModal.next": "Next",
"components.RequestModal.SearchByNameModal.nosummary": "No summary for this title was found.",
"components.RequestModal.SearchByNameModal.notvdbid": "Manual match required",
"components.RequestModal.SearchByNameModal.notvdbiddescription": "We couldn't automatically match your request. Please select the correct match from the list below.",
"components.RequestModal.autoapproval": "Auto Approval",
"components.RequestModal.backbutton": "Back",
"components.RequestModal.cancel": "Cancel Request",
"components.RequestModal.cancelling": "Cancelling…",
"components.RequestModal.cancelrequest": "This will remove your request. Are you sure you want to continue?",
"components.RequestModal.close": "Close",
"components.RequestModal.errorediting": "Something went wrong editing the request.",
"components.RequestModal.extras": "Extras",
"components.RequestModal.next": "Next",
"components.RequestModal.notrequested": "Not Requested",
"components.RequestModal.notvdbid": "No TVDB id was found connected on TMDB",
"components.RequestModal.notvdbiddescription": "Either add the TVDB id to TMDB and come back later, or select the correct match below.",
"components.RequestModal.numberofepisodes": "# of Episodes",
"components.RequestModal.pending4krequest": "Pending request for {title} in 4K",
"components.RequestModal.pendingrequest": "Pending request for {title}",
@ -154,6 +162,7 @@
"components.RequestModal.requestadmin": "Your request will be immediately approved.",
"components.RequestModal.requestcancelled": "Request cancelled.",
"components.RequestModal.requestedited": "Request edited.",
"components.RequestModal.requesterror": "Something went wrong when trying to request media.",
"components.RequestModal.requestfrom": "There is currently a pending request from {username}",
"components.RequestModal.requesting": "Requesting…",
"components.RequestModal.requestseasons": "Request {seasonCount} {seasonCount, plural, one {Season} other {Seasons}}",

Loading…
Cancel
Save