fix(alldebrid): correct magnet status response model and file extraction - #1407
Conversation
The MagnetInfo model had a `files` field but the AllDebrid v4.1/magnet/status API returns `links`. Pydantic silently discarded the unknown field, leaving `files` as None and causing _get_magnet_files to always return None. - Add AllDebridMagnetLinkEntry model matching the actual links structure - Replace MagnetInfo.files with MagnetInfo.links - Make AllDebridFile.l optional (files within links[].files have no l field) - Rewrite _get_magnet_files to iterate links, injecting each link's URL into its files Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 9 minutes and 16 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAllDebrid magnet status models now accept compact file entries and error-info responses, file extraction follows the updated nested structure, and tests and fixtures cover the revised parsing and torrent-info behavior. ChangesAllDebrid magnet parsing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/program/services/downloaders/alldebrid.py`:
- Around line 621-633: The recursive file collection in
_add_link_to_files_recursive currently skips AllDebridMagnetLinkEntry metadata
when link_entry.files is empty, causing usable magnet entries to be dropped.
Update the handling in this branch to fall back to the entry’s filename, size,
and link fields when files is missing, and make sure _get_magnet_files can still
build an AllDebridFile from AllDebridMagnetLinkEntry even without a nested files
list.
- Line 29: Ruff is flagging the API-shaped field name `l` in
`AllDebridDownloadInfo` with E741, but it should stay aligned with the upstream
payload key. Add a targeted Ruff suppression on the `l` field declaration in
`alldebrid.py` instead of renaming the attribute, so the model stays compatible
while keeping lint green.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c6f88186-c746-4869-93cf-6b7bcdd1569c
📒 Files selected for processing (1)
src/program/services/downloaders/alldebrid.py
- Fall back to link entry metadata when links[].files is absent or empty - Add noqa: E741 on AllDebridFile.l to suppress ambiguous name lint; the field name is dictated by the upstream API payload Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…traction Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…bose log - Remove AllDebridMagnetLinkEntry (was based on v4 API; v4.1 uses files) - Restore MagnetInfo.files field (API returns files, not links) - Simplify _get_magnet_files to call _add_link_to_files_recursive directly - Add MagnetErrorInfo to AllDebridMagnet for invalid-magnet upload responses - Handle MagnetErrorInfo in add_torrent with a clean error message - Remove verbose debug log from normalize_magnets validator - Update test fixtures to v4.1 API format (files with embedded l links) - Rewrite tests to cover v4.1 structure and upload error handling Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/program/services/downloaders/alldebrid.py (1)
612-625: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value
return Noneinside the loop short-circuits after the first non-error magnet.The
return Noneon Line 625 lives in the loop body, so once the firstMagnetInfois reached (even with empty/no files) the function returns immediately and never inspects later magnets. This is fine for the single-magnet status query in practice, but if AllDebrid ever returns an error magnet followed by a valid one, ordering would matter. Consider moving thereturn Noneoutside the loop for clarity/robustness.♻️ Proposed adjustment
for magnet in magnets: if isinstance(magnet, AllDebridMagnetStatusResponse.MagnetErrorInfo): continue files = magnet.files if files: all_files: list[AllDebridFile] = [] self._add_link_to_files_recursive(files, "", all_files) if all_files: return all_files - return None + return None🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/program/services/downloaders/alldebrid.py` around lines 612 - 625, The magnet collection logic in the downloader returns None too early because the fallback is inside the loop over magnets. Update the flow in the magnet-processing method to only return after all entries have been checked, so later valid magnets are still considered if earlier ones are empty or non-usable. Keep the existing checks around AllDebridMagnetStatusResponse.MagnetErrorInfo, magnet.files, and _add_link_to_files_recursive, but move the None return to the end of the method.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/program/services/downloaders/alldebrid.py`:
- Around line 612-625: The magnet collection logic in the downloader returns
None too early because the fallback is inside the loop over magnets. Update the
flow in the magnet-processing method to only return after all entries have been
checked, so later valid magnets are still considered if earlier ones are empty
or non-usable. Keep the existing checks around
AllDebridMagnetStatusResponse.MagnetErrorInfo, magnet.files, and
_add_link_to_files_recursive, but move the None return to the end of the method.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8524b96e-76f2-4a80-b7b9-19c8ade24969
📒 Files selected for processing (4)
src/program/services/downloaders/alldebrid.pysrc/tests/test_alldebrid_downloader.pysrc/tests/test_data/alldebrid_magnet_status_one_downloading.jsonsrc/tests/test_data/alldebrid_magnet_status_one_ready.json
💤 Files with no reviewable changes (1)
- src/tests/test_data/alldebrid_magnet_status_one_downloading.json
AllDebrid rejecting an unknown hash is expected; WARNING was too noisy for routine scraping misses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The AllDebrid
v4.1/magnet/statusendpoint returns alinksarray on each magnet, butMagnetInfomodeled it asfiles. Pydantic silently discarded the unknownlinksfield, leavingfiles = Noneevery time — so_get_magnet_filesalways returnedNoneand instant availability never worked.Changes (all in
alldebrid.py):AllDebridMagnetLinkEntrymodel matching the actual API structure (link,filename,size,files)MagnetInfo.fileswithMagnetInfo.links: list[AllDebridMagnetLinkEntry] | NoneAllDebridFile.loptional (= ""), since files insidelinks[].filescarry nolfield — the link comes from the parentlink_entry.link_get_magnet_filesto iteratemagnet.links, injectinglink_entry.linkinto each file (and recursing into directories via the existing_add_link_to_files_recursive)Summary by CodeRabbit
Bug Fixes
Tests