fix: auto-blacklist streams that return 451 Infringing Torrent#1367
fix: auto-blacklist streams that return 451 Infringing Torrent#1367thescottthompson wants to merge 1 commit intorivenmedia:mainfrom
Conversation
When Real-Debrid returns HTTP 451 for a torrent (flagged as infringing), the stream should be immediately blacklisted since it will never succeed on this debrid service. Previously, these streams would continue to be retried, wasting API calls and contributing to circuit breaker trips. Changes: - Add InfringingTorrentException in models.py - Raise InfringingTorrentException on 451 errors in realdebrid.py - Handle InfringingTorrentException in __init__.py to blacklist immediately Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughA new exception type for infringing torrents is introduced to the downloader service. RealDebrid returns a 451 error code when torrents are infringing; this is now caught and converted to an Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/program/services/downloaders/realdebrid.py (1)
279-294:⚠️ Potential issue | 🟡 MinorUse exception chaining:
raise InfringingTorrentException(infohash) from e.Ruff B904 correctly flags this. Raising inside an
exceptblock withoutfrommakes it ambiguous whether this is a deliberate conversion or an accidental error during handling. Chaining withfrom epreserves the originalRealDebridErrorcontext for debugging.Proposed fix
# 451 = Infringing torrent - raise special exception for immediate blacklisting # This is a permanent failure, the torrent will never work on this debrid service if "[451]" in error_msg: - raise InfringingTorrentException(infohash) + raise InfringingTorrentException(infohash) from e
🤖 Fix all issues with AI agents
In `@src/program/services/downloaders/__init__.py`:
- Around line 187-195: The InfringingTorrentException handler in the inner loop
should stop trying other services for the same stream and remove the unused
exception binding: replace the unused "except InfringingTorrentException as e:"
with "except InfringingTorrentException:" and change the trailing "continue"
after calling item.blacklist_stream(stream) to "break" so the loop over
available_services exits for that blacklisted stream (affecting the
InfringingTorrentException handler that logs using stream.infohash and
service.key and sets stream_failed_on_all_services).
| except InfringingTorrentException as e: | ||
| # 451 Infringing Torrent - immediately blacklist, do not retry | ||
| # This is a permanent failure from the debrid service | ||
| logger.warning( | ||
| f"Stream {stream.infohash} flagged as infringing by {service.key}, blacklisting immediately" | ||
| ) | ||
| item.blacklist_stream(stream) | ||
| stream_failed_on_all_services = False # Already handled via blacklist | ||
| continue |
There was a problem hiding this comment.
continue should be break — no point trying other services for a blacklisted stream.
After blacklisting at line 193, the inner for service in available_services loop still continues to the next service. Since the stream is already blacklisted (removed from item.streams and moved to blacklisted_streams), attempting it on remaining services is wasteful. Use break to move on to the next stream.
Also, the as e binding is unused (Ruff F841).
Proposed fix
- except InfringingTorrentException as e:
+ except InfringingTorrentException:
# 451 Infringing Torrent - immediately blacklist, do not retry
# This is a permanent failure from the debrid service
logger.warning(
f"Stream {stream.infohash} flagged as infringing by {service.key}, blacklisting immediately"
)
item.blacklist_stream(stream)
stream_failed_on_all_services = False # Already handled via blacklist
- continue
+ break📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| except InfringingTorrentException as e: | |
| # 451 Infringing Torrent - immediately blacklist, do not retry | |
| # This is a permanent failure from the debrid service | |
| logger.warning( | |
| f"Stream {stream.infohash} flagged as infringing by {service.key}, blacklisting immediately" | |
| ) | |
| item.blacklist_stream(stream) | |
| stream_failed_on_all_services = False # Already handled via blacklist | |
| continue | |
| except InfringingTorrentException: | |
| # 451 Infringing Torrent - immediately blacklist, do not retry | |
| # This is a permanent failure from the debrid service | |
| logger.warning( | |
| f"Stream {stream.infohash} flagged as infringing by {service.key}, blacklisting immediately" | |
| ) | |
| item.blacklist_stream(stream) | |
| stream_failed_on_all_services = False # Already handled via blacklist | |
| break |
🧰 Tools
🪛 Ruff (0.14.14)
[error] 187-187: Local variable e is assigned to but never used
Remove assignment to unused variable e
(F841)
🤖 Prompt for AI Agents
In `@src/program/services/downloaders/__init__.py` around lines 187 - 195, The
InfringingTorrentException handler in the inner loop should stop trying other
services for the same stream and remove the unused exception binding: replace
the unused "except InfringingTorrentException as e:" with "except
InfringingTorrentException:" and change the trailing "continue" after calling
item.blacklist_stream(stream) to "break" so the loop over available_services
exits for that blacklisted stream (affecting the InfringingTorrentException
handler that logs using stream.infohash and service.key and sets
stream_failed_on_all_services).
Summary
Changes
InfringingTorrentExceptionclass to represent 451 errors with the infohash[451]in error messages and raiseInfringingTorrentExceptionInfringingTorrentExceptionand immediately blacklist the streamTest plan
python -m py_compileon all modified filesSummary by CodeRabbit