Skip to content

Commit 699ef3d

Browse files
committed
fix trakt import fails if season not found in TMDB #528
1 parent ba429cc commit 699ef3d

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/app/providers/tmdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ def tv_with_seasons(media_id, season_numbers):
212212
# Create a new response object with 404 status
213213
not_found_response = requests.Response()
214214
not_found_response.status_code = 404
215-
raise requests.exceptions.HTTPError(msg, response=not_found_response)
215+
# Set the error attribute to match what ProviderAPIError expects
216+
not_found_error = type("Error", (), {"response": not_found_response})
217+
raise services.ProviderAPIError(msg, error=not_found_error, details=msg)
216218

217219
season_data = process_season(response[season_key])
218220

src/integrations/imports/simkl.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import app
99
from app.models import Media, MediaTypes, Sources
10+
from app.providers import services
1011
from integrations import helpers
1112
from integrations.helpers import MediaImportError, MediaImportUnexpectedError
1213

@@ -42,8 +43,8 @@ def get_token(request):
4243
headers=headers,
4344
params=params,
4445
)
45-
except requests.exceptions.HTTPError as error:
46-
if error.response.status_code == requests.codes.unauthorized:
46+
except services.ProviderAPIError as error:
47+
if error.status_code == requests.codes.unauthorized:
4748
msg = "Invalid SIMKL secret key."
4849
raise MediaImportError(msg) from error
4950
raise
@@ -149,8 +150,8 @@ def process_tv_list(tv_list, user, bulk_media, warnings):
149150

150151
try:
151152
metadata = app.providers.tmdb.tv_with_seasons(tmdb_id, season_numbers)
152-
except requests.exceptions.HTTPError as error:
153-
if error.response.status_code == requests.codes.not_found:
153+
except services.ProviderAPIError as error:
154+
if error.status_code == requests.codes.not_found:
154155
warnings.append(
155156
f"{title}: not found in {Sources.TMDB.label} "
156157
f"with ID {tmdb_id}.",
@@ -295,8 +296,8 @@ def process_movie_list(movie_list, user, bulk_media, warnings):
295296

296297
try:
297298
metadata = app.providers.tmdb.movie(tmdb_id)
298-
except requests.exceptions.HTTPError as error:
299-
if error.response.status_code == requests.codes.not_found:
299+
except services.ProviderAPIError as error:
300+
if error.status_code == requests.codes.not_found:
300301
warnings.append(
301302
f"{title}: not found in {Sources.TMDB.label} "
302303
f"with ID {tmdb_id}.",
@@ -359,8 +360,8 @@ def process_anime_list(anime_list, user, bulk_media, warnings):
359360

360361
try:
361362
metadata = app.providers.mal.anime(mal_id)
362-
except requests.exceptions.HTTPError as error:
363-
if error.response.status_code == requests.codes.not_found:
363+
except services.ProviderAPIError as error:
364+
if error.status_code == requests.codes.not_found:
364365
warnings.append(
365366
f"{title}: not found in {Sources.MAL.label} with ID {mal_id}.",
366367
)

src/integrations/imports/yamtrack.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import logging
22
from csv import DictReader
33

4-
import requests
54
from django.apps import apps
65
from django.conf import settings
76

87
import app
9-
import app.providers
108
from app.models import TV, Episode, MediaTypes, Season, Sources
9+
from app.providers import services
1110
from integrations import helpers
1211
from integrations.helpers import MediaImportError, MediaImportUnexpectedError
1312

@@ -65,7 +64,7 @@ def add_bulk_media(row, user, bulk_media, warnings):
6564
row["image"] = settings.IMG_NONE
6665
else:
6766
try:
68-
metadata = app.providers.services.get_media_metadata(
67+
metadata = services.get_media_metadata(
6968
media_type,
7069
row["media_id"],
7170
row["source"],
@@ -74,7 +73,7 @@ def add_bulk_media(row, user, bulk_media, warnings):
7473
)
7574
row["title"] = metadata["title"]
7675
row["image"] = metadata["image"]
77-
except requests.exceptions.HTTPError as e:
76+
except services.ProviderAPIError as e:
7877
warnings.append(
7978
f"Failed to fetch metadata for {row['media_id']}: {e!s}",
8079
)

0 commit comments

Comments
 (0)