From a141777b9055b014d534443e9ae78dd1e8bfadf0 Mon Sep 17 00:00:00 2001 From: Gaisberg Date: Thu, 28 Dec 2023 00:38:44 +0200 Subject: [PATCH] Workaround for quick shutdown, fixed ongoing season logic --- backend/program/media/item.py | 2 +- backend/program/media/state.py | 12 ++++++++++-- backend/program/realdebrid.py | 2 +- backend/utils/utils.py | 6 +++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/program/media/item.py b/backend/program/media/item.py index bed30674..41d970b8 100644 --- a/backend/program/media/item.py +++ b/backend/program/media/item.py @@ -201,7 +201,7 @@ def _determine_state(self): return Symlink() if all(episode.file and episode.folder for episode in self.episodes): return Download() - if self.is_scraped(): + if self.is_scraped() or any(episode.state == Scrape for episode in self.episodes): return Scrape() if any(episode.state == Content for episode in self.episodes): return Content() diff --git a/backend/program/media/state.py b/backend/program/media/state.py index 2f1da6a0..9ab6c9ee 100644 --- a/backend/program/media/state.py +++ b/backend/program/media/state.py @@ -34,7 +34,11 @@ def perform_action(self): scrape.run(self.context) if self.context.type == "show": for season in self.context.seasons: - season.state.perform_action() + if season.aired_at: + season.state.perform_action() + else: + for episode in season.episodes: + episode.state.perform_action() class Scrape(MediaItemState): @@ -46,7 +50,11 @@ def perform_action(self): debrid.run(self.context) if self.context.type == "show": for season in self.context.seasons: - season.state.perform_action() + if season.aired_at: + season.state.perform_action() + else: + for episode in season.episodes: + episode.state.perform_action() if self.context.type == "season": self.context.state.perform_action() diff --git a/backend/program/realdebrid.py b/backend/program/realdebrid.py index 59e31d25..f5ce96ce 100644 --- a/backend/program/realdebrid.py +++ b/backend/program/realdebrid.py @@ -83,7 +83,7 @@ def _is_downloaded(self, item): def _update_torrent_info(self, item): info = self.get_torrent_info(item.get("active_stream")["id"]) - item.active_stream["name"] = info.filename + item.active_stream["name"] = info.original_filename def _download_item(self, item): request_id = self.add_magnet(item) diff --git a/backend/utils/utils.py b/backend/utils/utils.py index ae5a6908..5f650289 100644 --- a/backend/utils/utils.py +++ b/backend/utils/utils.py @@ -33,7 +33,11 @@ def save(self) -> None: def run(self): while self.running: self.save() - time.sleep(10) + # workaround for quick shutdown, we should use threading.Event instead + for i in range(10): + if not self.running: + break + time.sleep(i) class Parser: