Skip to content

Add AIOStreams, TorBox and dual-debrid stream diversity - #43

Merged
vitobotta merged 8 commits into
vitobotta:mainfrom
phantomic12:aio-streams-parity
Nov 15, 2026
Merged

vitobotta merged 8 commits into
vitobotta:mainfrom
phantomic12:aio-streams-parity

Conversation

@phantomic12

@phantomic12 phantomic12 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds AIOStreams and TorBox as first-class stream sources alongside Real-Debrid/Comet, and lets both debrid accounts be active at once so the resolver ranks every candidate in a single list instead of picking one provider up front.

  • AIOStreams (Streams::AioStreamsProvider, AIOSTREAMS_URL): reads a Stremio install link, normalises behaviorHints, resolution and size, and probes a proxied resolve URL with Range: bytes=0-1 before treating it as playable.
  • TorBox (TorBoxService, TORBOX_API_KEY): account info, torrent search, and per-user keys kept in encrypted credentials, with separate admin team key and user key handling.
  • Dual debrid: Real-Debrid and TorBox can both be configured. StreamProvider merges candidates from all configured providers, the resolver scores them together, and cached playback generations stay keyed per provider.
  • Quality: stream quality menu, automatic downshift after repeated stalls, and subtitle/HDR-aware transcode decisions that use scale2ref for bitmap subtitles when the deployed ffmpeg supports it.
  • Settings: masked key display, explicit per-key clear controls, and verify-before-save for admin team keys so a mistyped key cannot replace a working one.

Routing also had to become provider-aware: when COMET_URL and AIOSTREAMS_URL share an origin, the candidate's provider now decides which connection (and therefore which proxy) is used, rather than comparing origins alone.

