Skip to content

feat: spend RED/OPS Freeleech tokens on eligible downloads (v0.28.0) - #46

Merged
beveradb merged 1 commit into
mainfrom
feat/sess-20260829-2249-red-fl-tokens
Aug 30, 2026
Merged

feat: spend RED/OPS Freeleech tokens on eligible downloads (v0.28.0)#46
beveradb merged 1 commit into
mainfrom
feat/sess-20260829-2249-red-fl-tokens

Conversation

@beveradb

Copy link
Copy Markdown
Collaborator

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

  • Opt-in, off by default: RED_USE_FL_TOKEN / OPS_USE_FL_TOKEN env vars, or --red-use-token / --ops-use-token CLI flags.
  • Driven by the tracker's canUseToken flag captured from the browse search response (previously discarded). It's true only 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; canUseToken is the authoritative signal.
  • Never charges a token on already-free torrents, or when serving a cached .torrent.
  • Graceful fallback: a failed token spend transparently retries as a normal (ratio-counted) download — a token failure never blocks a download.
  • Hardened the .torrent fetch to validate bencoded content before caching, so a JSON error body (e.g. "no tokens left") is never cached as a bogus torrent.

Tests

  • 24 new tests (eligibility, token URL building, fallback, content validation, canUseToken propagation).
  • Full suite: 651 → 675 passing.

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

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

codecov Bot commented Aug 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
flacfetch/api/services/download_manager.py 0.00% 8 Missing ⚠️
flacfetch/interface/cli.py 0.00% 6 Missing ⚠️
flacfetch/providers/gazelle.py 92.30% 4 Missing ⚠️
Flag Coverage Δ
unittests 46.40% <75.00%> (-4.30%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
flacfetch/api/routes/health.py 56.06% <ø> (+0.67%) ⬆️
flacfetch/core/models.py 84.37% <100.00%> (-5.21%) ⬇️
flacfetch/providers/ops.py 100.00% <100.00%> (+40.97%) ⬆️
flacfetch/providers/red.py 100.00% <100.00%> (+40.62%) ⬆️
flacfetch/providers/gazelle.py 75.21% <92.30%> (ø)
flacfetch/interface/cli.py 14.95% <0.00%> (-6.97%) ⬇️
flacfetch/api/services/download_manager.py 48.25% <0.00%> (+4.75%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@beveradb
beveradb merged commit fa13459 into main Aug 30, 2026
6 checks passed
@beveradb
beveradb deleted the feat/sess-20260829-2249-red-fl-tokens branch August 30, 2026 03:57
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.

1 participant