Simplify code
This commit is contained in:
parent
f4c3674bc2
commit
0d36a2a3b9
1 changed files with 24 additions and 17 deletions
|
@ -31,6 +31,7 @@ class PlayStrm(object):
|
||||||
LOG.debug('Starting PlayStrm with server_id %s, params: %s',
|
LOG.debug('Starting PlayStrm with server_id %s, params: %s',
|
||||||
server_id, params)
|
server_id, params)
|
||||||
self.xml = None
|
self.xml = None
|
||||||
|
self.playqueue_item = None
|
||||||
self.api = None
|
self.api = None
|
||||||
self.start_index = None
|
self.start_index = None
|
||||||
self.index = None
|
self.index = None
|
||||||
|
@ -41,10 +42,10 @@ class PlayStrm(object):
|
||||||
self.synched = False
|
self.synched = False
|
||||||
else:
|
else:
|
||||||
self.synched = True
|
self.synched = True
|
||||||
self._get_xml()
|
|
||||||
self.name = self.api.title()
|
|
||||||
self.kodi_id = utils.cast(int, params.get('kodi_id'))
|
self.kodi_id = utils.cast(int, params.get('kodi_id'))
|
||||||
self.kodi_type = params.get('kodi_type')
|
self.kodi_type = params.get('kodi_type')
|
||||||
|
self._get_xml()
|
||||||
|
self.name = self.api.title()
|
||||||
if ((self.kodi_id is None or self.kodi_type is None) and
|
if ((self.kodi_id is None or self.kodi_type is None) and
|
||||||
self.xml[0].get('pkc_db_item')):
|
self.xml[0].get('pkc_db_item')):
|
||||||
self.kodi_id = self.xml[0].get('pkc_db_item')['kodi_id']
|
self.kodi_id = self.xml[0].get('pkc_db_item')['kodi_id']
|
||||||
|
@ -86,6 +87,12 @@ class PlayStrm(object):
|
||||||
'position': self.index,
|
'position': self.index,
|
||||||
'item': {'%sid' % self.kodi_type: self.kodi_id}})
|
'item': {'%sid' % self.kodi_type: self.kodi_id}})
|
||||||
|
|
||||||
|
def playlist_add(self, url, listitem):
|
||||||
|
self.kodi_playlist.add(url=url, listitem=listitem, index=self.index)
|
||||||
|
self.playqueue_item.file = url.decode('utf-8')
|
||||||
|
self.playqueue.items.insert(self.index, self.playqueue_item)
|
||||||
|
self.index += 1
|
||||||
|
|
||||||
def remove_from_playlist(self, index):
|
def remove_from_playlist(self, index):
|
||||||
LOG.debug('Removing playlist item number %s from %s', index, self)
|
LOG.debug('Removing playlist item number %s from %s', index, self)
|
||||||
json_rpc.playlist_remove(self.kodi_playlist.getPlayListId(),
|
json_rpc.playlist_remove(self.kodi_playlist.getPlayListId(),
|
||||||
|
@ -101,7 +108,9 @@ class PlayStrm(object):
|
||||||
else:
|
else:
|
||||||
self.xml[0].set('pkc_db_item', None)
|
self.xml[0].set('pkc_db_item', None)
|
||||||
self.api = API(self.xml[0])
|
self.api = API(self.xml[0])
|
||||||
self.playqueue_item = PL.playlist_item_from_xml(self.xml[0])
|
self.playqueue_item = PL.playlist_item_from_xml(self.xml[0],
|
||||||
|
kodi_id=self.kodi_id,
|
||||||
|
kodi_type=self.kodi_type)
|
||||||
|
|
||||||
def start_playback(self, index=0):
|
def start_playback(self, index=0):
|
||||||
LOG.debug('Starting playback at %s', index)
|
LOG.debug('Starting playback at %s', index)
|
||||||
|
@ -133,6 +142,7 @@ class PlayStrm(object):
|
||||||
LOG.info('Play folder plex_id %s, index: %s', self.plex_id, self.index)
|
LOG.info('Play folder plex_id %s, index: %s', self.plex_id, self.index)
|
||||||
if self.kodi_id and self.kodi_type:
|
if self.kodi_id and self.kodi_type:
|
||||||
self.playlist_add_json()
|
self.playlist_add_json()
|
||||||
|
self.index += 1
|
||||||
else:
|
else:
|
||||||
listitem = widgets.get_listitem(self.xml[0], resume=True)
|
listitem = widgets.get_listitem(self.xml[0], resume=True)
|
||||||
url = 'http://127.0.0.1:%s/plex/play/file.strm' % v.WEBSERVICE_PORT
|
url = 'http://127.0.0.1:%s/plex/play/file.strm' % v.WEBSERVICE_PORT
|
||||||
|
@ -151,10 +161,8 @@ class PlayStrm(object):
|
||||||
args['transcode'] = True
|
args['transcode'] = True
|
||||||
url = utils.extend_url(url, args).encode('utf-8')
|
url = utils.extend_url(url, args).encode('utf-8')
|
||||||
listitem.setPath(url)
|
listitem.setPath(url)
|
||||||
self.kodi_playlist.add(url=url,
|
self.playlist_add(url, listitem)
|
||||||
listitem=listitem,
|
return self.index - 1
|
||||||
index=self.index)
|
|
||||||
return self.index
|
|
||||||
|
|
||||||
def _set_playlist(self):
|
def _set_playlist(self):
|
||||||
'''
|
'''
|
||||||
|
@ -200,8 +208,7 @@ class PlayStrm(object):
|
||||||
play = PlayUtils(self.api, self.playqueue_item)
|
play = PlayUtils(self.api, self.playqueue_item)
|
||||||
url = play.getPlayUrl().encode('utf-8')
|
url = play.getPlayUrl().encode('utf-8')
|
||||||
listitem.setPath(url)
|
listitem.setPath(url)
|
||||||
self.kodi_playlist.add(url=url, listitem=listitem, index=self.index)
|
self.playlist_add(url, listitem)
|
||||||
self.index += 1
|
|
||||||
if self.xml.get('PartCount'):
|
if self.xml.get('PartCount'):
|
||||||
self._set_additional_parts()
|
self._set_additional_parts()
|
||||||
|
|
||||||
|
@ -238,14 +245,11 @@ class PlayStrm(object):
|
||||||
continue
|
continue
|
||||||
api = API(intro)
|
api = API(intro)
|
||||||
listitem = widgets.get_listitem(intro, resume=False)
|
listitem = widgets.get_listitem(intro, resume=False)
|
||||||
listitem.setSubtitles(api.cache_external_subs())
|
self.playqueue_item = PL.playlist_item_from_xml(intro)
|
||||||
playqueue_item = PL.playlist_item_from_xml(intro)
|
play = PlayUtils(api, self.playqueue_item)
|
||||||
play = PlayUtils(api, playqueue_item)
|
|
||||||
url = play.getPlayUrl().encode('utf-8')
|
url = play.getPlayUrl().encode('utf-8')
|
||||||
listitem.setPath(url)
|
listitem.setPath(url)
|
||||||
self.kodi_playlist.add(url=url, listitem=listitem, index=self.index)
|
self.playlist_add(url, listitem)
|
||||||
self.index += 1
|
|
||||||
utils.window('plex.skip.%s' % api.plex_id(), value='true')
|
|
||||||
|
|
||||||
def _set_additional_parts(self):
|
def _set_additional_parts(self):
|
||||||
''' Create listitems and add them to the stack of playlist.
|
''' Create listitems and add them to the stack of playlist.
|
||||||
|
@ -255,11 +259,14 @@ class PlayStrm(object):
|
||||||
# The first part that we've already added
|
# The first part that we've already added
|
||||||
continue
|
continue
|
||||||
self.api.set_part_number(part)
|
self.api.set_part_number(part)
|
||||||
|
self.playqueue_item = PL.playlist_item_from_xml(self.xml[0],
|
||||||
|
kodi_id=self.kodi_id,
|
||||||
|
kodi_type=self.kodi_type)
|
||||||
|
self.playqueue_item.part = part
|
||||||
listitem = widgets.get_listitem(self.xml[0], resume=False)
|
listitem = widgets.get_listitem(self.xml[0], resume=False)
|
||||||
listitem.setSubtitles(self.api.cache_external_subs())
|
listitem.setSubtitles(self.api.cache_external_subs())
|
||||||
playqueue_item = PL.playlist_item_from_xml(self.xml[0])
|
playqueue_item = PL.playlist_item_from_xml(self.xml[0])
|
||||||
play = PlayUtils(self.api, playqueue_item)
|
play = PlayUtils(self.api, playqueue_item)
|
||||||
url = play.getPlayUrl().encode('utf-8')
|
url = play.getPlayUrl().encode('utf-8')
|
||||||
listitem.setPath(url)
|
listitem.setPath(url)
|
||||||
self.kodi_playlist.add(url=url, listitem=listitem, index=self.index)
|
self.playlist_add(url, listitem)
|
||||||
self.index += 1
|
|
||||||
|
|
Loading…
Reference in a new issue