Rename to PlayqueueError

This commit is contained in:
croneter 2019-05-26 11:26:14 +02:00
parent 3d4bde878e
commit d3752e1958
5 changed files with 33 additions and 36 deletions

View file

@ -5,7 +5,7 @@ Monitors the Kodi playqueue and adjusts the Plex playqueue accordingly
""" """
from __future__ import absolute_import, division, unicode_literals from __future__ import absolute_import, division, unicode_literals
from .common import PlaylistItem, PlaylistItemDummy, PlaylistError, PLAYQUEUES from .common import PlaylistItem, PlaylistItemDummy, PlayqueueError, PLAYQUEUES
from .playqueue import PlayQueue from .playqueue import PlayQueue
from .monitor import PlayqueueMonitor from .monitor import PlayqueueMonitor
from .functions import init_playqueues, get_playqueue_from_type, \ from .functions import init_playqueues, get_playqueue_from_type, \

View file

@ -10,7 +10,7 @@ from .. import plex_functions as PF, utils, kodi_db, variables as v, app
PLAYQUEUES = [] PLAYQUEUES = []
class PlaylistError(Exception): class PlayqueueError(Exception):
""" """
Exception for our playlist constructs Exception for our playlist constructs
""" """

View file

@ -7,7 +7,7 @@ from __future__ import absolute_import, division, unicode_literals
from logging import getLogger from logging import getLogger
import copy import copy
from .common import PlaylistError, PlaylistItem, PLAYQUEUES from .common import PlayqueueError, PlaylistItem, PLAYQUEUES
from .. import backgroundthread, json_rpc as js, utils, app from .. import backgroundthread, json_rpc as js, utils, app
@ -68,7 +68,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
i + j, i) i + j, i)
try: try:
playqueue.plex_move_item(i + j, i) playqueue.plex_move_item(i + j, i)
except PlaylistError: except PlayqueueError:
LOG.error('Could not modify playqueue positions') LOG.error('Could not modify playqueue positions')
LOG.error('This is likely caused by mixing audio and ' LOG.error('This is likely caused by mixing audio and '
'video tracks in the Kodi playqueue') 'video tracks in the Kodi playqueue')
@ -83,7 +83,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
playqueue.init(playlistitem) playqueue.init(playlistitem)
else: else:
playqueue.plex_add_item(playlistitem, i) playqueue.plex_add_item(playlistitem, i)
except PlaylistError: except PlayqueueError:
LOG.warn('Couldnt add new item to Plex: %s', playlistitem) LOG.warn('Couldnt add new item to Plex: %s', playlistitem)
except IndexError: except IndexError:
# This is really a hack - happens when using Addon Paths # This is really a hack - happens when using Addon Paths
@ -103,7 +103,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
LOG.debug('Detected deletion of playqueue element at pos %s', i) LOG.debug('Detected deletion of playqueue element at pos %s', i)
try: try:
playqueue.plex_remove_item(i) playqueue.plex_remove_item(i)
except PlaylistError: except PlayqueueError:
LOG.error('Could not delete PMS element from position %s', i) LOG.error('Could not delete PMS element from position %s', i)
LOG.error('This is likely caused by mixing audio and ' LOG.error('This is likely caused by mixing audio and '
'video tracks in the Kodi playqueue') 'video tracks in the Kodi playqueue')

View file

