Skip to content

feat: add Zenith, fix BTN, add IPTorrents & TorrentLeech adapters - #175

Open
clawdbrunner wants to merge 10 commits into
jordanlambrecht:mainfrom
clawdbrunner:feat/add-zenith-btn-ipt-tl
Open

feat: add Zenith, fix BTN, add IPTorrents & TorrentLeech adapters#175
clawdbrunner wants to merge 10 commits into
jordanlambrecht:mainfrom
clawdbrunner:feat/add-zenith-btn-ipt-tl

Conversation

@clawdbrunner

@clawdbrunner clawdbrunner commented Jul 25, 2026

Copy link
Copy Markdown

Added Trackers

Zenith (znth.cx)

  • New registry entry (UNIT3D platform)
  • Uses existing Unit3dAdapter — no new adapter needed
  • Tested against live account ✅

BroadcasTheNet (BTN)

  • Fixed: was listed as Gazelle "Unvalidated" — never actually worked with the Gazelle adapter
  • New custom BTN JSON-RPC adapter (platform: btn)
  • POST JSON-RPC 2.0 to api.broadcasthe.net, method userInfo
  • Maps Lumens → seedbonus, computes ratio from raw bytes
  • Un-stucks the BTN entry — now fully functional ✅

IPTorrents (IPT)

  • New custom adapter (cookie + HTML scrape)
  • Platform: iptorrents
  • Parses .tTipWrap/.tTip header stats bar from any authenticated page
  • Credential format: {"cookies":"...","userAgent":"..."} JSON
  • Tested against live account ✅

TorrentLeech (TL)

  • New custom adapter (username/password login → HTML scrape)
  • Platform: torrentleech
  • POSTs credentials to /user/account/login/, captures tluid/tlpass cookies
  • Parses .profile-*-details spans from profile page
  • Credential format: {"username":"...","password":"..."} JSON
  • Tested against live account ✅

Changes

File Action Tracker
src/data/trackers/zenith.ts Create Zenith
src/data/trackers/broadcasthenet.ts Edit (gazelle → btn) BTN
src/data/trackers/iptorrents.ts Edit (custom → iptorrents) IPT
src/data/trackers/torrentleech.ts Edit (custom → torrentleech) TL
src/data/trackers/index.ts Edit (add zenith) All
src/lib/adapters/constants.ts Edit (3 new platform types + paths) BTN, IPT, TL
src/lib/adapters/btn.ts Create BTN
src/lib/adapters/iptorrents.ts Create IPT
src/lib/adapters/torrentleech.ts Create TL
src/lib/adapters/index.ts Edit (register 3 adapters) BTN, IPT, TL
src/lib/adapters/btn.test.ts Create BTN
src/lib/adapters/iptorrents.test.ts Create IPT
src/lib/adapters/torrentleech.test.ts Create TL

Total: 7 new files, 6 edited files
Tests: 2849 passing (78 new) at open; see update below
TypeScript: clean
Lint: clean

Integration testing complete — see update below.


Update 2 — Post-deployment fixes (2026-07-26)

After running this branch in production against live accounts, two edge cases surfaced and were fixed:

  • src/lib/parser.tsparseBytes() now handles infinity values (, Inf, -∞, -Inf, case-insensitive) → returns 0n. Zenith reports "buffer": "∞" for accounts with unlimited buffer, which previously threw Invalid byte format. (Touches shared parser — behavior for all other inputs unchanged, covered by 6 new tests.)
  • src/lib/adapters/iptorrents.tsfetchHtml() no longer treats every 302 as session expiry. IPTorrents 302s logged-in users from //t (normal behavior). Now inspects the Location header: only throws session-expired when it points at a login page; otherwise follows the redirect (bounded to 3 hops, relative Location values resolved via new URL(loc, base)).

Tests: 2858 passing | TypeScript: clean

Verified live against all four trackers on a production instance: Zenith ✅ BTN ✅ IPTorrents ✅ TorrentLeech ✅ — all polling real stats.

### Zenith (znth.cx)
- New registry entry (UNIT3D platform)
- Uses existing Unit3dAdapter

### BroadcasTheNet (BTN)
- Fixed: was listed as Gazelle 'Unvalidated' — never worked
- New custom BTN JSON-RPC adapter (platform: 'btn')
- POST JSON-RPC to api.broadcasthe.net, maps Lumens→seedbonus
- Un-stucks the BTN entry — now fully functional

