Merge branch 'code-opt' into beta-version
This commit is contained in:
commit
12fe644b85
3 changed files with 21 additions and 77 deletions
|
@ -514,10 +514,8 @@ def process_indirect(key, offset, resolve=True):
|
||||||
playqueue = PQ.get_playqueue_from_type(
|
playqueue = PQ.get_playqueue_from_type(
|
||||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.plex_type])
|
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.plex_type])
|
||||||
playqueue.clear()
|
playqueue.clear()
|
||||||
item = PL.Playlist_Item()
|
item = PL.playlist_item_from_xml(xml[0])
|
||||||
item.xml = xml[0]
|
|
||||||
item.offset = offset
|
item.offset = offset
|
||||||
item.plex_type = v.PLEX_TYPE_CLIP
|
|
||||||
item.playmethod = 'DirectStream'
|
item.playmethod = 'DirectStream'
|
||||||
|
|
||||||
# Need to get yet another xml to get the final playback url
|
# Need to get yet another xml to get the final playback url
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Playqueue_Object(object):
|
||||||
return position
|
return position
|
||||||
|
|
||||||
|
|
||||||
class Playlist_Item(object):
|
class PlaylistItem(object):
|
||||||
"""
|
"""
|
||||||
Object to fill our playqueues and playlists with.
|
Object to fill our playqueues and playlists with.
|
||||||
|
|
||||||
|
@ -165,20 +165,20 @@ class Playlist_Item(object):
|
||||||
force_transcode [bool] defaults to False
|
force_transcode [bool] defaults to False
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._id = None
|
self.id = None
|
||||||
self._plex_id = None
|
self._plex_id = None
|
||||||
self.plex_type = None
|
self.plex_type = None
|
||||||
self._kodi_id = None
|
self.kodi_id = None
|
||||||
self.kodi_type = None
|
self.kodi_type = None
|
||||||
self.file = None
|
self.file = None
|
||||||
self._uri = None
|
self._uri = None
|
||||||
self.guid = None
|
self.guid = None
|
||||||
self.xml = None
|
self.xml = None
|
||||||
self.playmethod = None
|
self.playmethod = None
|
||||||
self._playcount = None
|
self.playcount = None
|
||||||
self._offset = None
|
self.offset = None
|
||||||
# If Plex video consists of several parts; part number
|
# If Plex video consists of several parts; part number
|
||||||
self._part = 0
|
self.part = 0
|
||||||
self.force_transcode = False
|
self.force_transcode = False
|
||||||
# Shall we ask user to resume this item?
|
# Shall we ask user to resume this item?
|
||||||
# None: ask user to resume
|
# None: ask user to resume
|
||||||
|
@ -192,8 +192,6 @@ class Playlist_Item(object):
|
||||||
|
|
||||||
@plex_id.setter
|
@plex_id.setter
|
||||||
def plex_id(self, value):
|
def plex_id(self, value):
|
||||||
if not isinstance(value, int) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._plex_id = value
|
self._plex_id = value
|
||||||
self._uri = ('server://%s/com.plexapp.plugins.library/library/metadata/%s' %
|
self._uri = ('server://%s/com.plexapp.plugins.library/library/metadata/%s' %
|
||||||
(app.CONN.machine_identifier, value))
|
(app.CONN.machine_identifier, value))
|
||||||
|
@ -202,58 +200,8 @@ class Playlist_Item(object):
|
||||||
def uri(self):
|
def uri(self):
|
||||||
return self._uri
|
return self._uri
|
||||||
|
|
||||||
@property
|
def __unicode__(self):
|
||||||
def id(self):
|
return ("{{"
|
||||||
return self._id
|
|
||||||
|
|
||||||
@id.setter
|
|
||||||
def id(self, value):
|
|
||||||
if not isinstance(value, int) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._id = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def kodi_id(self):
|
|
||||||
return self._kodi_id
|
|
||||||
|
|
||||||
@kodi_id.setter
|
|
||||||
def kodi_id(self, value):
|
|
||||||
if not isinstance(value, int) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._kodi_id = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def playcount(self):
|
|
||||||
return self._playcount
|
|
||||||
|
|
||||||
@playcount.setter
|
|
||||||
def playcount(self, value):
|
|
||||||
if not isinstance(value, int) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._playcount = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def offset(self):
|
|
||||||
return self._offset
|
|
||||||
|
|
||||||
@offset.setter
|
|
||||||
def offset(self, value):
|
|
||||||
if not isinstance(value, (int, float)) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._offset = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def part(self):
|
|
||||||
return self._part
|
|
||||||
|
|
||||||
@part.setter
|
|
||||||
def part(self, value):
|
|
||||||
if not isinstance(value, int) and value is not None:
|
|
||||||
raise TypeError('Passed %s instead of int!' % type(value))
|
|
||||||
self._part = value
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
answ = ("{{"
|
|
||||||
"'id': {self.id}, "
|
"'id': {self.id}, "
|
||||||
"'plex_id': {self.plex_id}, "
|
"'plex_id': {self.plex_id}, "
|
||||||
"'plex_type': '{self.plex_type}', "
|
"'plex_type': '{self.plex_type}', "
|
||||||
|
@ -265,13 +213,10 @@ class Playlist_Item(object):
|
||||||
"'playcount': {self.playcount}, "
|
"'playcount': {self.playcount}, "
|
||||||
"'offset': {self.offset}, "
|
"'offset': {self.offset}, "
|
||||||
"'force_transcode': {self.force_transcode}, "
|
"'force_transcode': {self.force_transcode}, "
|
||||||
"'part': {self.part}, ".format(self=self))
|
"'part': {self.part}".format(self=self))
|
||||||
answ = answ.encode('utf-8')
|
|
||||||
# etree xml.__repr__() could return string, not unicode
|
|
||||||
return answ + b"'xml': \"{self.xml}\"}}".format(self=self)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __repr__(self):
|
||||||
return self.__repr__()
|
return self.__unicode__().encode('utf-8')
|
||||||
|
|
||||||
def plex_stream_index(self, kodi_stream_index, stream_type):
|
def plex_stream_index(self, kodi_stream_index, stream_type):
|
||||||
"""
|
"""
|
||||||
|
@ -336,7 +281,7 @@ def playlist_item_from_kodi(kodi_item):
|
||||||
Supply with data['item'] as returned from Kodi JSON-RPC interface.
|
Supply with data['item'] as returned from Kodi JSON-RPC interface.
|
||||||
kodi_item dict contains keys 'id', 'type', 'file' (if applicable)
|
kodi_item dict contains keys 'id', 'type', 'file' (if applicable)
|
||||||
"""
|
"""
|
||||||
item = Playlist_Item()
|
item = PlaylistItem()
|
||||||
item.kodi_id = kodi_item.get('id')
|
item.kodi_id = kodi_item.get('id')
|
||||||
item.kodi_type = kodi_item.get('type')
|
item.kodi_type = kodi_item.get('type')
|
||||||
if item.kodi_id:
|
if item.kodi_id:
|
||||||
|
@ -384,8 +329,8 @@ def verify_kodi_item(plex_id, kodi_item):
|
||||||
if ((kodi_item['file'].startswith('plugin') and
|
if ((kodi_item['file'].startswith('plugin') and
|
||||||
not kodi_item['file'].startswith('plugin://%s' % v.ADDON_ID)) or
|
not kodi_item['file'].startswith('plugin://%s' % v.ADDON_ID)) or
|
||||||
kodi_item['file'].startswith('http')):
|
kodi_item['file'].startswith('http')):
|
||||||
LOG.info('kodi_item %s cannot be used for Plex playback', kodi_item)
|
LOG.debug('kodi_item cannot be used for Plex playback: %s', kodi_item)
|
||||||
raise PlaylistError
|
raise PlaylistError('kodi_item cannot be used for Plex playback')
|
||||||
LOG.debug('Starting research for Kodi id since we didnt get one: %s',
|
LOG.debug('Starting research for Kodi id since we didnt get one: %s',
|
||||||
kodi_item)
|
kodi_item)
|
||||||
# Try the VIDEO DB first - will find both movies and episodes
|
# Try the VIDEO DB first - will find both movies and episodes
|
||||||
|
@ -407,7 +352,7 @@ def playlist_item_from_plex(plex_id):
|
||||||
|
|
||||||
Returns a Playlist_Item
|
Returns a Playlist_Item
|
||||||
"""
|
"""
|
||||||
item = Playlist_Item()
|
item = PlaylistItem()
|
||||||
item.plex_id = plex_id
|
item.plex_id = plex_id
|
||||||
with PlexDB(lock=False) as plexdb:
|
with PlexDB(lock=False) as plexdb:
|
||||||
db_item = plexdb.item_by_id(plex_id)
|
db_item = plexdb.item_by_id(plex_id)
|
||||||
|
@ -427,7 +372,7 @@ def playlist_item_from_xml(xml_video_element, kodi_id=None, kodi_type=None):
|
||||||
|
|
||||||
xml_video_element: etree xml piece 1 level underneath <MediaContainer>
|
xml_video_element: etree xml piece 1 level underneath <MediaContainer>
|
||||||
"""
|
"""
|
||||||
item = Playlist_Item()
|
item = PlaylistItem()
|
||||||
api = API(xml_video_element)
|
api = API(xml_video_element)
|
||||||
item.plex_id = api.plex_id
|
item.plex_id = api.plex_id
|
||||||
item.plex_type = api.plex_type
|
item.plex_type = api.plex_type
|
||||||
|
@ -437,9 +382,10 @@ def playlist_item_from_xml(xml_video_element, kodi_id=None, kodi_type=None):
|
||||||
if kodi_id is not None:
|
if kodi_id is not None:
|
||||||
item.kodi_id = kodi_id
|
item.kodi_id = kodi_id
|
||||||
item.kodi_type = kodi_type
|
item.kodi_type = kodi_type
|
||||||
elif item.plex_id is not None and item.plex_type != v.PLEX_TYPE_CLIP:
|
elif item.plex_type != v.PLEX_TYPE_CLIP:
|
||||||
with PlexDB(lock=False) as plexdb:
|
with PlexDB(lock=False) as plexdb:
|
||||||
db_element = plexdb.item_by_id(item.plex_id)
|
db_element = plexdb.item_by_id(item.plex_id,
|
||||||
|
plex_type=item.plex_type)
|
||||||
if db_element:
|
if db_element:
|
||||||
item.kodi_id = db_element['kodi_id']
|
item.kodi_id = db_element['kodi_id']
|
||||||
item.kodi_type = db_element['kodi_type']
|
item.kodi_type = db_element['kodi_type']
|
||||||
|
|
|
@ -17,7 +17,7 @@ class PlayUtils():
|
||||||
def __init__(self, api, playqueue_item):
|
def __init__(self, api, playqueue_item):
|
||||||
"""
|
"""
|
||||||
init with api (PlexAPI wrapper of the PMS xml element) and
|
init with api (PlexAPI wrapper of the PMS xml element) and
|
||||||
playqueue_item (Playlist_Item())
|
playqueue_item (PlaylistItem())
|
||||||
"""
|
"""
|
||||||
self.api = api
|
self.api = api
|
||||||
self.item = playqueue_item
|
self.item = playqueue_item
|
||||||
|
|
Loading…
Reference in a new issue