From 1540bc4bf55653220af1692e713f5a0521ec8641 Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Fri, 23 Dec 2022 03:26:58 -0500 Subject: [PATCH] [3] Added webp Image Support --- CHANGELOG | 5 +++-- VERSION | 2 +- modules/builder.py | 4 ++-- modules/overlays.py | 11 ++++++++--- modules/plex.py | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7fa3ba5a..eb714bbd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,8 @@ # Requirements Update (requirements will need to be reinstalled) # New Features -Added new collection_order `custom.desc`. ([FR](https://features.metamanager.wiki/features/p/reverse-sort-collectionorder-custom)) +Added new collection_order `custom.desc` ([FR](https://features.metamanager.wiki/features/p/reverse-sort-collectionorder-custom)) +Added webp Image Support ([FR](https://features.metamanager.wiki/features/p/support-webp-image-extensions)) # Bug Fixes -Fixed Italian Translation \ No newline at end of file +Fixed Italian Translation \ No newline at end of file diff --git a/VERSION b/VERSION index cace1a5f..d96f975a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.18.1-develop2 +1.18.1-develop3 diff --git a/modules/builder.py b/modules/builder.py index d28f1f6c..29789175 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -898,7 +898,7 @@ class CollectionBuilder: if method_name == "url_poster": try: image_response = self.config.get(method_data, headers=util.header()) - if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in ["image/jpeg", "image/png"]: + if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in ["image/jpeg", "image/png", "image/webp"]: raise ConnectionError self.posters[method_name] = method_data except ConnectionError: @@ -925,7 +925,7 @@ class CollectionBuilder: if method_name == "url_background": try: image_response = self.config.get(method_data, headers=util.header()) - if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in ["image/jpeg", "image/png"]: + if image_response.status_code >= 400 or image_response.headers["Content-Type"] not in ["image/jpeg", "image/png", "image/webp"]: raise ConnectionError self.backgrounds[method_name] = method_data except ConnectionError: diff --git a/modules/overlays.py b/modules/overlays.py index 5d4dde06..a31c9230 100644 --- a/modules/overlays.py +++ b/modules/overlays.py @@ -179,9 +179,14 @@ class Overlays: image_response = self.config.get(new_backup) if image_response.status_code >= 400: raise Failed(f"{item_title[:60]:<60} | Overlay Error: Image Download Failed") - if image_response.headers["Content-Type"] not in ["image/png", "image/jpeg"]: - raise Failed(f"{item_title[:60]:<60} | Overlay Error: Image Not JPG or PNG") - i_ext = "jpg" if image_response.headers["Content-Type"] == "image/jpeg" else "png" + if image_response.headers["Content-Type"] not in ["image/png", "image/jpeg", "image/webp"]: + raise Failed(f"{item_title[:60]:<60} | Overlay Error: Image Not PNG, JPG, or WEBP") + if image_response.headers["Content-Type"] == "image/jpeg": + i_ext = "jpg" + elif image_response.headers["Content-Type"] == "image/webp": + i_ext = "webp" + else: + i_ext = "png" backup_image_path = os.path.join(self.library.overlay_backup, f"{item.ratingKey}.{i_ext}") with open(backup_image_path, "wb") as handler: handler.write(image_response.content) diff --git a/modules/plex.py b/modules/plex.py index 7f7aac4e..0b211e51 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -1239,7 +1239,7 @@ class Plex(Library): if is_top_level and self.asset_folders and self.dimensional_asset_rename and (not poster or not background): for file in util.glob_filter(os.path.join(item_asset_directory, "*.*")): - if file.lower().endswith((".jpg", ".png", ".jpeg")): + if file.lower().endswith((".png", ".jpg", ".jpeg", "webp")): try: image = Image.open(file) _w, _h = image.size