Repository navigation
fix: treat an out-of-range season as final instead of a transient error - #37
Conversation
Emby passes a year-based season number (Tagesschau S2024) straight to the API, which caps a season at 1000, so every such episode answered a 400 that this plugin classified as a client error: the client warned the body, the provider warned per episode and the scanner warned per item, every scan, on a request that can never succeed (jellyfin-plugin#39). Those coordinates cannot be expressed on /media, so the answer is final for the item. A 400 carrying the range message now maps to a new MediaFetchResult.Unsupported()/SegmentFetchResult.Unsupported(): the client logs it at debug, the provider warns once per series, the address is remembered for the session so later scans do not re-ask, and the scan skips the item without writing - IsLookupCompleted stays false so a completed 404 cannot make it ReplaceSegments with an empty list. ShouldCountTowardFailureLimit excludes it, or eight episodes of one year-based series would abort the scan. Serving those episodes still needs the API to accept season numbers above 1000.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
API rejection classification TheIntroDB/Api/MediaFetchResult.cs, TheIntroDB/Api/TheIntroDbClient.cs, TheIntroDB.Tests/ScanSafetyTests.cs |
The client recognizes HTTP 400 responses containing season or episode range errors and returns an unsupported result. Tests cover result classification and the rejection conditions. |
Provider result and session cache TheIntroDB/Providers/SegmentFetchResult.cs, TheIntroDB/Providers/TheIntroDbSegmentProvider.cs, TheIntroDB.Tests/ScanSafetyTests.cs |
The provider returns an unsupported segment result for rejected coordinates. It caches rejected lookup addresses for the session and logs one warning per series. Tests cover unsupported results and lookup reservation behavior. |
Scanner skip behavior and validation TheIntroDB/Services/TheIntroDbLibraryScanner.cs, README.md |
The scanner skips unsupported results without changing stored segments or counting them toward the failure limit. The README describes the year-based season case and its handling. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Sequence Diagram(s)
sequenceDiagram
participant API as TheIntroDB API
participant Client as TheIntroDbClient
participant Provider as TheIntroDbSegmentProvider
participant Scanner as TheIntroDbLibraryScanner
API->>Client: HTTP 400 with invalid season or episode range
Client->>Provider: Unsupported media result
Provider->>Provider: Cache rejected lookup address and log once per series
Provider->>Scanner: Unsupported segment result
Scanner->>Scanner: Skip item without changing stored segments
Possibly related PRs
- TheIntroDB/emby-plugin#35: PR
#35adds season and episode coordinates to API v4 lookups, which PR#37uses to identify out-of-range coordinate responses.
Merge Risk: 
Minimal · up to 03405
-
No actionable merge-blocking risk remains in the reviewed change.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main behavior change: an API 400 rejection for an out-of-range season is now treated as a final, unsupported result instead of a transient error. The changeset adds an Unsupported result state across MediaFetchResult, SegmentFetchResult, TheIntroDbClient, the segment provider, and the library scanner, and the objectives describe the same skip path. The title is concise, specific, and follows the conventional prefix style.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 6 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Review finding on this PR, verified against the scanner: it reserves a lookup before calling the provider and refunds it only when the result reports no API attempt (`!result.WasApiAttempted`). The session memo for an out-of-range season returned SegmentFetchResult.Unsupported(), which sets WasApiAttempted, so a cached skip kept its reservation: with enough such items sorting first, every run would spend MaxLookupsPerRun on the same cached items and never reach the rest of the library. The memo hit now returns NotAttempted() - no request goes out, exactly like the not-found cache hit below it - while a real HTTP 400 still returns Unsupported(). A test pins the flag contract the scanner's refund depends on. Also rewords the skip log and the README: the API raised its season cap to 9999 and the change is live, so the refusal only happens against an older API deployment, and the message must not assert the current bound.
0076a80 to
03405fa
Compare
Update after the API change shippedTheIntroDB/theintrodb-api#47 merged and is deployed — probed against production: So these episodes now fetch normally, and this PR's path only fires against a deployment that still caps a season at 1000 — which is why the classifier matches the message prefix and the skip log no longer asserts the current bound. README and the log line were reworded accordingly ( CodeRabbit's finding on the memo hit (it charged a reserved lookup even though no request went out) is fixed in the same commit: the memo now returns |
Why
The same defect as TheIntroDB/jellyfin-plugin#39, in this codebase: Emby passes the season number it reads from TVDB metadata straight through, and TVDB numbers the seasons of a year-based series by year — Tagesschau is S2024, S2025, … The API caps a season at 1000, so every episode of those series answers
Here that 400 became
MediaFetchResult.ClientError()→SegmentFetchResult.ClientError(): the client logged the body at Warn for every request, the provider logged a warning per episode, and the scanner logged a third warning per item ("TheIntroDB API rejected request … (client error)"). A 200-episode year-based season produced ~600 warning lines per scan, and every scan re-sent a request that cannot succeed.Nothing about the request is fixable on this side:
season+episodeis the only way/mediaaddresses an episode (the episode's TVDB id is already sent as a pin), so the coordinates are simply not expressible on this API version.What the PR does
TheIntroDbClient.IsUnsupportedCoordinateRejection(statusCode, body)(new, internal): a 400 whose body carries the API's range message (Invalid season. Must be between …/Invalid episode. Must be between …) is recognised as a refusal of the coordinates. Matching the message prefix keeps it correct if the API moves the bounds. The client logs it at Debug and reportsresult = "unsupported_coordinates"instead of the truncated body at Warn.MediaFetchResult.Unsupported()— a final outcome that is deliberately notIsError(which would retry it forever) and notIsNotFound(whose path makes the scan rewrite the item's segments with an empty list).SegmentFetchResult.Unsupported()—WasApiAttempted: true,IsLookupCompleted: false,IsError: false, plus anIsUnsupportedflag.TheIntroDbSegmentProvider— an unsupported answer warns once per series (the dedupe dictionaries are static, like_orderSkipsLogged, because a provider instance is short-lived), remembers the address for the rest of the session so later scans do not re-ask a known 400, and returns without writing anything for the item.IsLookupCompleted: falseis the point:truewould make the scanReplaceSegments(...)with an empty list and wipe what the item already has.TheIntroDbLibraryScanner— handles the new flag explicitly (processed++; continue;) before the failure-counting branch, andShouldCountTowardFailureLimitexcludes it. Without that, an unsupported run of items would have counted as consecutive API failures and aborted the scan ("API may be down") after 8 episodes of one year-based series.Segments for those series need the API to accept season numbers above 1000 (TheIntroDB/theintrodb-api#47 raises the cap to 9999). Until then this PR's contract is: handled gracefully, one line per series, no wasted requests, nothing deleted.
Tests
dotnet test TheIntroDB.sln→ 117 passed, 0 failed (was 104 onmain; +13 cases).dotnet buildclean for both projects (thenetstandard2.0library and thenet8.0test project); the only warnings are the five pre-existingCS8625s atScanSafetyTestslines 79–130, which this PR does not touch.The new coverage is the classification and the result contract, and both are pinned by mutation:
IsUnsupportedCoordinateRejection→ never matches) → 3 failures, exactly the range rows ofOnlyTheSeasonOrEpisodeRangeIsClassifiedAsUnsupportedCoordinates(including the case-insensitive one).ShouldCountTowardFailureLimit(SegmentFetchResult.Unsupported())is asserted false — that is the assertion standing between a year-based season and an aborted scan.curl "https://api.theintrodb.org/v4/media?tvdb_id=252244&season=2024&episode=196"→ that exact 400; the same request withseason=1→404 no_submissions. A malformed-season body (Invalid season format) is asserted to stay a loud error rather than becoming a silent skip.Honest limits: the provider/scanner branch itself has no runtime test here (it needs
ILibraryManagerplus a live item, and this repo mocks noPlugininstance), so it is covered by the flag-contract tests plus the build. And the API has not been re-pointed at a server that accepts 2024 — the classification was verified against the live 400 body above.Not in this PR
MaxEpisodeNumber(10000) and the other result kinds are untouched.Summary by CodeRabbit