auto trigger refresh after import

This commit is contained in:
simon 2023-04-07 09:28:16 +07:00
parent 656b36d291
commit b9cbd4ed3a
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -38,7 +38,9 @@ class Library:
show_handler.validate_episodes()
show_handler.delete_folders(folders)
self.set_collection_art()
collection_id: str = self._get_collection()
self.set_collection_art(collection_id)
self.refresh_collection(collection_id)
def _get_all_series(self) -> dict:
"""get all shows indexed in jf"""
@ -47,18 +49,28 @@ class Library:
return all_shows
def set_collection_art(self) -> None:
def _get_collection(self) -> str:
"""get youtube collection id"""
folders: dict = Jellyfin().get("Library/MediaFolders")
for folder in folders["Items"]:
if folder.get("Name").lower() == "youtube":
return folder["Id"]
raise ValueError("youtube collection folder not found")
def set_collection_art(self, collection_id: str) -> None:
"""set collection ta art"""
with open(self.COLLECTION_ART, "rb") as f:
asset: bytes = f.read()
folders: dict = Jellyfin().get("Library/MediaFolders")
for folder in folders["Items"]:
if folder.get("Name").lower() == "youtube":
jf_id: str = folder.get("Id")
path: str = f"Items/{jf_id}/Images/Primary"
path: str = f"Items/{collection_id}/Images/Primary"
Jellyfin().post_img(path, base64.b64encode(asset))
def refresh_collection(self, collection_id: str) -> None:
"""trigger collection refresh"""
path: str = f"Items/{collection_id}/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default" # noqa: E501
Jellyfin().post(path, False)
class Show:
"""interact with a single show"""