From 7df3ad3f08d5686162035c78ccbc0d73d1e7d735 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 7 Apr 2023 12:08:52 +0700 Subject: [PATCH] only index new videos to speed up scan --- src/episode.py | 1 + src/series.py | 31 ++++++++++++++++++++++++------- src/static_types.py | 2 ++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/episode.py b/src/episode.py index 3045d87..0ef6997 100644 --- a/src/episode.py +++ b/src/episode.py @@ -40,6 +40,7 @@ class Episode: "ParentIndexNumber": published_date.year, "PremiereDate": published_date.isoformat(), "Overview": self._get_desc(ta_video), + "Studios": [{"Name": "YouTube"}], } path: str = f"Items/{self.jf_id}" Jellyfin().post(path, data) diff --git a/src/series.py b/src/series.py index 94dc335..55dfe42 100644 --- a/src/series.py +++ b/src/series.py @@ -78,13 +78,24 @@ class Show: def __init__(self, show: JFShow): self.show: JFShow = show - def _get_all_episodes(self) -> list[JFEpisode]: + def _get_all_episodes( + self, + filter_new: bool = False, + limit: int | bool = False, + ) -> list[JFEpisode]: """get all episodes of show""" series_id: str = self.show["Id"] - path: str = f"Shows/{series_id}/Episodes?fields=Path" - all_episodes = Jellyfin().get(path) + path: str = f"Shows/{series_id}/Episodes?fields=Path,Studios" + if limit: + path = f"{path}&limit={limit}" - return all_episodes["Items"] + all_episodes = Jellyfin().get(path) + all_items: list[JFEpisode] = all_episodes["Items"] + + if filter_new: + all_items = [i for i in all_items if not i["Studios"]] + + return all_items def _get_expected_seasons(self) -> set[str]: """get all expected seasons""" @@ -149,7 +160,7 @@ class Show: def _get_ta_channel(self) -> TAChannel: """get ta channel metadata""" - episode: JFEpisode = self._get_all_episodes()[0] + episode: JFEpisode = self._get_all_episodes(limit=1)[0] youtube_id: str = os.path.split(episode["Path"])[-1][9:20] path = f"/video/{youtube_id}" @@ -188,7 +199,13 @@ class Show: def validate_episodes(self) -> None: """sync all episodes""" - all_episodes: list[JFEpisode] = self._get_all_episodes() - for video in all_episodes: + showname: str = self.show["Name"] + new_episodes: list[JFEpisode] = self._get_all_episodes(filter_new=True) + if not new_episodes: + print(f"[show][{showname}] no new videos found") + return + + print(f"[show][{showname}] found {len(new_episodes)} new videos") + for video in new_episodes: youtube_id: str = os.path.split(video["Path"])[-1][9:20] Episode(youtube_id, video["Id"]).sync() diff --git a/src/static_types.py b/src/static_types.py index 1b011dd..bf011b1 100644 --- a/src/static_types.py +++ b/src/static_types.py @@ -38,6 +38,7 @@ class JFShow(TypedDict): Id: str Path: str + Name: str class JFEpisode(TypedDict): @@ -45,3 +46,4 @@ class JFEpisode(TypedDict): Id: str Path: str + Studios: list