diff --git a/resources/lib/playback.py b/resources/lib/playback.py index f094943d..f32b0297 100644 --- a/resources/lib/playback.py +++ b/resources/lib/playback.py @@ -235,7 +235,10 @@ def _playback_init(plex_id, plex_type, playqueue, pos): playqueue.clear() if plex_type != v.PLEX_TYPE_CLIP: # Post to the PMS to create a playqueue - in any case due to Companion - xml = PF.init_plex_playqueue(plex_id, plex_type, trailers=trailers) + xml = PF.init_plex_playqueue(plex_id, + plex_type, + xml.get('librarySectionUUID'), + trailers=trailers) if xml is None: LOG.error('Could not get a playqueue xml for plex id %s', plex_id) # "Play error" diff --git a/resources/lib/plex_functions.py b/resources/lib/plex_functions.py index a378d5d3..7a54a240 100644 --- a/resources/lib/plex_functions.py +++ b/resources/lib/plex_functions.py @@ -820,10 +820,10 @@ def get_plex_sections(): return xml -def init_plex_playqueue(plex_id, plex_type, trailers=False): +def init_plex_playqueue(plex_id, plex_type, section_uuid, trailers=False): """ Returns raw API metadata XML dump for a playlist with e.g. trailers. - """ + """ url = "{server}/playQueues" args = { 'type': plex_type, @@ -839,8 +839,30 @@ def init_plex_playqueue(plex_id, plex_type, trailers=False): try: xml[0].tag except (IndexError, TypeError, AttributeError): - LOG.error("Error retrieving metadata for %s", url) - return + LOG.warn('Need to initialize Plex playqueue the old fashioned way') + xml = init_plex_playqueue_old_fashioned(plex_id, section_uuid, url, args) + return xml + + +def init_plex_playqueue_old_fashioned(plex_id, section_uuid, url, args): + """ + In rare cases (old PMS version?), the PMS does not allow to add media using + an uri + server:///com.plexapp.plugins.library/library... + We need to use + library:///item/... + + This involves an extra step to grab the librarySectionUUID for plex_id + """ + args['uri'] = 'library://{0}/item/%2Flibrary%2Fmetadata%2F{1}'.format( + section_uuid, plex_id) + xml = DU().downloadUrl(utils.extend_url(url, args), action_type="POST") + try: + xml[0].tag + except (IndexError, TypeError, AttributeError): + LOG.error('Error initializing the playqueue the old fashioned way %s', + utils.extend_url(url, args)) + xml = None return xml