Cleanup
This commit is contained in:
parent
d3752e1958
commit
fb21bc7d71
2 changed files with 47 additions and 39 deletions
|
@ -12,7 +12,7 @@ PLAYQUEUES = []
|
||||||
|
|
||||||
class PlayqueueError(Exception):
|
class PlayqueueError(Exception):
|
||||||
"""
|
"""
|
||||||
Exception for our playlist constructs
|
Exception for our playqueue constructs
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class PlaylistItem(object):
|
||||||
self.kodi_type = kodi_type
|
self.kodi_type = kodi_type
|
||||||
self.file = None
|
self.file = None
|
||||||
if kodi_item:
|
if kodi_item:
|
||||||
self.kodi_id = kodi_item.get('id')
|
self.kodi_id = utils.cast(int, kodi_item.get('id'))
|
||||||
self.kodi_type = kodi_item.get('type')
|
self.kodi_type = kodi_item.get('type')
|
||||||
self.file = kodi_item.get('file')
|
self.file = kodi_item.get('file')
|
||||||
self.uri = None
|
self.uri = None
|
||||||
|
@ -76,15 +76,9 @@ class PlaylistItem(object):
|
||||||
# False: do NOT resume, don't ask user
|
# False: do NOT resume, don't ask user
|
||||||
# True: do resume, don't ask user
|
# True: do resume, don't ask user
|
||||||
self.resume = None
|
self.resume = None
|
||||||
if (self.plex_id is None and
|
if self.plex_id is None:
|
||||||
(self.kodi_id is not None and self.kodi_type is not None)):
|
self._from_plex_db()
|
||||||
with PlexDB(lock=False) as plexdb:
|
if grab_xml and self.plex_id is not None and xml_video_element is None:
|
||||||
db_item = plexdb.item_by_kodi_id(self.kodi_id, self.kodi_type)
|
|
||||||
if db_item:
|
|
||||||
self.plex_id = db_item['plex_id']
|
|
||||||
self.plex_type = db_item['plex_type']
|
|
||||||
self.plex_uuid = db_item['section_uuid']
|
|
||||||
if grab_xml and plex_id is not None and xml_video_element is None:
|
|
||||||
xml_video_element = PF.GetPlexMetadata(plex_id)
|
xml_video_element = PF.GetPlexMetadata(plex_id)
|
||||||
try:
|
try:
|
||||||
xml_video_element = xml_video_element[0]
|
xml_video_element = xml_video_element[0]
|
||||||
|
@ -99,11 +93,13 @@ class PlaylistItem(object):
|
||||||
if db_item is not None:
|
if db_item is not None:
|
||||||
self.kodi_id = db_item['kodi_id']
|
self.kodi_id = db_item['kodi_id']
|
||||||
self.kodi_type = db_item['kodi_type']
|
self.kodi_type = db_item['kodi_type']
|
||||||
|
self.plex_type = db_item['plex_type']
|
||||||
self.plex_uuid = db_item['section_uuid']
|
self.plex_uuid = db_item['section_uuid']
|
||||||
if (lookup_kodi and (self.kodi_id is None or self.kodi_type is None) and
|
if (lookup_kodi and (self.kodi_id is None or self.kodi_type is None) and
|
||||||
self.plex_type != v.PLEX_TYPE_CLIP):
|
self.plex_type != v.PLEX_TYPE_CLIP):
|
||||||
self._guess_id_from_file()
|
self._guess_id_from_file()
|
||||||
self.set_uri()
|
self._from_plex_db()
|
||||||
|
self._set_uri()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if self.plex_id is not None and other.plex_id is not None:
|
if self.plex_id is not None and other.plex_id is not None:
|
||||||
|
@ -142,6 +138,20 @@ class PlaylistItem(object):
|
||||||
return unicode(self).encode('utf-8')
|
return unicode(self).encode('utf-8')
|
||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
|
|
||||||
|
def _from_plex_db(self):
|
||||||
|
"""
|
||||||
|
Uses self.kodi_id and self.kodi_type to look up the item in the Plex
|
||||||
|
DB. Thus potentially sets self.plex_id, plex_type, plex_uuid
|
||||||
|
"""
|
||||||
|
if self.kodi_id is None or not self.kodi_type:
|
||||||
|
return
|
||||||
|
with PlexDB(lock=False) as plexdb:
|
||||||
|
db_item = plexdb.item_by_kodi_id(self.kodi_id, self.kodi_type)
|
||||||
|
if db_item:
|
||||||
|
self.plex_id = db_item['plex_id']
|
||||||
|
self.plex_type = db_item['plex_type']
|
||||||
|
self.plex_uuid = db_item['section_uuid']
|
||||||
|
|
||||||
def from_xml(self, xml_video_element):
|
def from_xml(self, xml_video_element):
|
||||||
"""
|
"""
|
||||||
xml_video_element: etree xml piece 1 level underneath <MediaContainer>
|
xml_video_element: etree xml piece 1 level underneath <MediaContainer>
|
||||||
|
@ -157,7 +167,9 @@ class PlaylistItem(object):
|
||||||
self.playcount = api.viewcount()
|
self.playcount = api.viewcount()
|
||||||
self.offset = api.resume_point()
|
self.offset = api.resume_point()
|
||||||
self.xml = xml_video_element
|
self.xml = xml_video_element
|
||||||
self.set_uri()
|
if self.kodi_id is None or not self.kodi_type:
|
||||||
|
self._from_plex_db()
|
||||||
|
self._set_uri()
|
||||||
|
|
||||||
def from_kodi(self, playlist_item):
|
def from_kodi(self, playlist_item):
|
||||||
"""
|
"""
|
||||||
|
@ -167,17 +179,12 @@ class PlaylistItem(object):
|
||||||
If kodi_id & kodi_type are provided, plex_id and plex_type will be
|
If kodi_id & kodi_type are provided, plex_id and plex_type will be
|
||||||
looked up (if not already set)
|
looked up (if not already set)
|
||||||
"""
|
"""
|
||||||
self.kodi_id = playlist_item.get('id')
|
self.kodi_id = utils.cast(int, playlist_item.get('id'))
|
||||||
self.kodi_type = playlist_item.get('type')
|
self.kodi_type = playlist_item.get('type')
|
||||||
self.file = playlist_item.get('file')
|
self.file = playlist_item.get('file')
|
||||||
if self.plex_id is None and self.kodi_id is not None and self.kodi_type:
|
if self.plex_id is None and self.kodi_id is not None and self.kodi_type:
|
||||||
with PlexDB(lock=False) as plexdb:
|
self._from_plex_db()
|
||||||
db_item = plexdb.item_by_kodi_id(self.kodi_id, self.kodi_type)
|
if self.plex_id is None and self.file:
|
||||||
if db_item:
|
|
||||||
self.plex_id = db_item['plex_id']
|
|
||||||
self.plex_type = db_item['plex_type']
|
|
||||||
self.plex_uuid = db_item['section_uuid']
|
|
||||||
if self.plex_id is None and self.file is not None:
|
|
||||||
try:
|
try:
|
||||||
query = self.file.split('?', 1)[1]
|
query = self.file.split('?', 1)[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
@ -185,14 +192,13 @@ class PlaylistItem(object):
|
||||||
query = dict(utils.parse_qsl(query))
|
query = dict(utils.parse_qsl(query))
|
||||||
self.plex_id = utils.cast(int, query.get('plex_id'))
|
self.plex_id = utils.cast(int, query.get('plex_id'))
|
||||||
self.plex_type = query.get('itemType')
|
self.plex_type = query.get('itemType')
|
||||||
self.set_uri()
|
self._set_uri()
|
||||||
|
|
||||||
def set_uri(self):
|
def _set_uri(self):
|
||||||
if self.plex_id is None and self.file is not None:
|
if self.plex_id is None and self.file is not None:
|
||||||
self.uri = ('library://whatever/item/%s'
|
self.uri = ('library://whatever/item/%s'
|
||||||
% utils.quote(self.file, safe=''))
|
% utils.quote(self.file, safe=''))
|
||||||
elif self.plex_id is not None and self.plex_uuid is not None:
|
elif self.plex_id is not None and self.plex_uuid is not None:
|
||||||
# TO BE VERIFIED - PLEX DOESN'T LIKE PLAYLIST ADDS IN THIS MANNER
|
|
||||||
self.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
|
self.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
|
||||||
(self.plex_uuid, self.plex_id))
|
(self.plex_uuid, self.plex_id))
|
||||||
elif self.plex_id is not None:
|
elif self.plex_id is not None:
|
||||||
|
@ -203,6 +209,8 @@ class PlaylistItem(object):
|
||||||
|
|
||||||
def _guess_id_from_file(self):
|
def _guess_id_from_file(self):
|
||||||
"""
|
"""
|
||||||
|
If self.file is set, will try to guess kodi_id and kodi_type from the
|
||||||
|
filename and path using the Kodi video and music databases
|
||||||
"""
|
"""
|
||||||
if not self.file:
|
if not self.file:
|
||||||
return
|
return
|
||||||
|
@ -219,12 +227,12 @@ class PlaylistItem(object):
|
||||||
self.file.startswith('http://127.0.0.1:%s' % v.WEBSERVICE_PORT))):
|
self.file.startswith('http://127.0.0.1:%s' % v.WEBSERVICE_PORT))):
|
||||||
return
|
return
|
||||||
# Try the VIDEO DB first - will find both movies and episodes
|
# Try the VIDEO DB first - will find both movies and episodes
|
||||||
self.kodi_id, self.kodi_type = kodi_db.kodiid_from_filename(self.file,
|
self.kodi_id, self.kodi_type = kodi_db.kodiid_from_filename(
|
||||||
db_type='video')
|
self.file, db_type='video')
|
||||||
if self.kodi_id is None:
|
if self.kodi_id is None:
|
||||||
# No movie or episode found - try MUSIC DB now for songs
|
# No movie or episode found - try MUSIC DB now for songs
|
||||||
self.kodi_id, self.kodi_type = kodi_db.kodiid_from_filename(self.file,
|
self.kodi_id, self.kodi_type = kodi_db.kodiid_from_filename(
|
||||||
db_type='music')
|
self.file, db_type='music')
|
||||||
self.kodi_type = None if self.kodi_id is None else self.kodi_type
|
self.kodi_type = None if self.kodi_id is None else self.kodi_type
|
||||||
|
|
||||||
def plex_stream_index(self, kodi_stream_index, stream_type):
|
def plex_stream_index(self, kodi_stream_index, stream_type):
|
||||||
|
@ -289,6 +297,6 @@ class PlaylistItemDummy(PlaylistItem):
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PlaylistItemDummy, self).__init__(*args, **kwargs)
|
super(PlaylistItemDummy, self).__init__(*args, **kwargs)
|
||||||
self.name = 'dummy item'
|
self.name = 'PKC Dummy playqueue item'
|
||||||
self.id = 0
|
self.id = 0
|
||||||
self.plex_id = 0
|
self.plex_id = 0
|
||||||
|
|
Loading…
Reference in a new issue