only index new videos to speed up scan

This commit is contained in:
simon 2023-04-07 12:08:52 +07:00
parent b9cbd4ed3a
commit 7df3ad3f08
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 27 additions and 7 deletions

View File

@ -40,6 +40,7 @@ class Episode:
"ParentIndexNumber": published_date.year, "ParentIndexNumber": published_date.year,
"PremiereDate": published_date.isoformat(), "PremiereDate": published_date.isoformat(),
"Overview": self._get_desc(ta_video), "Overview": self._get_desc(ta_video),
"Studios": [{"Name": "YouTube"}],
} }
path: str = f"Items/{self.jf_id}" path: str = f"Items/{self.jf_id}"
Jellyfin().post(path, data) Jellyfin().post(path, data)

View File

@ -78,13 +78,24 @@ class Show:
def __init__(self, show: JFShow): def __init__(self, show: JFShow):
self.show: JFShow = show 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""" """get all episodes of show"""
series_id: str = self.show["Id"] series_id: str = self.show["Id"]
path: str = f"Shows/{series_id}/Episodes?fields=Path" path: str = f"Shows/{series_id}/Episodes?fields=Path,Studios"
all_episodes = Jellyfin().get(path) 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]: def _get_expected_seasons(self) -> set[str]:
"""get all expected seasons""" """get all expected seasons"""
@ -149,7 +160,7 @@ class Show:
def _get_ta_channel(self) -> TAChannel: def _get_ta_channel(self) -> TAChannel:
"""get ta channel metadata""" """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] youtube_id: str = os.path.split(episode["Path"])[-1][9:20]
path = f"/video/{youtube_id}" path = f"/video/{youtube_id}"
@ -188,7 +199,13 @@ class Show:
def validate_episodes(self) -> None: def validate_episodes(self) -> None:
"""sync all episodes""" """sync all episodes"""
all_episodes: list[JFEpisode] = self._get_all_episodes() showname: str = self.show["Name"]
for video in all_episodes: 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] youtube_id: str = os.path.split(video["Path"])[-1][9:20]
Episode(youtube_id, video["Id"]).sync() Episode(youtube_id, video["Id"]).sync()

View File

@ -38,6 +38,7 @@ class JFShow(TypedDict):
Id: str Id: str
Path: str Path: str
Name: str
class JFEpisode(TypedDict): class JFEpisode(TypedDict):
@ -45,3 +46,4 @@ class JFEpisode(TypedDict):
Id: str Id: str
Path: str Path: str
Studios: list