Fix TV webhook failing when IMDB/TVDB returns series-level match#1218
Fix TV webhook failing when IMDB/TVDB returns series-level match#1218Redhair777 wants to merge 3 commits intoFuzzyGrim:devfrom
Conversation
'_find_tv_media_id' only checked tv_episode_results from the TMDB /find endpoint. When a webhook payload contains a series-level IMDB or TVDB ID, TMDB returns the show under tv_results instead. This caused the function to always return None, logging "No matching TMDB ID found for TV show" and silently dropping the webhook without tracking anything. Fix: also check tv_results as a fallback. When a series-level match is found, season and episode numbers are not available from the TMDB response and are instead read from the webhook payload's ParentIndexNumber and IndexNumber fields.
changed comments base.py.
Summary of ChangesHello @Redhair777, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where TV webhooks failed to track new shows when the TMDB API returned a series-level match instead of an episode-level match. By expanding the lookup logic to consider series-level results and falling back to the webhook payload for episode details, the system can now successfully process and track content that previously would have been silently dropped. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request aims to resolve an issue where series-level matches from TMDB's /find endpoint were ignored, hindering webhook content tracking when episode-level matches were absent. A critical security vulnerability related to integer validation for season_number and episode_number in webhook payloads, which could lead to application crashes and denial of service, has been identified and a solution provided. However, a potential regression for Plex integrations due to differing payload structures (Item vs Metadata keys) still needs to be addressed to ensure robust processing across all platforms.
| if season_number is None: | ||
| season_number = payload["Item"].get("ParentIndexNumber") | ||
| if episode_number is None: | ||
| episode_number = payload["Item"].get("IndexNumber") |
There was a problem hiding this comment.
The extraction of season_number and episode_number from the webhook payload lacks proper integer validation. Providing non-integer values can lead to application crashes and a denial of service due to TypeError or ValueError. The provided code suggestion addresses this by explicitly casting these values to integers and handling exceptions. However, the current hardcoded access to payload["Item"] is specific to Jellyfin/Emby and will cause a KeyError for Plex integrations, which use a Metadata key. This structural difference still needs to be addressed to ensure robust processing across all platforms.
if season_number is None:
try:
season_number = int(payload["Item"].get("ParentIndexNumber"))
except (TypeError, ValueError):
season_number = None
if episode_number is None:
try:
episode_number = int(payload["Item"].get("IndexNumber"))
except (TypeError, ValueError):
episode_number = None
Was trying to use Yamtrack to track content on apps outside of the usual JF/Plex/Emby via webhook. But currently it fails to add a new show to yamtrack if series-level metadata ID is returned.
What
Currently
_find_tv_media_idinbase.pyonly checkedtv_episode_resultsfrom the TMDB/findendpoint.Why
When a webhook payload contains a series-level IMDB or TVDB ID, TMDB returns the show under
tv_resultsinstead oftv_episode_results. This caused_find_tv_media_idto always return(None, None, None), logging "No matching TMDB ID found for TV show" and silently dropping the webhook without tracking anything.How
Also check
tv_resultsas a fallback. When a series-level match is found, season and episode numbers are not available from the TMDB response and are returned asNone. They are then read from the webhook payload'sParentIndexNumberandIndexNumberfields, which was already the existing behaviour in_process_tvfor this case.Files changed
app/integrations/webhooks/base.py