From a27fcf334afb3e328bb494c84a54e5065fa727ad Mon Sep 17 00:00:00 2001 From: Brock H Caldwell Date: Thu, 24 Jul 2025 16:24:21 -0500 Subject: [PATCH] wip: download single episode --- assets/components/download-option-tr.js | 37 +++++++++++++++++++ assets/components/episode-container.js | 2 + assets/controllers/tv_results_controller.js | 4 -- .../Handler/GetTvShowOptionsHandler.php | 1 + .../Action/Result/GetTvShowOptionsResult.php | 1 + templates/components/TvEpisodeList.html.twig | 1 + .../torrentio/partial/option-table.html.twig | 19 ++++------ 7 files changed, 50 insertions(+), 15 deletions(-) diff --git a/assets/components/download-option-tr.js b/assets/components/download-option-tr.js index ab744d7..84265c0 100644 --- a/assets/components/download-option-tr.js +++ b/assets/components/download-option-tr.js @@ -2,6 +2,9 @@ export default class DownloadOptionTr extends HTMLTableRowElement { H264_CODECS = ['h264', 'h.264', 'x264'] H265_CODECS = ['h265', 'h.265', 'x265', 'hevc'] + #downloadBtnEl; + + url; size; quality; resolution; @@ -12,20 +15,31 @@ export default class DownloadOptionTr extends HTMLTableRowElement { mediaType; season; episode; + filename; + imdbId; + episodeId; + mediaTitle; constructor() { super(); + this.url = this.getAttribute('url'); this.size = this.getAttribute('size'); this.quality = this.getAttribute('quality'); this.resolution = this.getAttribute('resolution'); this.codec = this.getAttribute('codec'); this.seeders = this.getAttribute('seeders'); this.provider = this.getAttribute('provider'); + this.filename = this.getAttribute('filename'); + this.imdbId = this.getAttribute('imdb-id'); this.languages = JSON.parse(this.getAttribute('languages')); this.mediaType = this.getAttribute('media-type'); + this.mediaTitle = this.getAttribute('media-title'); this.season = this.getAttribute('season') ?? null; this.episode = this.getAttribute('episode') ?? null; + this.episodeId = this.getAttribute('episode-id') ?? null; + this.#downloadBtnEl = this.querySelector('.download-btn'); + this.#downloadBtnEl.addEventListener('click', () => this.download()); // document.addEventListener('filterDownloadOptions', this.filter.bind(this)); } connectedCallback() { @@ -90,4 +104,27 @@ export default class DownloadOptionTr extends HTMLTableRowElement { return include; } + + download() { + console.log('Downloading dis bihh') + fetch('/api/download', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + body: JSON.stringify({ + url: this.url, + title: this.mediaTitle, + filename: this.filename, + mediaType: this.mediaType, + imdbId: this.imdbId, + episodeId: this.episodeId + }) + }) + .then(res => res.json()) + .then(json => { + console.log(json) + }) + } } diff --git a/assets/components/episode-container.js b/assets/components/episode-container.js index 7c5fff2..5cc3422 100644 --- a/assets/components/episode-container.js +++ b/assets/components/episode-container.js @@ -3,6 +3,7 @@ export default class EpisodeContainer extends HTMLElement { H265_CODECS = ['h265', 'h.265', 'x265', 'hevc'] options = []; + showTitle; #episodeSelectorEl; #resultsToggleBtnEl; @@ -12,6 +13,7 @@ export default class EpisodeContainer extends HTMLElement { constructor() { super(); + this.showTitle = this.getAttribute('show-title'); this.#resultsTableEl = this.querySelector('.results-container'); this.#resultsToggleBtnEl = this.querySelector('.dropdown-button'); this.#resultsCountBadgeEl = this.querySelector('.results-count-badge'); diff --git a/assets/controllers/tv_results_controller.js b/assets/controllers/tv_results_controller.js index a8fe7cc..dd36c58 100644 --- a/assets/controllers/tv_results_controller.js +++ b/assets/controllers/tv_results_controller.js @@ -38,10 +38,6 @@ export default class extends Controller { } } - isSelected() { - return this.episodeSelectorTarget.checked; - } - download() { this.element.options.forEach(option => { const optionSelector = option.querySelector('input[type="checkbox"]'); diff --git a/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php b/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php index 0885c8c..c0117d9 100644 --- a/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php +++ b/src/Torrentio/Action/Handler/GetTvShowOptionsHandler.php @@ -28,6 +28,7 @@ class GetTvShowOptionsHandler implements HandlerInterface $file = $this->mediaFiles->episodeExists($parentShow->title, $command->season, $command->episode); return new GetTvShowOptionsResult( + parentShow: $parentShow, media: $media, file: MediaFileDto::fromSplFileInfo($file), season: $command->season, diff --git a/src/Torrentio/Action/Result/GetTvShowOptionsResult.php b/src/Torrentio/Action/Result/GetTvShowOptionsResult.php index a1b71e4..5a4cc1f 100644 --- a/src/Torrentio/Action/Result/GetTvShowOptionsResult.php +++ b/src/Torrentio/Action/Result/GetTvShowOptionsResult.php @@ -9,6 +9,7 @@ use OneToMany\RichBundle\Contract\ResultInterface; class GetTvShowOptionsResult implements ResultInterface { public function __construct( + public TmdbResult $parentShow, public TmdbResult $media, public MediaFileDto|false $file, public string $season, diff --git a/templates/components/TvEpisodeList.html.twig b/templates/components/TvEpisodeList.html.twig index 78d734c..2109e87 100644 --- a/templates/components/TvEpisodeList.html.twig +++ b/templates/components/TvEpisodeList.html.twig @@ -4,6 +4,7 @@
{% for episode in this.getEpisodes().items %} @@ -79,17 +86,7 @@ {{ result.languageFlags|raw }} -