### IPTorrents (IPT)
- New custom adapter (cookie + HTML scrape)
- Parses .tTipWrap/.tTip header stats and .up-stat cards
- Credential format: {cookies, userAgent} JSON

### TorrentLeech (TL)
- New custom adapter (username/password login + HTML scrape)
- POSTs to /user/account/login/, captures tluid/tlpass cookies
- Parses .profile-*-details spans from profile page
- Credential format: {username, password} JSON

### Files
- 7 new files, 6 edited files
- All 2848 tests pass (78 new)
- TypeScript and biome lint clean
H1: mark Class, Lumens, Bonus, HnR, JoinDate as optional in
BtnUserInfoResult. use nullish coalescing fallbacks in mapBtnResult
so adapter degrades gracefully if BTN changes API response shape.

H2: replace BigInt(parseInt()) with BigInt(string) to preserve
full precision for byte values exceeding Number.MAX_SAFE_INTEGER.

add test for missing optional fields scenario.

Fixes: QA H1+H2
@clawdbrunner
clawdbrunner marked this pull request as ready for review July 25, 2026 22:03
parseBytes: return 0n for ∞/Inf/-∞/-Inf values so UNIT3D
trackers (e.g. zenith) that return infinite buffer don't crash
the poll with 'Invalid byte format' error.

iptorrents: inspect Location header on 302 rather than throwing
session-expired on every redirect. iptorrents 302s logged-in
users from / to /t — only throw when redirected to a login page.
follow non-login redirects up to 3 hops.

add 6 new tests (4 parseBytes ∞ variants, 2 ipt redirect).
2855 total tests pass, tsc clean.

Fixes: 86bae41991a748
- H1: Handle infinity values case-insensitively (e.g. 'inf', 'INF').
- H2: Fix relative redirect resolution in IPTorrents fetchHtml.
- Added tests for case-insensitive infinity and path-relative redirects.

Fixes: 86bae41991a748
clawdbrunner and others added 6 commits August 2, 2026 18:52
Postgres freeleech_tokens/seedbonus columns are INTEGER; parseFloat on
BTN's Bonus/Lumens fields produced decimals once tokens accrued
fractional values, causing every snapshot INSERT to throw and BTN to
auto-pause after 4 consecutive failed polls (failing since 2026-07-26).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…x stale test

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
qBittorrent 5.2.3RC returns 204 with an empty body on successful
/api/v2/auth/login instead of the pre-5.2 200 "Ok." body, which was
incorrectly treated as a failed login and surfaced as a generic
"Connection failed" error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
qBittorrent 5.2+ names its session cookie QBT_SID_<port> (its own
WebUI listen port baked into the name) instead of the legacy plain
SID, so the /SID=([^;]+)/ regex in login() never matched and auth
kept failing even after the 204-status fix. Widen it to match any
cookie whose name contains SID as a token.

Verified live against a 5.2+ instance that the server accepts the
session value back under any cookie name (only the value is
validated, not the name), so qbtFetch's Cookie: SID=${sid} header
needs no change.
… SID

qBittorrent 5.2+ rejects the session value when sent back under the wrong
cookie name (verified live: same SID value, QBT_SID_8080=<value> -> 200,
SID=<value> -> 403). login() now returns {name, value} captured from the
Set-Cookie regex match instead of just the value, and that pair is plumbed
through sidCache/getSession/withSessionRetry/qbtFetch so the Cookie header
uses the actual assigned name.
The regex-over-comma-joined-header approach could pick the wrong cookie
(any name merely containing "SID", e.g. "SIDCC") and could bleed a cookie's
value across a comma boundary into the next Set-Cookie entry when the SID
cookie had no trailing attributes. getSetCookie() returns each Set-Cookie
header as its own array element, so each is parsed as a single cookie and
matched against an exact SID/QBT_SID_<port> name pattern.
@jordanlambrecht

Copy link
Copy Markdown
Owner

@clawdbrunner your btn credentials are exposed! Unless you are permanently okay with your login info being used in our vitests haha

src/lib/adapters/btn.test.ts, lines 19–21:

19:        UserID: "<redacted>",
20:        Username: "<redacted>",
21:        Email: "<redacted>",

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.

2 participants