Skip to content

Comments

fix: validate season number when matching episode torrents#1368

Open
thescottthompson wants to merge 1 commit intorivenmedia:mainfrom
thescottthompson:fix/episode-season-matching
Open

fix: validate season number when matching episode torrents#1368
thescottthompson wants to merge 1 commit intorivenmedia:mainfrom
thescottthompson:fix/episode-season-matching

Conversation

@thescottthompson
Copy link

@thescottthompson thescottthompson commented Feb 7, 2026

Summary

  • Fixes a bug where torrents from different seasons were incorrectly attached to episodes
  • When matching episode torrents, the code now validates both episode AND season numbers

Problem

When scraping for episodes like Bob's Burgers S15E12, the parser would attach torrents from other seasons (e.g., S12E12, S13E12, S14E12) because it only checked the episode number.

This caused episodes to get stuck in "Scraped" state with downloads failing with "No valid files found" - the torrent contained the right episode number but from the wrong season.

Evidence from DEBUG logs

Before the fix, searching for Bob's Burgers S15E12 returned:

Found 5 streams for Bob's Burgers S15E12
[Rank: 750] Bobs Burgers S13E12...
[Rank: 350] Bob s Burgers S14E12...
[Rank: 250] Bobs Burgers S12E12...

None of the 5 streams were actually for S15!

Other examples observed:

  • Bob's Burgers S11E20 got streams for S12E20, S13E20, S15E20
  • Grey's Anatomy S22E05 got stream for S12E05
  • Grey's Anatomy S17E09 got stream for S14E09

Solution

When torrent.data.episodes is present, the code now:

  1. Checks that the episode number matches (existing behavior)
  2. Also verifies that the season number matches if torrent.data.seasons is available

Test plan

  • Tested on production instance with Bob's Burgers, Grey's Anatomy, and Schitt's Creek
  • Verified that wrong-season torrents are now filtered out
  • Verified that correct-season torrents still pass through
  • Confirmed episodes transition properly through states after fix

🤖 Generated with Claude Code

Summary by CodeRabbit

Bug Fixes

  • Improved episode matching accuracy for torrents by implementing combined episode and season validation to prevent incorrect cross-season matches (e.g., S12E05 incorrectly matching S22E05).
  • Enhanced handling for torrents containing season data to ensure proper season alignment verification.

Previously, when filtering torrents for an Episode item, the code only
checked if the episode number matched (e.g., E12). This caused torrents
from different seasons (e.g., S12E12) to be incorrectly attached to
episodes from other seasons (e.g., S15E12).

The fix adds season validation when torrent.data.episodes is present:
- Check that the episode number matches (existing behavior)
- Also verify that the season number matches if available

This prevents mismatches like:
- Bob's Burgers S15E12 getting streams for S12E12, S13E12, S14E12
- Grey's Anatomy S22E05 getting streams for S12E05

Without this fix, episodes get stuck in "Scraped" state because all
attached streams fail with "No valid files found" - the torrent
contains the right episode number but from the wrong season.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Walkthrough

Refines Episode matching logic in torrent processing to require both episode and season verification, preventing cross-season mismatches. Extends season alignment validation when season data exists without episode information.

Changes

Cohort / File(s) Summary
Episode Matching Logic Refinement
src/program/services/scrapers/shared.py
Refines Episode matching validation to require both episode_matches and season_matches to be true for skip decisions. Introduces parent_season reference and extends season alignment checks for torrents with season data but no episodes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through seasons fine,
Matching episodes, line by line,
No more S12 meets S22 by mistake,
Both checks aligned for matching's sake!
wiggles nose

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is comprehensive with problem statement, solution, and test results, but does not address the template's required checklist items for tests and documentation. Add explicit statements confirming whether tests and documentation were added/updated, and check the corresponding boxes in the PR template checklist.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding season number validation to episode torrent matching logic.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dreulavelle
Copy link
Member

I'll take a look at this sometime this week. This is definitely a bug as it should only find the same episode, or same season content.. other episodes, and even other seasons shouldn't show up when searching by season/episode.

@dreulavelle
Copy link
Member

Can you list some torrent examples as well. It's possible they got mis-parsed as well.

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.

2 participants