Automated checks (at 156e6cc, Windows dev box)

  • Specs for the changed areas (streams_resolver_spec, tor_box_service_spec, admin_settings_spec, settings_spec, media_transcoder_spec, hls_session_manager_spec, hls_spec): 156 examples, 11 failures, and none of the failures is an assertion. Nine come from Process.spawn(..., pgroup: true) raising wrong exec option symbol: pgroup and two from Process.kill('SIGCONT', -pid) raising unsupported signal 'SIGCONT'; both are Windows gaps in the process-manager specs. Everything else passes, including provider routing, shared-origin routing, resolve-URL probing, TorBox account/search/error paths, key save/verify/clear leaving a working key intact when verification fails, scale2ref burn-in, HDR transfer-function detection, and the stall-driven HLS quality argument.
  • node --test spec/javascript/*_test.mjs: 580 tests, 580 pass, 0 fail. Includes the auto-downgrade ladder stepping direct playback onto the transcode path and the HLS stall hook.
  • bin/rubocop: 188 files inspected, no offenses.
  • Full suite: 596 examples, 12 failures — the same platform gaps (10 pgroup, 1 SIGCONT) plus spec/config/production_process_spec.rb:15, which spawns bin/docker-entrypoint and cannot execute on Windows.
  • Deployed on a LAN host: /up 200, scale2ref present on the bundled ffmpeg 7.1.5, single-row app_settings after migration.

Browser verification (head 156e6cc)

Deployed the branch with its own Dockerfile on a LAN host and drove it in Chromium, signed in as a real user. No AIOStreams install link or TorBox subscription was available, so playback was reached through a real playback descriptor issued by the app for a public MP4 (media.w3.org, allowlisted through STREAM_SOURCE_HOSTS). That exercises the genuine direct-play, transcode and HLS endpoints; only the provider/resolver layer is bypassed.

Quality menu

  • Playback began as direct play (/direct_stream, playing at 19.8s, readyState 4), menu at Auto.
  • Selecting 720p: controller moved to quality=720p / autoQuality=false, the select synced, the choice persisted to localStorage, and playback restarted through GET /transcode?...&start_seconds=30&quality=720p (200), continuing on the MSE blob: source with the resume position kept.

HLS downgrade

Chromium cannot enter the HLS path on its own (it requires isSafari()), so the watchdog entry point was driven on the live controller with the restart requests captured:

Stall Controller quality POST /hls/start body tail
1, still auto auto ...&start_seconds=5&audio_stream=1 (no quality)
2, ladder steps down 720p, select synced ...&start_seconds=5&quality=720p&audio_stream=1

So the stall path does step down, and the restarted session carries the new rung.

Not covered

  • End-to-end playback against a live AIOStreams install link and a subscribed TorBox account: no credentials, so provider parsing, resolve-URL probing and TorBox search are covered by specs and dry runs, not by a real resolve.
  • HLS playback itself: the sessions and playlists were created and served (200/206), but Chromium has no native HLS, so the restarted stream was not watched playing in Safari.

phantomic12 and others added 3 commits November 3, 2026 00:09
Stream selection now resolves through AIOStreams or the direct providers,
and users can keep RealDebrid and TorBox keys at once so both resolvers feed
the same list: providers are merged, deduplicated by info hash and file index,
and the preferred service's streams are ordered first. Playback also gains
selectable quality rungs with HDR tone mapping and hardware encoder
auto-detection, so slow links and HDR sources transcode predictably.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Make saved keys removable, verify administrator key replacements before they
replace a working key, constrain app_settings to a single row, and fix two
transcode filter defects: HDR detection now keys off the transfer function
only, and bitmap subtitles are scaled to the base before the overlay. The
resolver also probes with a Range request and routes provider proxy links by
origin, and stalls rejected during recovery no longer count toward a quality
downgrade.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
An automatic quality downgrade now leaves direct/remux playback so the next
reconnect actually carries the rung, and resolver connections are chosen by the
candidate's provider before URL origin so a shared Comet/AIOStreams origin keeps
the AIOStreams proxy in use.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
phantomic12 and others added 3 commits November 9, 2026 16:58
Keeps upstream's redesigned views and README, with the debrid section rebuilt
as a dual-service panel and TorBox/AIOStreams documented in the new
docs/CONFIGURATION.md. The home notice now covers TorBox and team keys.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
The settings controller only ran key verification on the update path
without a password, so a mistyped TorBox or RealDebrid key saved in the
same form as a password change replaced a working key while the flash
message reported only the password update.

Run the same verification on the password path and report a failure as
an alert that still confirms the password change.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
Upstream added a picture-in-picture button and notice to the player, which
collides with this branch's quality selector in the target list and the
control bar. Both features are additive, so the resolution keeps the quality
select and the PiP button side by side and registers both sets of targets.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@phantomic12

Copy link
Copy Markdown
Contributor Author

@vitobotta ready for a first review and mergeable against current main: AIOStreams, TorBox and dual-debrid stream diversity.

@vitobotta vitobotta left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not ready to merge. Two blocking items, one security fix and two behavior gaps; the rest is minor.

Blocking

  1. The committed suite is red. bundle exec rspec is 559 examples with 1 failure: spec/services/tor_box_service_spec.rb:31. to_timeout raises Faraday::ConnectionFailed on the locked Faraday 2.15.1, so the service returns "Could not connect to TorBox" and the include("timed out") expectation fails. The timeout branch is never exercised. Fix the stub or the rescue, and get the suite green.

  2. Nobody can become an admin. admin defaults to false and no seed, rake task, env var, UI or doc ever sets it to true. A fresh install therefore hides the Team link and /admin/settings only redirects, so the team-key feature this PR adds cannot be reached without a console update. Add a documented bootstrap (first-user promotion, FIRST_ADMIN_EMAIL, or a rake task) and a README step.

Security

  1. Comet writes the debrid key to the log. build_config base64-encodes the key into the request path, and the HTTP failure and timeout rescues log that path. Base64 is reversible, and the path now carries TorBox keys as well as RealDebrid ones. Redact the config segment before logging.

Behavior

  1. Auto-downgrade never runs on HLS. The new call sits in handleStreamStall. Safari and iOS stalls go through handleHlsStall, which restarts the session at the current quality, so auto mode never steps down on the platform where HLS is the default. Call the same check from the HLS path.

  2. Hardware encoders are now auto-selected on Linux. transcode_args tries nvenc, qsv and amf if FFMPEG_ENCODER is unset. Those arg lists set no bitrate, and auto quality adds no -maxrate, so a GPU host can encode 1080p at the encoder default instead of libx264 CRF 23. Make it opt-in or add rate control, and document it.

Minor

  • The Team entry uses sidebar-link, which is not defined anywhere. The other sidebar links use nav-link, so the new entry loses padding, hover and active styles.
  • content/show.html.erb:208 still tells a TorBox-only user to add a RealDebrid key. Use the debrid-configured helper there as the home page now does.
  • The README env table and docs/CONFIGURATION.md omit REALDEBRID_API_KEY, TORBOX_API_KEY, AIOSTREAMS_URL, AIOSTREAMS_PROXY, TORBOX_API_BASE_URL and STREAM_SOURCE_HOSTS.
  • db/schema.rb reorders the columns of every table. That is dump noise and will conflict with the other open PRs; regenerate on the project DB version or revert the reorder.

Verified

  • Focused specs (user, resolved source, stream provider, resolver, TorBox, AIOStreams, available streams, Comet, transcoder, settings, admin settings): 227 examples, 1 failure (the TorBox timeout).
  • Full RSpec: 559 examples, 1 failure.
  • JS: 530 pass, 0 fail.
  • RuboCop on 22 touched Ruby files: no offenses.
  • db:prepare, migrations and tailwindcss:build run.
  • Admin settings specs cover member rejection, masked keys, verify-before-save, clear and blank-keeps.
  • Scale filter with a real ffmpeg run: 1920x1080 becomes 1280x720, 1440x1080 becomes 960x720, 1080x1920 becomes 406x720.
  • Key scoping: the RealDebrid bearer is only added for RealDebrid hosts, TorBox and AIOStreams URLs get no debrid header, and an unlisted host is rejected.

Not verified

  • Live AIOStreams or TorBox playback; the PR says the same, and it needs a password-protected install link and an active TorBox account.
  • The quality menu in a real browser; the PR says it has not been driven.
  • The container ffmpeg build for zscale, tonemap and hardware encoders; I could not build the image here. There are also no CI checks attached to the head, so the gates above are local runs.

Comment thread spec/services/tor_box_service_spec.rb Resolved
Comment thread app/services/comet_service.rb Resolved
Comment thread app/services/media/transcoder.rb Resolved
Comment thread app/views/layouts/application.html.erb Resolved
WebMock's to_timeout surfaces as a connection failure on Faraday 2.15, so the timeout branch was never exercised; hardware encoders become opt-in because they carry no rate control; the Comet config segment is base64 of the debrid key and must not be logged. Also merges upstream/main, keeping the quality param inside its new buildMseStreamUrl and restoring the schema column order.
@phantomic12

Copy link
Copy Markdown
Contributor Author

All items are addressed at 156e6cc, which also merges current main (the dependabot bumps included).

Blocking

  1. Red suite / TorBox timeout: WebMock to_timeout surfaces as Faraday::ConnectionFailed on Faraday 2.15.1, so the example was exercising the connection branch and never the timeout branch. It now stubs to_raise(Faraday::TimeoutError) and the assertion covers the real timeout path; I added a separate example for Faraday::ConnectionFailed so both rescues are pinned.
  2. Admin bootstrap: new lib/tasks/admin.rake with admin:promote[email] (promotes the oldest account when no email is given) and admin:list, plus a README step right after "Create your first user" that shows docker compose exec web bin/rails "admin:promote[you@example.com]" and says only administrators reach /admin/settings. Verified from the console task: no accounts prints "No accounts yet", an unknown email prints "No account with ...", and admin:list prints the hint.

Security

  1. Comet config in logs: redacted_path replaces the base64 segment with [config] and is used by both the HTTP-failure and timeout rescues. New spec stubs a 500 and asserts the log contains /[config]/stream/ and never contains the encoded key.

Behaviour

  1. HLS auto-downgrade: handleHlsStall now calls maybeDowngradeAutoQuality before delegating, guarded like the MSE path by paused/seeking. The HLS client already sends quality when it creates or restarts a session, so the new rung applies to the restarted session.
  2. Hardware encoders: detection is opt-in. FFMPEG_ENCODER=auto runs the verified-encoder probe; an explicit FFMPEG_ENCODER still wins; unset keeps libx264 CRF 23. Documented in the README table and docs/CONFIGURATION.md, including why (no rate control in those arg lists). Two new spec examples: a detected encoder is ignored when the variable is unset, and used when it is auto.

Minor

  • Team link uses nav-link with active and aria-current, like its neighbours.
  • content/show.html.erb uses debrid_configured? and names both RealDebrid and TorBox.
  • README and docs/CONFIGURATION.md now list REALDEBRID_API_KEY, TORBOX_API_KEY, AIOSTREAMS_URL, AIOSTREAMS_PROXY, TORBOX_API_BASE_URL, STREAM_SOURCE_HOSTS and FFMPEG_ENCODER.
  • db/schema.rb is rebuilt on main column order: the diff against main is 13 lines (the app_settings table plus three users columns), with no table-wide reordering.

One merge note: main moved the MSE URL construction into buildMseStreamUrl, so the conflict resolution puts the quality parameter inside that helper rather than at each call site. Seeks, stall recovery and continuations therefore keep the selected rung, which is what the branch intended.

Gates on this head (Windows machine, so results differ from your Linux run): targeted services and request specs 115/0; JS 580/580; RuboCop clean on every touched Ruby file. Full suite is 596 examples with 12 failures, and all 12 are platform-only: ten Process.spawn ... pgroup: (unsupported option), one SIGCONT (unsupported signal), one Errno::ENOEXEC running bin/docker-entrypoint through Open3. None of them touch these changes. Live AIOStreams and TorBox playback is still unverified for the same reason as before (no install link or account), and the quality menu still has not been driven in a browser.

@phantomic12

Copy link
Copy Markdown
Contributor Author

Drove the player in a real browser on a deployed build of this branch to close the "quality menu not driven" gap. Environment: the branch built with its own Dockerfile, the app on a LAN address, Chromium, a real playback descriptor issued by the app for a public MP4 (media.w3.org, allowlisted through STREAM_SOURCE_HOSTS), so no TorBox or AIOStreams account was involved.

Quality menu

  • Playback started as direct play (/direct_stream, playing at 19.8s, readyState 4) with the menu at Auto.
  • Selecting 720p on the live page: the controller moved to quality=720p, autoQuality=false, the select synced, the choice persisted to localStorage, and playback restarted through GET /transcode?...&start_seconds=30&quality=720p (200) with the video continuing on the MSE blob: source. The resume position survived the switch.

HLS downgrade

Chromium cannot start the HLS path on its own (it needs isSafari()), so I drove the watchdog entry point on the live controller, with reportStall silenced so the torn-down SourceBuffer would not abort the probe, and captured the restart requests:

  • Stall 1 with quality=auto: POST /hls/start with no quality param.
  • Stall 2 (the ladder steps down after every second stall): controller quality became 720p, the select synced, and the restart request body now ended ...&quality=720p.

So the HLS stall path does step down and the restarted session carries the new rung. What I did not observe is HLS playback itself: the sessions and playlists were created and served, but Chromium has no native HLS, so I cannot claim the restarted stream played in Safari. The AIOStreams provider and TorBox resolver also remain unexercised for lack of credentials.

@phantomic12

Copy link
Copy Markdown
Contributor Author

@vitobotta the verification section of this PR description has been rewritten to match what was actually measured, and it no longer claims the quality menu is untested.

Since the last review:

  • The quality menu was driven in Chromium on a deployed build: selecting 720p restarts playback through /transcode with quality=720p and keeps the resume position. The stall-driven HLS downgrade was driven on the live controller, and the restart request carries the new rung (...&quality=720p).
  • The automated numbers were re-measured at 156e6cc and stated per command, including the fact that the 11 failures in the changed-area specs and 12 in the full suite are all Windows platform gaps (pgroup: unsupported, SIGCONT unsupported, bin/docker-entrypoint unexecutable), not assertion failures.
  • What remains unverified is stated: no live AIOStreams install link or TorBox subscription, and no HLS playback watched in Safari.

Could you take another look when you have a moment?

@vitobotta vitobotta left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All six findings from the previous review are addressed at 156e6cc:

  • The TorBox timeout example now raises Faraday::TimeoutError, so the actual timeout rescue runs.
  • The admin:promote task and the README bootstrap step make the Team page reachable on a fresh install.
  • Comet logs /[config]/stream/ instead of the base64 config segment.
  • Hardware encoders are opt-in through FFMPEG_ENCODER, with libx264 as the default.
  • HLS stalls now call maybeDowngradeAutoQuality before restarting the session.
  • The Team entry uses the existing nav-link class.

The branch still conflicts with current main in db/schema.rb. Main's schema version is 2026_10_30_130000 from the playlists migration, while this branch carries 2026_11_05_090000. Rebase onto main and keep 2026_11_05_090000, retaining the playlists tables that main adds.

Gates after a test merge with that resolution: 623 RSpec examples, 0 failures; 580 JavaScript tests, 0 failures; RuboCop inspected 165 files with no offenses; Brakeman clean. The focused changed-area specs are 231 examples, 0 failures.

No other findings.

Comment thread db/schema.rb Resolved
Resolve the schema dump against main's playlists migration: keep this
branch's 2026_11_05_090000 version with app_settings, and retain the
playlists tables main adds. The merged schema was verified by migrating a
throwaway database from scratch and comparing the dump, which matches byte
for byte. The README env table keeps both sides' rows.
@phantomic12

Copy link
Copy Markdown
Contributor Author

Merged today's main (d0f8cb9) into the branch at 7a3584a; the PR is now MERGEABLE/CLEAN with lint, scan_js and scan_ruby passing.

I merged rather than replaying the branch: it carries seven commits, two of which are earlier merges of main, so a rebase re-conflicts each one. The merged tree is the one your test merge describes — 623 RSpec examples, matching your count exactly.

Schema resolution — db/schema.rb takes this branch's version 2026_11_05_090000 with its app_settings table, and keeps main's playlists and playlist_items tables. I didn't hand-trust that resolution: I migrated an empty throwaway SQLite database from scratch through every migration and compared the dump against the merged file, and the two are identical (259 lines, same column order). users keeps both sides' columns, including debrid_service, realdebrid_api_key and torbox_api_key.

README — the env table keeps both sides' rows, so the RealDebrid/TorBox/AIOStreams/STREAM_SOURCE_HOSTS/FFMPEG_ENCODER rows sit alongside FORCE_SSL, ASSUME_SSL, SOLID_QUEUE_IN_PUMA, JOB_PROCESSES and HLS_CLEANUP_IN_WEB.

Gates at 7a3584a (Windows dev box): full RSpec 623 examples, 12 failures — the same platform-only set as before the merge (9 Process.spawn(..., pgroup: true), 2 SIGCONT, 1 bin/docker-entrypoint exec), no assertion failures. JS 580/580. RuboCop 198 files, no offenses. Coverage 88.3% line / 71.0% branch.

@vitobotta vitobotta left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge onto d0f8cb9 resolves the schema conflict. db/schema.rb uses version 2026_11_05_090000, keeps the app_settings table from this branch, and retains the playlists and playlist_items tables from main.

The six earlier findings remain fixed. CI now passes lint, scan_js and scan_ruby, and the PR is MERGEABLE and CLEAN.

Gates at 7a3584a: 623 RSpec examples, 0 failures; 580 JavaScript tests, 0 failures; RuboCop inspected 198 files with no offenses; Brakeman reports no warnings.

No other findings.

@vitobotta
vitobotta merged commit 155a41d into vitobotta:main Nov 15, 2026
3 checks passed
@vitobotta

Copy link
Copy Markdown
Owner

Merged. Thanks @phantomic12 for the AIOStreams, TorBox, dual-debrid and team-key work. A new release will be made soon.

@phantomic12
phantomic12 deleted the aio-streams-parity branch November 15, 2026 22:34
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