feat: spend RED/OPS Freeleech tokens on eligible downloads (v0.28.0) - #46
Merged
Merged
Conversation
Opt-in via RED_USE_FL_TOKEN / OPS_USE_FL_TOKEN env vars (or --red-use-token / --ops-use-token CLI flags), off by default. When enabled, appends usetoken=1 to the Gazelle download endpoint so eligible downloads don't count against ratio. - Driven by the tracker's per-torrent canUseToken flag, captured from the browse search response (previously discarded). True only when a spendable token exists for that torrent (<=5GB, not already free) -- so tokens are used automatically whenever available and stop once they run out. No RED API endpoint returns a raw token count; canUseToken is the authoritative signal. - Never charges a token on already-free torrents or cached .torrent files. - Graceful fallback: a failed token spend retries as a normal download. - Hardened .torrent fetch to validate bencoded content before caching, so a JSON error body is never cached as a bogus torrent. - 24 new tests; full suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Lets flacfetch spend Freeleech (FL) tokens on RED/OPS so eligible downloads don't count against ratio — using the same mechanism as the site's
[FL]button (ajax.php?action=download&id=<id>&usetoken=1, API-key auth).Motivated by 30 expiring gift tokens on RED. Enabling this on the live server means karaoke-gen downloads automatically burn tokens while any remain.
How it works
RED_USE_FL_TOKEN/OPS_USE_FL_TOKENenv vars, or--red-use-token/--ops-use-tokenCLI flags.canUseTokenflag captured from thebrowsesearch response (previously discarded). It'strueonly when the account currently holds a spendable token for that torrent (≤ 5 GB, not already free) — so tokens are used automatically whenever available and stop once they run out. There is no RED API endpoint that returns a raw token count;canUseTokenis the authoritative signal..torrent..torrentfetch to validate bencoded content before caching, so a JSON error body (e.g. "no tokens left") is never cached as a bogus torrent.Tests
canUseTokenpropagation).Files
gazelle.py(core),red.py/ops.py,models.py(is_freeleech+can_use_token),cli.py,download_manager.py,health.py, README + CHANGELOG.@coderabbitai ignore