Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions list_sync/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,11 @@ def process_media_item(item: Dict[str, Any], overseerr_client: OverseerrClient,

try:
# Import Trakt search functions
from .providers.trakt import search_trakt_by_imdb_id, search_trakt_by_title
from .providers.trakt import search_trakt_by_imdb_id, search_trakt_by_title, is_trakt_configured

search_result = None
match_method = None
trakt_configured = is_trakt_configured()

# METHOD 1: Direct TMDB ID lookup (fastest, most reliable)
if tmdb_id:
Expand All @@ -560,7 +561,9 @@ def process_media_item(item: Dict[str, Any], overseerr_client: OverseerrClient,
logging.info(f"✅ SUCCESS: Direct TMDB ID lookup")

# METHOD 2: IMDB ID → Trakt → TMDB ID
if not search_result and imdb_id:
if not search_result and imdb_id and not trakt_configured:
logging.info("⏭️ METHOD 2 skipped: Trakt not configured (no TRAKT_CLIENT_ID)")
elif not search_result and imdb_id:
logging.info(f"🔍 METHOD 2: IMDB ID → Trakt → TMDB ID (IMDB: {imdb_id})")
trakt_result = search_trakt_by_imdb_id(imdb_id)
if trakt_result and trakt_result.get('tmdb_id'):
Expand All @@ -584,7 +587,9 @@ def process_media_item(item: Dict[str, Any], overseerr_client: OverseerrClient,
logging.info(f"⚠️ WARNING: Trakt could not resolve IMDB ID {imdb_id} to TMDB ID")

# METHOD 3: Title/Year → Trakt → TMDB ID
if not search_result:
if not search_result and not trakt_configured:
logging.info("⏭️ METHOD 3 skipped: Trakt not configured (no TRAKT_CLIENT_ID)")
elif not search_result:
logging.info(f"🔍 METHOD 3: Title/Year → Trakt → TMDB ID")
trakt_result = search_trakt_by_title(search_title, year, media_type)
if trakt_result and trakt_result.get('tmdb_id'):
Expand Down
19 changes: 19 additions & 0 deletions list_sync/providers/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ def get_trakt_client_id() -> str:
)


def is_trakt_configured() -> bool:
"""
Check whether a Trakt Client ID is configured, without raising.

Used to skip Trakt-dependent lookup methods (IMDB->TMDB, Title->TMDB)
entirely when Trakt isn't set up, instead of attempting a network call
that's guaranteed to fail. This also avoids tripping Trakt's rate
limiter on every single processed item when Trakt is simply unused.

Returns:
bool: True if a Trakt Client ID is available from config or env.
"""
try:
get_trakt_client_id()
return True
except ValueError:
return False


def get_trakt_special_items_limit() -> int:
"""
Get the items limit for special Trakt lists.
Expand Down