Skip to content

Commit

Permalink
Add artProvider and thumbProvider to exporter fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyWong16 committed May 13, 2024
1 parent 5c115de commit ee0b4c0
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions plexpy/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def movie_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'audienceRating': None,
'audienceRatingImage': None,
'chapters': {
Expand Down Expand Up @@ -384,6 +385,7 @@ def movie_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand All @@ -406,6 +408,7 @@ def show_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'audienceRating': None,
'audienceRatingImage': None,
'audioLanguage': None,
Expand Down Expand Up @@ -472,6 +475,7 @@ def show_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand All @@ -491,6 +495,7 @@ def season_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'audioLanguage': None,
'collections': {
'id': None,
Expand Down Expand Up @@ -534,6 +539,7 @@ def season_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand All @@ -552,6 +558,7 @@ def episode_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'audienceRating': None,
'audienceRatingImage': None,
'chapters': {
Expand Down Expand Up @@ -792,6 +799,7 @@ def episode_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand All @@ -814,6 +822,7 @@ def artist_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'collections': {
'id': None,
'tag': None
Expand Down Expand Up @@ -866,6 +875,7 @@ def artist_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand All @@ -882,6 +892,7 @@ def album_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'collections': {
'id': None,
'tag': None
Expand Down Expand Up @@ -944,6 +955,7 @@ def album_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand Down Expand Up @@ -1223,6 +1235,7 @@ def collection_attrs():
'art': None,
'artBlurHash': None,
'artFile': lambda o: self.get_image(o, 'art'),
'artProvider': lambda o: self.get_image_attr(o, 'art', 'provider'),
'childCount': None,
'collectionFilterBasedOnUser': None,
'collectionMode': None,
Expand Down Expand Up @@ -1253,6 +1266,7 @@ def collection_attrs():
'thumb': None,
'thumbBlurHash': None,
'thumbFile': lambda o: self.get_image(o, 'thumb'),
'thumbProvider': lambda o: self.get_image_attr(o, 'thumb', 'provider'),
'title': None,
'titleSort': None,
'type': None,
Expand Down Expand Up @@ -2239,15 +2253,25 @@ def get_any_hdr(self, item, media_type):
media = helpers.get_attrs_to_dict(item, attrs)
return any(vs.get('hdr') for p in media.get('parts', []) for vs in p.get('videoStreams', []))

def _get_cached_images(self, item, image):
if image == 'art':
if not hasattr(item, '_arts'):
item._arts = item.arts()
return getattr(item, '_arts', [])
else:
if not hasattr(item, '_posters'):
item._posters = item.posters()
return getattr(item, '_posters', [])

def get_image(self, item, image):
media_type = item.type
rating_key = item.ratingKey

export_image = True
if self.thumb_level == 1 or self.art_level == 1:
posters = item.arts() if image == 'art' else item.posters()
export_image = any(poster.selected and poster.ratingKey.startswith('upload://')
for poster in posters)
images = self._get_cached_images(item, image)
export_image = any(im.selected and im.ratingKey.startswith('upload://')
for im in images)
elif self.thumb_level == 2 or self.art_level == 2:
export_image = any(field.locked and field.name == image
for field in item.fields)
Expand Down Expand Up @@ -2293,6 +2317,12 @@ def get_image(self, item, image):

return os.path.join(os.path.basename(dirpath), filename)

def get_image_attr(self, item, image, attr):
images = self._get_cached_images(item, image)
selected = next((im for im in images if im.selected), None)
if selected:
return getattr(selected, attr)


class ExportObject(Export):
def __init__(self, export, obj):
Expand Down

0 comments on commit ee0b4c0

Please sign in to comment.