@ -1,13 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""
Monitors the Kodi playqueue and adjusts the Plex playqueue accordingly
"""
from __future__ import absolute_import, division, unicode_literals from __future__ import absolute_import, division, unicode_literals
from logging import getLogger from logging import getLogger
import threading import threading
from .common import PlaylistItem, PlaylistItemDummy, PlaylistError from .common import PlaylistItem, PlaylistItemDummy, PlayqueueError
from ..downloadutils import DownloadUtils as DU from ..downloadutils import DownloadUtils as DU
from ..plex_api import API from ..plex_api import API
@ -157,7 +154,7 @@ class PlayQueue(object):
playlistitem.from_xml(xml[0]) playlistitem.from_xml(xml[0])
except (KeyError, IndexError, TypeError): except (KeyError, IndexError, TypeError):
LOG.error('Could not init Plex playlist with %s', playlistitem) LOG.error('Could not init Plex playlist with %s', playlistitem)
raise PlaylistError() raise PlayqueueError()
self.items.append(playlistitem) self.items.append(playlistitem)
LOG.debug('Initialized the playqueue on the Plex side: %s', self) LOG.debug('Initialized the playqueue on the Plex side: %s', self)
@ -203,7 +200,7 @@ class PlayQueue(object):
self.index = startpos + 1 self.index = startpos + 1
xml = PF.GetPlexMetadata(plex_id) xml = PF.GetPlexMetadata(plex_id)
if xml in (None, 401): if xml in (None, 401):
raise PlaylistError('Could not get Plex metadata %s for %s', raise PlayqueueError('Could not get Plex metadata %s for %s',
plex_id, self.items[startpos]) plex_id, self.items[startpos])
api = API(xml[0]) api = API(xml[0])
if playlistitem.resume is None: if playlistitem.resume is None:
@ -255,7 +252,7 @@ class PlayQueue(object):
else: else:
xml = PF.GetPlexMetadata(plex_id) xml = PF.GetPlexMetadata(plex_id)
if xml in (None, 401): if xml in (None, 401):
raise PlaylistError('Could not get Plex metadata %s', plex_id) raise PlayqueueError('Could not get Plex metadata %s', plex_id)
section_uuid = xml.get('librarySectionUUID') section_uuid = xml.get('librarySectionUUID')
api = API(xml[0]) api = API(xml[0])
plex_type = api.plex_type() plex_type = api.plex_type()
@ -277,7 +274,7 @@ class PlayQueue(object):
if xml is None: if xml is None:
LOG.error('Could not get playqueue for plex_id %s UUID %s for %s', LOG.error('Could not get playqueue for plex_id %s UUID %s for %s',
plex_id, section_uuid, self) plex_id, section_uuid, self)
raise PlaylistError('Could not get playqueue') raise PlayqueueError('Could not get playqueue')
# See that we add trailers, if they exist in the xml return # See that we add trailers, if they exist in the xml return
self._add_intros(xml) self._add_intros(xml)
# Add the main item after the trailers # Add the main item after the trailers
@ -311,7 +308,7 @@ class PlayQueue(object):
resume = resume_dialog(resume) resume = resume_dialog(resume)
LOG.info('User chose resume: %s', resume) LOG.info('User chose resume: %s', resume)
if resume is None: if resume is None:
raise PlaylistError('User backed out of resume dialog') raise PlayqueueError('User backed out of resume dialog')
app.PLAYSTATE.autoplay = True app.PLAYSTATE.autoplay = True
return resume return resume
@ -374,7 +371,7 @@ class PlayQueue(object):
""" """
Adds a PlaylistItem to both Kodi and Plex at position pos [int] Adds a PlaylistItem to both Kodi and Plex at position pos [int]
Also changes self.items Also changes self.items
Raises PlaylistError Raises PlayqueueError
""" """
self.kodi_add_item(item, pos, listitem) self.kodi_add_item(item, pos, listitem)
self.plex_add_item(item, pos) self.plex_add_item(item, pos)
@ -382,13 +379,13 @@ class PlayQueue(object):
def kodi_add_item(self, item, pos, listitem=None): def kodi_add_item(self, item, pos, listitem=None):
""" """
Adds a PlaylistItem to Kodi only. Will not change self.items Adds a PlaylistItem to Kodi only. Will not change self.items
Raises PlaylistError Raises PlayqueueError
""" """
if not isinstance(item, PlaylistItem): if not isinstance(item, PlaylistItem):
raise PlaylistError('Wrong item %s of type %s received' raise PlayqueueError('Wrong item %s of type %s received'
% (item, type(item))) % (item, type(item)))
if pos > len(self.items): if pos > len(self.items):
raise PlaylistError('Position %s too large for playlist length %s' raise PlayqueueError('Position %s too large for playlist length %s'
% (pos, len(self.items))) % (pos, len(self.items)))
LOG.debug('Adding item to Kodi playlist at position %s: %s', pos, item) LOG.debug('Adding item to Kodi playlist at position %s: %s', pos, item)
if listitem: if listitem:
@ -406,14 +403,14 @@ class PlayQueue(object):
'position': pos, 'position': pos,
'item': {'%sid' % item.kodi_type: item.kodi_id}}) 'item': {'%sid' % item.kodi_type: item.kodi_id}})
if 'error' in answ: if 'error' in answ:
raise PlaylistError('Kodi did not add item to playlist: %s', raise PlayqueueError('Kodi did not add item to playlist: %s',
answ) answ)
else: else:
if item.xml is None: if item.xml is None:
LOG.debug('Need to get metadata for item %s', item) LOG.debug('Need to get metadata for item %s', item)
item.xml = PF.GetPlexMetadata(item.plex_id) item.xml = PF.GetPlexMetadata(item.plex_id)
if item.xml in (None, 401): if item.xml in (None, 401):
raise PlaylistError('Could not get metadata for %s', item) raise PlayqueueError('Could not get metadata for %s', item)
api = API(item.xml[0]) api = API(item.xml[0])
listitem = widgets.get_listitem(item.xml, resume=True) listitem = widgets.get_listitem(item.xml, 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
@ -434,13 +431,13 @@ class PlayQueue(object):
""" """
Adds a new PlaylistItem to the playlist at position pos [int] only on Adds a new PlaylistItem to the playlist at position pos [int] only on
the Plex side of things. Also changes self.items the Plex side of things. Also changes self.items
Raises PlaylistError Raises PlayqueueError
""" """
if not isinstance(item, PlaylistItem) or not item.uri: if not isinstance(item, PlaylistItem) or not item.uri:
raise PlaylistError('Wrong item %s of type %s received' raise PlayqueueError('Wrong item %s of type %s received'
% (item, type(item))) % (item, type(item)))
if pos > len(self.items): if pos > len(self.items):
raise PlaylistError('Position %s too large for playlist length %s' raise PlayqueueError('Position %s too large for playlist length %s'
% (pos, len(self.items))) % (pos, len(self.items)))
LOG.debug('Adding item to Plex playlist at position %s: %s', pos, item) LOG.debug('Adding item to Plex playlist at position %s: %s', pos, item)
url = '{server}/%ss/%s?uri=%s' % (self.kind, self.id, item.uri) url = '{server}/%ss/%s?uri=%s' % (self.kind, self.id, item.uri)
@ -449,14 +446,14 @@ class PlayQueue(object):
try: try:
xml[0].attrib xml[0].attrib
except (TypeError, AttributeError, KeyError, IndexError): except (TypeError, AttributeError, KeyError, IndexError):
raise PlaylistError('Could not add item %s to playlist %s' raise PlayqueueError('Could not add item %s to playlist %s'
% (item, self)) % (item, self))
for actual_pos, xml_video_element in enumerate(xml): for actual_pos, xml_video_element in enumerate(xml):
api = API(xml_video_element) api = API(xml_video_element)
if api.plex_id() == item.plex_id: if api.plex_id() == item.plex_id:
break break
else: else:
raise PlaylistError('Something went wrong - Plex id not found') raise PlayqueueError('Something went wrong - Plex id not found')
item.from_xml(xml[actual_pos]) item.from_xml(xml[actual_pos])
self.items.insert(actual_pos, item) self.items.insert(actual_pos, item)
self.update_details_from_xml(xml) self.update_details_from_xml(xml)
@ -471,7 +468,7 @@ class PlayQueue(object):
LOG.debug('Removing position %s on the Kodi side for %s', pos, self) LOG.debug('Removing position %s on the Kodi side for %s', pos, self)
answ = js.playlist_remove(self.playlistid, pos) answ = js.playlist_remove(self.playlistid, pos)
if 'error' in answ: if 'error' in answ:
raise PlaylistError('Could not remove item: %s' % answ['error']) raise PlayqueueError('Could not remove item: %s' % answ['error'])
def plex_remove_item(self, pos): def plex_remove_item(self, pos):
""" """
@ -490,7 +487,7 @@ class PlayQueue(object):
except IndexError: except IndexError:
LOG.error('Could not delete item at position %s on the Plex side', LOG.error('Could not delete item at position %s on the Plex side',
pos) pos)
raise PlaylistError() raise PlayqueueError()
def plex_move_item(self, before, after): def plex_move_item(self, before, after):
""" """
@ -499,7 +496,7 @@ class PlayQueue(object):
Will also change self.items Will also change self.items
""" """
if before > len(self.items) or after > len(self.items) or after == before: if before > len(self.items) or after > len(self.items) or after == before:
raise PlaylistError('Illegal original position %s and/or desired ' raise PlayqueueError('Illegal original position %s and/or desired '
'position %s for playlist length %s' % 'position %s for playlist length %s' %
(before, after, len(self.items))) (before, after, len(self.items)))
LOG.debug('Moving item from %s to %s on the Plex side for %s', LOG.debug('Moving item from %s to %s on the Plex side for %s',
@ -525,7 +522,7 @@ class PlayQueue(object):
try: try:
xml[0].attrib xml[0].attrib
except (TypeError, IndexError, AttributeError): except (TypeError, IndexError, AttributeError):
raise PlaylistError('Could not move playlist item from %s to %s ' raise PlayqueueError('Could not move playlist item from %s to %s '
'for %s' % (before, after, self)) 'for %s' % (before, after, self))
self.update_details_from_xml(xml) self.update_details_from_xml(xml)
self.items.insert(after, self.items.pop(before)) self.items.insert(after, self.items.pop(before))

View file

@ -50,7 +50,7 @@ def update_playqueue_from_PMS(playqueue,
xml = PQ.get_PMS_playlist(playlist_id=playqueue_id) xml = PQ.get_PMS_playlist(playlist_id=playqueue_id)
if xml is None: if xml is None:
LOG.error('Could now download playqueue %s', playqueue_id) LOG.error('Could now download playqueue %s', playqueue_id)
raise PQ.PlaylistError() raise PQ.PlayqueueError()
app.PLAYSTATE.initiated_by_plex = True app.PLAYSTATE.initiated_by_plex = True
playqueue.init_from_xml(xml, playqueue.init_from_xml(xml,
offset=offset, offset=offset,
@ -81,7 +81,7 @@ class PlexCompanion(backgroundthread.KillableThread):
xml[0].attrib xml[0].attrib
except (AttributeError, IndexError, TypeError): except (AttributeError, IndexError, TypeError):
LOG.error('Could not download Plex metadata for: %s', data) LOG.error('Could not download Plex metadata for: %s', data)
raise PQ.PlaylistError() raise PQ.PlayqueueError()
api = API(xml[0]) api = API(xml[0])
if api.plex_type() == v.PLEX_TYPE_ALBUM: if api.plex_type() == v.PLEX_TYPE_ALBUM:
LOG.debug('Plex music album detected') LOG.debug('Plex music album detected')
@ -90,7 +90,7 @@ class PlexCompanion(backgroundthread.KillableThread):
xml[0].attrib xml[0].attrib
except (TypeError, IndexError, AttributeError): except (TypeError, IndexError, AttributeError):
LOG.error('Could not download the album xml for %s', data) LOG.error('Could not download the album xml for %s', data)
raise PQ.PlaylistError() raise PQ.PlayqueueError()
playqueue = PQ.get_playqueue_from_type('audio') playqueue = PQ.get_playqueue_from_type('audio')
playqueue.init_from_xml(xml, playqueue.init_from_xml(xml,
transient_token=data.get('token')) transient_token=data.get('token'))
@ -99,7 +99,7 @@ class PlexCompanion(backgroundthread.KillableThread):
xml = PF.DownloadChunks('{server}/playQueues/%s' % container_key) xml = PF.DownloadChunks('{server}/playQueues/%s' % container_key)
if xml is None: if xml is None:
LOG.error('Could not get playqueue for %s', data) LOG.error('Could not get playqueue for %s', data)
raise PQ.PlaylistError() raise PQ.PlayqueueError()
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()])
offset = utils.cast(float, data.get('offset')) or None offset = utils.cast(float, data.get('offset')) or None
@ -146,7 +146,7 @@ class PlexCompanion(backgroundthread.KillableThread):
xml[0].attrib xml[0].attrib
except (AttributeError, IndexError, TypeError): except (AttributeError, IndexError, TypeError):
LOG.error('Could not download Plex metadata') LOG.error('Could not download Plex metadata')
raise PQ.PlaylistError() raise PQ.PlayqueueError()
api = API(xml[0]) api = API(xml[0])
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()])
@ -234,7 +234,7 @@ class PlexCompanion(backgroundthread.KillableThread):
self._process_refresh(data) self._process_refresh(data)
elif task['action'] == 'setStreams': elif task['action'] == 'setStreams':
self._process_streams(data) self._process_streams(data)
except PQ.PlaylistError: except PQ.PlayqueueError:
LOG.error('Could not process companion data: %s', data) LOG.error('Could not process companion data: %s', data)
# "Play Error" # "Play Error"
utils.dialog('notification', utils.dialog('notification',