mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 04:49:36 -07:00
Refactor export get_any_hdr and get_image
This commit is contained in:
parent
e9f37d578e
commit
693c0ba658
1 changed files with 55 additions and 51 deletions
|
@ -84,7 +84,7 @@ class Export(object):
|
||||||
_movie_attrs = {
|
_movie_attrs = {
|
||||||
'addedAt': helpers.datetime_to_iso,
|
'addedAt': helpers.datetime_to_iso,
|
||||||
'art': None,
|
'art': None,
|
||||||
'artFile': lambda o: get_image(o, 'art', self.filename),
|
'artFile': lambda o: self.get_image(o, 'art'),
|
||||||
'audienceRating': None,
|
'audienceRating': None,
|
||||||
'audienceRatingImage': None,
|
'audienceRatingImage': None,
|
||||||
'chapters': {
|
'chapters': {
|
||||||
|
@ -150,7 +150,7 @@ class Export(object):
|
||||||
'videoProfile': None,
|
'videoProfile': None,
|
||||||
'videoResolution': None,
|
'videoResolution': None,
|
||||||
'width': None,
|
'width': None,
|
||||||
'hdr': lambda o: get_any_hdr(o, self.return_attrs('movie')['media']),
|
'hdr': lambda o: self.get_any_hdr(o),
|
||||||
'parts': {
|
'parts': {
|
||||||
'accessible': None,
|
'accessible': None,
|
||||||
'audioProfile': None,
|
'audioProfile': None,
|
||||||
|
@ -275,7 +275,7 @@ class Export(object):
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'tagline': None,
|
'tagline': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -294,7 +294,7 @@ class Export(object):
|
||||||
_show_attrs = {
|
_show_attrs = {
|
||||||
'addedAt': helpers.datetime_to_iso,
|
'addedAt': helpers.datetime_to_iso,
|
||||||
'art': None,
|
'art': None,
|
||||||
'artFile': lambda o: get_image(o, 'art', self.filename),
|
'artFile': lambda o: self.get_image(o, 'art'),
|
||||||
'banner': None,
|
'banner': None,
|
||||||
'childCount': None,
|
'childCount': None,
|
||||||
'collections': {
|
'collections': {
|
||||||
|
@ -338,7 +338,7 @@ class Export(object):
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'theme': None,
|
'theme': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -377,7 +377,7 @@ class Export(object):
|
||||||
'ratingKey': None,
|
'ratingKey': None,
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -440,7 +440,7 @@ class Export(object):
|
||||||
'videoProfile': None,
|
'videoProfile': None,
|
||||||
'videoResolution': None,
|
'videoResolution': None,
|
||||||
'width': None,
|
'width': None,
|
||||||
'hdr': lambda o: get_any_hdr(o, self.return_attrs('episode')['media']),
|
'hdr': lambda o: self.get_any_hdr(o),
|
||||||
'parts': {
|
'parts': {
|
||||||
'accessible': None,
|
'accessible': None,
|
||||||
'audioProfile': None,
|
'audioProfile': None,
|
||||||
|
@ -575,7 +575,7 @@ class Export(object):
|
||||||
_artist_attrs = {
|
_artist_attrs = {
|
||||||
'addedAt': helpers.datetime_to_iso,
|
'addedAt': helpers.datetime_to_iso,
|
||||||
'art': None,
|
'art': None,
|
||||||
'artFile': lambda o: get_image(o, 'art', self.filename),
|
'artFile': lambda o: self.get_image(o, 'art'),
|
||||||
'collections': {
|
'collections': {
|
||||||
'id': None,
|
'id': None,
|
||||||
'tag': None
|
'tag': None
|
||||||
|
@ -612,7 +612,7 @@ class Export(object):
|
||||||
},
|
},
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -627,7 +627,7 @@ class Export(object):
|
||||||
_album_attrs = {
|
_album_attrs = {
|
||||||
'addedAt': helpers.datetime_to_iso,
|
'addedAt': helpers.datetime_to_iso,
|
||||||
'art': None,
|
'art': None,
|
||||||
'artFile': lambda o: get_image(o, 'art', self.filename),
|
'artFile': lambda o: self.get_image(o, 'art'),
|
||||||
'collections': {
|
'collections': {
|
||||||
'id': None,
|
'id': None,
|
||||||
'tag': None
|
'tag': None
|
||||||
|
@ -671,7 +671,7 @@ class Export(object):
|
||||||
},
|
},
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -897,7 +897,7 @@ class Export(object):
|
||||||
_collection_attrs = {
|
_collection_attrs = {
|
||||||
'addedAt': helpers.datetime_to_iso,
|
'addedAt': helpers.datetime_to_iso,
|
||||||
'art': None,
|
'art': None,
|
||||||
'artFile': lambda o: get_image(o, 'art', self.filename),
|
'artFile': lambda o: self.get_image(o, 'art'),
|
||||||
'childCount': None,
|
'childCount': None,
|
||||||
'collectionMode': None,
|
'collectionMode': None,
|
||||||
'collectionSort': None,
|
'collectionSort': None,
|
||||||
|
@ -918,7 +918,7 @@ class Export(object):
|
||||||
'subtype': None,
|
'subtype': None,
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'thumb': None,
|
'thumb': None,
|
||||||
'thumbFile': lambda o: get_image(o, 'thumb', self.filename),
|
'thumbFile': lambda o: self.get_image(o, 'thumb'),
|
||||||
'title': None,
|
'title': None,
|
||||||
'titleSort': None,
|
'titleSort': None,
|
||||||
'type': None,
|
'type': None,
|
||||||
|
@ -1568,45 +1568,49 @@ class Export(object):
|
||||||
|
|
||||||
return reduce(helpers.dict_merge, export_attrs_list)
|
return reduce(helpers.dict_merge, export_attrs_list)
|
||||||
|
|
||||||
|
def get_any_hdr(self, item):
|
||||||
|
if self.media_type in ('show', 'season'):
|
||||||
|
_media_type = 'episode'
|
||||||
|
else:
|
||||||
|
_media_type = self.media_type
|
||||||
|
|
||||||
def get_any_hdr(obj, root):
|
root = self.return_attrs(_media_type)['media']
|
||||||
attrs = helpers.get_dict_value_by_path(root, 'parts.videoStreams.hdr')
|
attrs = helpers.get_dict_value_by_path(root, 'parts.videoStreams.hdr')
|
||||||
media = helpers.get_attrs_to_dict(obj, attrs)
|
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', []))
|
return any(vs.get('hdr') for p in media.get('parts', []) for vs in p.get('videoStreams', []))
|
||||||
|
|
||||||
|
def get_image(self, item, image):
|
||||||
def get_image(item, image, export_filename):
|
media_type = item.type
|
||||||
media_type = item.type
|
rating_key = item.ratingKey
|
||||||
rating_key = item.ratingKey
|
|
||||||
|
if media_type in ('season', 'episode', 'album', 'track'):
|
||||||
if media_type in ('season', 'episode', 'album', 'track'):
|
item_title = item._defaultSyncTitle()
|
||||||
item_title = item._defaultSyncTitle()
|
else:
|
||||||
else:
|
item_title = item.title
|
||||||
item_title = item.title
|
|
||||||
|
folder = get_export_filepath(self.filename, images=True)
|
||||||
folder = get_export_filepath(export_filename, images=True)
|
filename = helpers.clean_filename('{} [{}].{}.jpg'.format(item_title, rating_key, image))
|
||||||
filename = helpers.clean_filename('{} [{}].{}.jpg'.format(item_title, rating_key, image))
|
filepath = os.path.join(folder, filename)
|
||||||
filepath = os.path.join(folder, filename)
|
|
||||||
|
if not os.path.exists(folder):
|
||||||
if not os.path.exists(folder):
|
os.makedirs(folder)
|
||||||
os.makedirs(folder)
|
|
||||||
|
image_url = None
|
||||||
image_url = None
|
if image == 'art':
|
||||||
if image == 'art':
|
image_url = item.artUrl
|
||||||
image_url = item.artUrl
|
elif image == 'thumb':
|
||||||
elif image == 'thumb':
|
image_url = item.thumbUrl
|
||||||
image_url = item.thumbUrl
|
|
||||||
|
if not image_url:
|
||||||
if not image_url:
|
return
|
||||||
return
|
|
||||||
|
r = requests.get(image_url, stream=True)
|
||||||
r = requests.get(image_url, stream=True)
|
if r.status_code == 200:
|
||||||
if r.status_code == 200:
|
with open(filepath, 'wb') as outfile:
|
||||||
with open(filepath, 'wb') as outfile:
|
for chunk in r:
|
||||||
for chunk in r:
|
outfile.write(chunk)
|
||||||
outfile.write(chunk)
|
|
||||||
|
return filepath
|
||||||
return filepath
|
|
||||||
|
|
||||||
|
|
||||||
def get_export(export_id):
|
def get_export(export_id):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue