[54] Orderly error and no cache on too-large image (#2449)

nightly
Chaz Larson 3 days ago committed by GitHub Action
parent 003fbf0406
commit 5b6601cbe8

@ -25,6 +25,7 @@ Add `trakt`, `omdb_metascore`, `omdb_tomatoes` ratings sources for mass operatio
Add `trakt` ratings source for mass episode operations.
Added GitHub token validation during config validation.
add `plex` ratings source for mass operations.
Orderly error and no caching on too-large image
# Docs
Added "getting started" page

@ -1 +1 @@
2.1.0-build53
2.1.0-build54

@ -212,8 +212,7 @@ class Library(ABC):
self.reload(item, force=True)
if overlay and "Overlay" in [la.tag for la in self.item_labels(item)]:
item.removeLabel("Overlay")
self._upload_image(item, poster)
poster_uploaded = True
poster_uploaded = self._upload_image(item, poster)
logger.info(f"Metadata: {poster.attribute} updated {poster.message}")
elif self.show_asset_not_needed:
logger.info(f"Metadata: {poster.prefix}poster update not needed")
@ -228,8 +227,7 @@ class Library(ABC):
if self.config.Cache:
_, image_compare, _ = self.config.Cache.query_image_map(item.ratingKey, f"{self.image_table_name}_backgrounds")
if not image_compare or str(background.compare) != str(image_compare):
self._upload_image(item, background)
background_uploaded = True
background_uploaded = self._upload_image(item, background)
logger.info(f"Metadata: {background.attribute} updated {background.message}")
elif self.show_asset_not_needed:
logger.info(f"Metadata: {background.prefix}background update not needed")

@ -442,6 +442,8 @@ watchlist_sorts = {
"critic_rating.asc": "rating:asc", "critic_rating.desc": "rating:desc",
}
MAX_IMAGE_SIZE = 10480000 # a little less than 10MB
class Plex(Library):
def __init__(self, config, params):
super().__init__(config, params)
@ -766,6 +768,13 @@ class Plex(Library):
item_list.append(item)
return item_list
def validate_image_size(self, image):
if image.compare < MAX_IMAGE_SIZE:
return True
else:
logger.error(f"Image too large: {image.location}, bytes {image.compare}, MAX {MAX_IMAGE_SIZE}")
return False
@retry(stop=stop_after_attempt(6), wait=wait_fixed(10), retry=retry_if_not_exception_type((BadRequest, NotFound, Unauthorized)))
def reload(self, item, force=False):
is_full = False
@ -789,6 +798,7 @@ class Plex(Library):
@retry(stop=stop_after_attempt(6), wait=wait_fixed(10), retry=retry_if_not_exception_type((BadRequest, NotFound, Unauthorized)))
def _upload_image(self, item, image):
upload_success = True
try:
if image.is_url and "theposterdb.com" in image.location:
now = datetime.now()
@ -800,12 +810,17 @@ class Plex(Library):
if image.is_poster and image.is_url:
item.uploadPoster(url=image.location)
elif image.is_poster:
item.uploadPoster(filepath=image.location)
upload_success = self.validate_image_size(image)
if upload_success:
item.uploadPoster(filepath=image.location)
elif image.is_url:
item.uploadArt(url=image.location)
else:
item.uploadArt(filepath=image.location)
upload_success = self.validate_image_size(image)
if upload_success:
item.uploadArt(filepath=image.location)
self.reload(item, force=True)
return upload_success
except BadRequest as e:
item.refresh()
raise Failed(e)

Loading…
Cancel
Save