Refactoring: playlist and playqueue items to use API instead of xml
This commit is contained in:
parent
176fa07e80
commit
2bd692e173
3 changed files with 31 additions and 31 deletions
|
@ -344,8 +344,7 @@ class KodiMonitor(xbmc.Monitor):
|
|||
container_key = '/library/metadata/%s' % plex_id
|
||||
# Mechanik for Plex skip intro feature
|
||||
if utils.settings('enableSkipIntro') == 'true':
|
||||
api = API(item.xml)
|
||||
status['intro_markers'] = api.intro_markers()
|
||||
status['intro_markers'] = item.api.intro_markers()
|
||||
# Remember the currently playing item
|
||||
app.PLAYSTATE.item = item
|
||||
# Remember that this player has been active
|
||||
|
@ -593,11 +592,10 @@ def _next_episode(current_api):
|
|||
current_api.grandparent_title())
|
||||
return
|
||||
try:
|
||||
next_api = API(xml[counter + 1])
|
||||
return API(xml[counter + 1])
|
||||
except IndexError:
|
||||
# Was the last episode
|
||||
return
|
||||
return next_api
|
||||
pass
|
||||
|
||||
|
||||
def _complete_artwork_keys(info):
|
||||
|
@ -623,7 +621,7 @@ def _notify_upnext(item):
|
|||
"""
|
||||
if not item.plex_type == v.PLEX_TYPE_EPISODE:
|
||||
return
|
||||
this_api = API(item.xml)
|
||||
this_api = item.api
|
||||
next_api = _next_episode(this_api)
|
||||
if next_api is None:
|
||||
return
|
||||
|
|
|
@ -445,27 +445,26 @@ def _conclude_playback(playqueue, pos):
|
|||
"""
|
||||
LOG.debug('Concluding playback for playqueue position %s', pos)
|
||||
item = playqueue.items[pos]
|
||||
api = API(item.xml)
|
||||
if api.mediastream_number() is None:
|
||||
if item.api.mediastream_number() is None:
|
||||
# E.g. user could choose between several media streams and cancelled
|
||||
LOG.debug('Did not get a mediastream_number')
|
||||
_ensure_resolve()
|
||||
return
|
||||
api.part = item.part or 0
|
||||
playback_decision.set_pkc_playmethod(api, item)
|
||||
if not playback_decision.audio_subtitle_prefs(api, item):
|
||||
item.api.part = item.part or 0
|
||||
playback_decision.set_pkc_playmethod(item.api, item)
|
||||
if not playback_decision.audio_subtitle_prefs(item.api, item):
|
||||
LOG.info('Did not set audio subtitle prefs, aborting silently')
|
||||
_ensure_resolve()
|
||||
return
|
||||
playback_decision.set_playurl(api, item)
|
||||
playback_decision.set_playurl(item.api, item)
|
||||
if not item.file:
|
||||
LOG.info('Did not get a playurl, aborting playback silently')
|
||||
_ensure_resolve()
|
||||
return
|
||||
listitem = api.listitem(listitem=transfer.PKCListItem, resume=False)
|
||||
listitem = item.api.listitem(listitem=transfer.PKCListItem, resume=False)
|
||||
listitem.setPath(item.file.encode('utf-8'))
|
||||
if item.playmethod != v.PLAYBACK_METHOD_DIRECT_PATH:
|
||||
listitem.setSubtitles(api.cache_external_subs())
|
||||
listitem.setSubtitles(item.api.cache_external_subs())
|
||||
transfer.send(listitem)
|
||||
LOG.debug('Done concluding playback')
|
||||
|
||||
|
|
|
@ -149,13 +149,14 @@ class PlaylistItem(object):
|
|||
file = None [str] Path to the item's file. STRING!!
|
||||
uri = None [str] PMS path to item; will be auto-set with plex_id
|
||||
guid = None [str] Weird Plex guid
|
||||
xml = None [etree] XML from PMS, 1 lvl below <MediaContainer>
|
||||
api = None [API] API of xml 1 lvl below <MediaContainer>
|
||||
playmethod = None [str] either 'DirectPath', 'DirectStream', 'Transcode'
|
||||
playcount = None [int] how many times the item has already been played
|
||||
offset = None [int] the item's view offset UPON START in Plex time
|
||||
part = 0 [int] part number if Plex video consists of mult. parts
|
||||
force_transcode [bool] defaults to False
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.id = None
|
||||
self._plex_id = None
|
||||
|
@ -165,7 +166,7 @@ class PlaylistItem(object):
|
|||
self.file = None
|
||||
self._uri = None
|
||||
self.guid = None
|
||||
self.xml = None
|
||||
self.api = None
|
||||
self.playmethod = None
|
||||
self.playcount = None
|
||||
self.offset = None
|
||||
|
@ -226,10 +227,10 @@ class PlaylistItem(object):
|
|||
count = 0
|
||||
if kodi_stream_index == -1:
|
||||
# Kodi telling us "it's the last one"
|
||||
iterator = list(reversed(self.xml[0][self.part]))
|
||||
iterator = list(reversed(self.api.plex_media_streams()))
|
||||
kodi_stream_index = 0
|
||||
else:
|
||||
iterator = self.xml[0][self.part]
|
||||
iterator = self.api.plex_media_streams()
|
||||
# Kodi indexes differently than Plex
|
||||
for stream in iterator:
|
||||
if (stream.get('streamType') == stream_type and
|
||||
|
@ -270,7 +271,7 @@ class PlaylistItem(object):
|
|||
Returns None if no stream has been selected
|
||||
"""
|
||||
stream_type = v.PLEX_STREAM_TYPE_FROM_STREAM_TYPE[stream_type]
|
||||
for stream in self.xml[0][self.part]:
|
||||
for stream in self.api.plex_media_streams():
|
||||
if stream.get('streamType') == stream_type \
|
||||
and stream.get('selected') == '1':
|
||||
return (utils.cast(int, stream.get('id')),
|
||||
|
@ -287,9 +288,9 @@ class PlaylistItem(object):
|
|||
if stream_type == '3':
|
||||
streams = accessible_plex_subtitles(self.playmethod,
|
||||
self.file,
|
||||
self.xml[0][self.part])
|
||||
self.api.plex_media_streams())
|
||||
else:
|
||||
streams = [x for x in self.xml[0][self.part]
|
||||
streams = [x for x in self.api.plex_media_streams()
|
||||
if x.get('streamType') == stream_type]
|
||||
return streams
|
||||
|
||||
|
@ -415,14 +416,15 @@ def playlist_item_from_xml(xml_video_element, kodi_id=None, kodi_type=None):
|
|||
item.guid = api.guid_html_escaped()
|
||||
item.playcount = api.viewcount()
|
||||
item.offset = api.resume_point()
|
||||
item.xml = xml_video_element
|
||||
item.api = api
|
||||
LOG.debug('Created new playlist item from xml: %s', item)
|
||||
return item
|
||||
|
||||
|
||||
def _get_playListVersion_from_xml(playlist, xml):
|
||||
def _update_playlist_version(playlist, xml):
|
||||
"""
|
||||
Takes a PMS xml as input to overwrite the playlist version (e.g. Plex
|
||||
Takes a PMS xml (one level above the xml-depth where we're usually applying
|
||||
API()) as input to overwrite the playlist version (e.g. Plex
|
||||
playQueueVersion).
|
||||
|
||||
Raises PlaylistError if unsuccessful
|
||||
|
@ -605,7 +607,7 @@ def add_item_to_plex_playqueue(playlist, pos, plex_id=None, kodi_item=None):
|
|||
raise PlaylistError('Could not add item %s to playlist %s'
|
||||
% (kodi_item, playlist))
|
||||
api = API(xml[-1])
|
||||
item.xml = xml[-1]
|
||||
item.api = api
|
||||
item.id = api.item_id()
|
||||
item.guid = api.guid_html_escaped()
|
||||
item.offset = api.resume_point()
|
||||
|
@ -613,7 +615,7 @@ def add_item_to_plex_playqueue(playlist, pos, plex_id=None, kodi_item=None):
|
|||
playlist.items.append(item)
|
||||
if pos == len(playlist.items) - 1:
|
||||
# Item was added at the end
|
||||
_get_playListVersion_from_xml(playlist, xml)
|
||||
_update_playlist_version(playlist, xml)
|
||||
else:
|
||||
# Move the new item to the correct position
|
||||
move_playlist_item(playlist,
|
||||
|
@ -657,7 +659,7 @@ def add_item_to_kodi_playlist(playlist, pos, kodi_id=None, kodi_type=None,
|
|||
{'id': kodi_id, 'type': kodi_type, 'file': file})
|
||||
if item.plex_id is not None:
|
||||
xml = PF.GetPlexMetadata(item.plex_id)
|
||||
item.xml = xml[-1]
|
||||
item.api = API(xml[-1])
|
||||
playlist.items.insert(pos, item)
|
||||
return item
|
||||
|
||||
|
@ -681,9 +683,10 @@ def move_playlist_item(playlist, before_pos, after_pos):
|
|||
playlist.id,
|
||||
playlist.items[before_pos].id,
|
||||
playlist.items[after_pos - 1].id)
|
||||
# We need to increment the playlistVersion
|
||||
_get_playListVersion_from_xml(
|
||||
playlist, DU().downloadUrl(url, action_type="PUT"))
|
||||
# Tell the PMS that we're moving items around
|
||||
xml = DU().downloadUrl(url, action_type="PUT")
|
||||
# We need to increment the playlist version for communicating with the PMS
|
||||
_update_playlist_version(playlist, xml)
|
||||
# Move our item's position in our internal playlist
|
||||
playlist.items.insert(after_pos, playlist.items.pop(before_pos))
|
||||
LOG.debug('Done moving for %s', playlist)
|
||||
|
@ -731,7 +734,7 @@ def delete_playlist_item_from_PMS(playlist, pos):
|
|||
playlist.repeat),
|
||||
action_type="DELETE")
|
||||
del playlist.items[pos]
|
||||
_get_playListVersion_from_xml(playlist, xml)
|
||||
_update_playlist_version(playlist, xml)
|
||||
|
||||
|
||||
# Functions operating on the Kodi playlist objects ##########
|
||||
|
|
Loading…
Reference in a new issue