[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. Add `trakt` ratings source for mass episode operations.
Added GitHub token validation during config validation. Added GitHub token validation during config validation.
add `plex` ratings source for mass operations. add `plex` ratings source for mass operations.
Orderly error and no caching on too-large image
# Docs # Docs
Added "getting started" page 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) self.reload(item, force=True)
if overlay and "Overlay" in [la.tag for la in self.item_labels(item)]: if overlay and "Overlay" in [la.tag for la in self.item_labels(item)]:
item.removeLabel("Overlay") item.removeLabel("Overlay")
self._upload_image(item, poster) poster_uploaded = self._upload_image(item, poster)
poster_uploaded = True
logger.info(f"Metadata: {poster.attribute} updated {poster.message}") logger.info(f"Metadata: {poster.attribute} updated {poster.message}")
elif self.show_asset_not_needed: elif self.show_asset_not_needed:
logger.info(f"Metadata: {poster.prefix}poster update not needed") logger.info(f"Metadata: {poster.prefix}poster update not needed")
@ -228,8 +227,7 @@ class Library(ABC):
if self.config.Cache: if self.config.Cache:
_, image_compare, _ = self.config.Cache.query_image_map(item.ratingKey, f"{self.image_table_name}_backgrounds") _, 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): if not image_compare or str(background.compare) != str(image_compare):
self._upload_image(item, background) background_uploaded = self._upload_image(item, background)
background_uploaded = True
logger.info(f"Metadata: {background.attribute} updated {background.message}") logger.info(f"Metadata: {background.attribute} updated {background.message}")
elif self.show_asset_not_needed: elif self.show_asset_not_needed:
logger.info(f"Metadata: {background.prefix}background update 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", "critic_rating.asc": "rating:asc", "critic_rating.desc": "rating:desc",
} }
MAX_IMAGE_SIZE = 10480000 # a little less than 10MB
class Plex(Library): class Plex(Library):
def __init__(self, config, params): def __init__(self, config, params):
super().__init__(config, params) super().__init__(config, params)
@ -766,6 +768,13 @@ class Plex(Library):
item_list.append(item) item_list.append(item)
return item_list 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))) @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): def reload(self, item, force=False):
is_full = 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))) @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): def _upload_image(self, item, image):
upload_success = True
try: try:
if image.is_url and "theposterdb.com" in image.location: if image.is_url and "theposterdb.com" in image.location:
now = datetime.now() now = datetime.now()
@ -800,12 +810,17 @@ class Plex(Library):
if image.is_poster and image.is_url: if image.is_poster and image.is_url:
item.uploadPoster(url=image.location) item.uploadPoster(url=image.location)
elif image.is_poster: 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: elif image.is_url:
item.uploadArt(url=image.location) item.uploadArt(url=image.location)
else: 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) self.reload(item, force=True)
return upload_success
except BadRequest as e: except BadRequest as e:
item.refresh() item.refresh()
raise Failed(e) raise Failed(e)

Loading…
Cancel
Save