mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-16 02:02:58 -07:00
Implement X-Plex-Container-Size for retrieving library items
PMS 1.28 log warning ``` Missing X-Plex-Container-Size header. This will fail with status code 400 in the future. ```
This commit is contained in:
parent
85eaed57e0
commit
c45ded5a98
1 changed files with 93 additions and 35 deletions
|
@ -147,7 +147,7 @@ class PmsConnect(object):
|
||||||
|
|
||||||
return request
|
return request
|
||||||
|
|
||||||
def get_metadata_children(self, rating_key='', section_id='', artist=False, collection=False, output_format=''):
|
def get_metadata_children(self, rating_key='', collection=False, output_format=''):
|
||||||
"""
|
"""
|
||||||
Return metadata for children of the request item.
|
Return metadata for children of the request item.
|
||||||
|
|
||||||
|
@ -156,14 +156,9 @@ class PmsConnect(object):
|
||||||
|
|
||||||
Output: array
|
Output: array
|
||||||
"""
|
"""
|
||||||
if artist:
|
uri = '/library/{}/{}/children'.format(
|
||||||
uri = '/library/sections/{}/all?artist.id={}&type=9'.format(
|
'collections' if collection else 'metadata', rating_key
|
||||||
section_id, rating_key
|
)
|
||||||
)
|
|
||||||
else:
|
|
||||||
uri = '/library/{}/{}/children'.format(
|
|
||||||
'collections' if collection else 'metadata', rating_key
|
|
||||||
)
|
|
||||||
request = self.request_handler.make_request(uri=uri,
|
request = self.request_handler.make_request(uri=uri,
|
||||||
request_type='GET',
|
request_type='GET',
|
||||||
output_format=output_format)
|
output_format=output_format)
|
||||||
|
@ -326,7 +321,8 @@ class PmsConnect(object):
|
||||||
|
|
||||||
return request
|
return request
|
||||||
|
|
||||||
def get_library_list(self, section_id='', list_type='all', count='0', sort_type='', label_key='', output_format=''):
|
def get_library_list(self, section_id='', list_type='all', start=0, count=0, sort_type='',
|
||||||
|
label_key='', output_format=''):
|
||||||
"""
|
"""
|
||||||
Return list of items in library on server.
|
Return list of items in library on server.
|
||||||
|
|
||||||
|
@ -334,16 +330,51 @@ class PmsConnect(object):
|
||||||
|
|
||||||
Output: array
|
Output: array
|
||||||
"""
|
"""
|
||||||
count = '&X-Plex-Container-Size=' + count if count else ''
|
start = 'X-Plex-Container-Start=' + str(start)
|
||||||
|
count = 'X-Plex-Container-Size=' + str(count)
|
||||||
label_key = '&label=' + label_key if label_key else ''
|
label_key = '&label=' + label_key if label_key else ''
|
||||||
|
|
||||||
uri = '/library/sections/' + section_id + '/' + list_type + '?X-Plex-Container-Start=0' + count + sort_type + label_key
|
uri = ('/library/sections/' + section_id + '/' + list_type + '?'
|
||||||
|
+ start + '&' + count + sort_type + label_key)
|
||||||
request = self.request_handler.make_request(uri=uri,
|
request = self.request_handler.make_request(uri=uri,
|
||||||
request_type='GET',
|
request_type='GET',
|
||||||
output_format=output_format)
|
output_format=output_format)
|
||||||
|
|
||||||
return request
|
return request
|
||||||
|
|
||||||
|
def fetch_library_list(self, section_id='', list_type='all', count='', sort_type='',
|
||||||
|
label_key='', output_format=''):
|
||||||
|
xml_head = []
|
||||||
|
|
||||||
|
start = 0
|
||||||
|
_count = int(count) if count else 100
|
||||||
|
|
||||||
|
while True:
|
||||||
|
library_data = self.get_library_list(
|
||||||
|
section_id=str(section_id),
|
||||||
|
list_type=list_type,
|
||||||
|
start=start,
|
||||||
|
count=_count,
|
||||||
|
sort_type=sort_type,
|
||||||
|
label_key=label_key,
|
||||||
|
output_format=output_format
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
_xml_head = library_data.getElementsByTagName('MediaContainer')
|
||||||
|
library_count = int(helpers.get_xml_attr(_xml_head[0], 'totalSize'))
|
||||||
|
xml_head.extend(_xml_head)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for fetch_library_list: %s." % e)
|
||||||
|
return xml_head
|
||||||
|
|
||||||
|
start += _count
|
||||||
|
|
||||||
|
if count or start >= library_count:
|
||||||
|
break
|
||||||
|
|
||||||
|
return xml_head
|
||||||
|
|
||||||
def get_library_labels(self, section_id='', output_format=''):
|
def get_library_labels(self, section_id='', output_format=''):
|
||||||
"""
|
"""
|
||||||
Return list of labels for a library on server.
|
Return list of labels for a library on server.
|
||||||
|
@ -2352,6 +2383,8 @@ class PmsConnect(object):
|
||||||
'children_list': []
|
'children_list': []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xml_head = []
|
||||||
|
|
||||||
if media_type == 'playlist':
|
if media_type == 'playlist':
|
||||||
children_data = self.get_playlist_items(rating_key, output_format='xml')
|
children_data = self.get_playlist_items(rating_key, output_format='xml')
|
||||||
elif media_type == 'collection':
|
elif media_type == 'collection':
|
||||||
|
@ -2361,15 +2394,21 @@ class PmsConnect(object):
|
||||||
elif media_type == 'artist':
|
elif media_type == 'artist':
|
||||||
artist_metadata = self.get_metadata_details(rating_key)
|
artist_metadata = self.get_metadata_details(rating_key)
|
||||||
section_id = artist_metadata['section_id']
|
section_id = artist_metadata['section_id']
|
||||||
children_data = self.get_metadata_children(rating_key, section_id, artist=True, output_format='xml')
|
sort_type = '&artist.id={}&type=9'.format(rating_key)
|
||||||
|
xml_head = self.fetch_library_list(
|
||||||
|
section_id=str(section_id),
|
||||||
|
sort_type=sort_type,
|
||||||
|
output_format='xml'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
children_data = self.get_metadata_children(rating_key, output_format='xml')
|
children_data = self.get_metadata_children(rating_key, output_format='xml')
|
||||||
|
|
||||||
try:
|
if not xml_head:
|
||||||
xml_head = children_data.getElementsByTagName('MediaContainer')
|
try:
|
||||||
except Exception as e:
|
xml_head = children_data.getElementsByTagName('MediaContainer')
|
||||||
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_item_children: %s." % e)
|
except Exception as e:
|
||||||
return default_return
|
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_item_children: %s." % e)
|
||||||
|
return default_return
|
||||||
|
|
||||||
children_list = []
|
children_list = []
|
||||||
|
|
||||||
|
@ -2691,20 +2730,32 @@ class PmsConnect(object):
|
||||||
else:
|
else:
|
||||||
sort_type = ''
|
sort_type = ''
|
||||||
|
|
||||||
if str(rating_key).isdigit():
|
if str(rating_key).isdigit() and section_type != 'album':
|
||||||
_artist = section_type == 'album'
|
library_data = self.get_metadata_children(str(rating_key), output_format='xml')
|
||||||
library_data = self.get_metadata_children(str(rating_key), str(section_id), artist=_artist, output_format='xml')
|
|
||||||
elif str(section_id).isdigit():
|
try:
|
||||||
library_data = self.get_library_list(str(section_id), list_type, count, sort_type, label_key, output_format='xml')
|
xml_head = library_data.getElementsByTagName('MediaContainer')
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_library_children_details: %s." % e)
|
||||||
|
return []
|
||||||
|
|
||||||
|
elif str(section_id).isdigit() or section_type == 'album':
|
||||||
|
if section_type == 'album':
|
||||||
|
sort_type += '&artist.id=' + str(rating_key)
|
||||||
|
|
||||||
|
xml_head = self.fetch_library_list(
|
||||||
|
section_id=str(section_id),
|
||||||
|
list_type=list_type,
|
||||||
|
count=count,
|
||||||
|
sort_type=sort_type,
|
||||||
|
label_key=label_key,
|
||||||
|
output_format='xml'
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.warn("Tautulli Pmsconnect :: get_library_children called by invalid section_id or rating_key provided.")
|
logger.warn("Tautulli Pmsconnect :: get_library_children called by invalid section_id or rating_key provided.")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
try:
|
|
||||||
xml_head = library_data.getElementsByTagName('MediaContainer')
|
|
||||||
except Exception as e:
|
|
||||||
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_library_children_details: %s." % e)
|
|
||||||
return []
|
|
||||||
|
|
||||||
children_list = []
|
children_list = []
|
||||||
|
|
||||||
|
@ -3055,14 +3106,21 @@ class PmsConnect(object):
|
||||||
|
|
||||||
|
|
||||||
# get parent_rating_keys
|
# get parent_rating_keys
|
||||||
_artist = media_type in ('artist', 'album', 'track')
|
if media_type in ('artist', 'album', 'track'):
|
||||||
metadata = self.get_metadata_children(str(rating_key), str(section_id), artist=_artist, output_format='xml')
|
sort_type = '&artist.id={}&type=9'.format(rating_key)
|
||||||
|
xml_head = self.fetch_library_list(
|
||||||
|
section_id=str(section_id),
|
||||||
|
sort_type=sort_type,
|
||||||
|
output_format='xml'
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
metadata = self.get_metadata_children(str(rating_key), output_format='xml')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml_head = metadata.getElementsByTagName('MediaContainer')
|
xml_head = metadata.getElementsByTagName('MediaContainer')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_rating_keys_list: %s." % e)
|
logger.warn("Tautulli Pmsconnect :: Unable to parse XML for get_rating_keys_list: %s." % e)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
for a in xml_head:
|
for a in xml_head:
|
||||||
if a.getAttribute('size'):
|
if a.getAttribute('size'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue