Skip to content

Fix TV webhook failing when IMDB/TVDB returns series-level match#1218

Open
Redhair777 wants to merge 3 commits intoFuzzyGrim:devfrom
Redhair777:patch-1
Open

Fix TV webhook failing when IMDB/TVDB returns series-level match#1218
Redhair777 wants to merge 3 commits intoFuzzyGrim:devfrom
Redhair777:patch-1

Conversation

@Redhair777
Copy link
Copy Markdown

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_id in base.py only checked tv_episode_results from the TMDB /find endpoint.

Why

When a webhook payload contains a series-level IMDB or TVDB ID, TMDB returns the show under tv_results instead of tv_episode_results. This caused _find_tv_media_id to 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_results as a fallback. When a series-level match is found, season and episode numbers are not available from the TMDB response and are returned as None. They are then read from the webhook payload's ParentIndexNumber and IndexNumber fields, which was already the existing behaviour in _process_tv for this case.

Files changed

  • app/integrations/webhooks/base.py

'_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.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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

  • Enhanced TV Media ID Resolution: The _find_tv_media_id function now includes a fallback mechanism to check "tv_results" from TMDB's /find endpoint, in addition to "tv_episode_results", to correctly identify TV shows when series-level metadata IDs are provided.
  • Improved Season/Episode Number Retrieval: The _process_tv function has been updated to retrieve season and episode numbers directly from the webhook payload's "ParentIndexNumber" and "IndexNumber" fields if they are not resolved from TMDB, preventing tracking failures for series-level matches.
Changelog
  • src/integrations/webhooks/base.py
    • Modified _find_tv_media_id to check "tv_results" from TMDB when "tv_episode_results" are not found.
    • Implemented logic in _process_tv to use "ParentIndexNumber" and "IndexNumber" from the webhook payload for season and episode numbers if TMDB does not provide them.
    • Added logging for cases where season/episode numbers cannot be determined.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +65 to +68
if season_number is None:
season_number = payload["Item"].get("ParentIndexNumber")
if episode_number is None:
episode_number = payload["Item"].get("IndexNumber")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-medium medium

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant