From 37e13347b20955774ba741af03c1150b4b4890b3 Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Sat, 8 Nov 2025 16:26:38 -0600 Subject: [PATCH] feat(Download): adds streaming and local download options --- assets/icons/bi/camera-video.svg | 1 + assets/icons/bi/cloud-download.svg | 1 + assets/icons/bi/download.svg | 1 + config/packages/sentry.yaml | 1 + src/Torrentio/Client/Torrentio.php | 6 ++++++ .../Framework/Controller/WebController.php | 13 +++++++++++++ src/Twig/Extensions/UtilExtension.php | 6 ++++++ .../torrentio/partial/option-table.html.twig | 15 ++++++++++++--- templates/torrentio/stream.html.twig | 7 +++++++ 9 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 assets/icons/bi/camera-video.svg create mode 100644 assets/icons/bi/cloud-download.svg create mode 100644 assets/icons/bi/download.svg create mode 100644 templates/torrentio/stream.html.twig diff --git a/assets/icons/bi/camera-video.svg b/assets/icons/bi/camera-video.svg new file mode 100644 index 0000000..30b3355 --- /dev/null +++ b/assets/icons/bi/camera-video.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/bi/cloud-download.svg b/assets/icons/bi/cloud-download.svg new file mode 100644 index 0000000..13b5b65 --- /dev/null +++ b/assets/icons/bi/cloud-download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/icons/bi/download.svg b/assets/icons/bi/download.svg new file mode 100644 index 0000000..1303def --- /dev/null +++ b/assets/icons/bi/download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/config/packages/sentry.yaml b/config/packages/sentry.yaml index e8b0366..ec8a80a 100644 --- a/config/packages/sentry.yaml +++ b/config/packages/sentry.yaml @@ -5,6 +5,7 @@ when@prod: options: release: '%app.version%' + environment: '%env(APP_ENV)%' traces_sample_rate: 1 profiles_sample_rate: 1 attach_stacktrace: true diff --git a/src/Torrentio/Client/Torrentio.php b/src/Torrentio/Client/Torrentio.php index 6489127..02a71b3 100644 --- a/src/Torrentio/Client/Torrentio.php +++ b/src/Torrentio/Client/Torrentio.php @@ -68,4 +68,10 @@ class Torrentio return $results; } + + public function getDestinationUrl(string $url) + { + $request = get_headers($url)[8]; + return explode(' ', $request)[1]; + } } diff --git a/src/Torrentio/Framework/Controller/WebController.php b/src/Torrentio/Framework/Controller/WebController.php index 1ecce02..cf5e6ee 100644 --- a/src/Torrentio/Framework/Controller/WebController.php +++ b/src/Torrentio/Framework/Controller/WebController.php @@ -7,6 +7,7 @@ use App\Torrentio\Action\Handler\GetMovieOptionsHandler; use App\Torrentio\Action\Handler\GetTvShowOptionsHandler; use App\Torrentio\Action\Input\GetMovieOptionsInput; use App\Torrentio\Action\Input\GetTvShowOptionsInput; +use App\Torrentio\Client\Torrentio; use App\Torrentio\Exception\TorrentioRateLimitException; use Carbon\Carbon; use OneToMany\RichBundle\Contract\ResultInterface; @@ -21,6 +22,8 @@ use Symfony\UX\Turbo\TurboBundle; final class WebController extends AbstractController { + const REAL_DEBRID_STREAM_URL = 'https://real-debrid.com/streaming-%s'; + public function __construct( private readonly GetMovieOptionsHandler $getMovieOptionsHandler, private readonly GetTvShowOptionsHandler $getTvShowOptionsHandler, @@ -99,4 +102,14 @@ final class WebController extends AbstractController ] ); } + + #[Route('/torrentio/stream/{url}', name: 'app.torrentio.stream')] + public function streamVideo(string $url, Torrentio $torrentio): Response + { + $destinationUrl = $torrentio->getDestinationUrl(\base64_decode($url)); + $urlPathParts = explode('/', parse_url($destinationUrl)['path']); + $videoId = $urlPathParts[2]; + $url = sprintf(self::REAL_DEBRID_STREAM_URL, $videoId); + return $this->redirect($url); + } } diff --git a/src/Twig/Extensions/UtilExtension.php b/src/Twig/Extensions/UtilExtension.php index cf04255..4ce5880 100644 --- a/src/Twig/Extensions/UtilExtension.php +++ b/src/Twig/Extensions/UtilExtension.php @@ -120,4 +120,10 @@ class UtilExtension return $sentryConfig['javascript_url'] !== null && $sentryConfig['javascript_url'] !== ''; } + + #[AsTwigFilter('base64_encode')] + public function base64_encode(string $data): string + { + return \base64_encode($data); + } } diff --git a/templates/torrentio/partial/option-table.html.twig b/templates/torrentio/partial/option-table.html.twig index 7594ab3..351d0b1 100644 --- a/templates/torrentio/partial/option-table.html.twig +++ b/templates/torrentio/partial/option-table.html.twig @@ -86,9 +86,18 @@ {{ result.languageFlags|raw }} - + + + + + + + + + + diff --git a/templates/torrentio/stream.html.twig b/templates/torrentio/stream.html.twig new file mode 100644 index 0000000..ada46c5 --- /dev/null +++ b/templates/torrentio/stream.html.twig @@ -0,0 +1,7 @@ +{% extends 'base.html.twig' %} + +{% block title %}Streaming — Torrentio{% endblock %} + +{% block body %} + +{% endblock %} \ No newline at end of file