Rename to PlayqueueError
This commit is contained in:
parent
3d4bde878e
commit
d3752e1958
5 changed files with 33 additions and 36 deletions
|
@ -5,7 +5,7 @@ Monitors the Kodi playqueue and adjusts the Plex playqueue accordingly
|
|||
"""
|
||||
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 .monitor import PlayqueueMonitor
|
||||
from .functions import init_playqueues, get_playqueue_from_type, \
|
||||
|
|
|
@ -10,7 +10,7 @@ from .. import plex_functions as PF, utils, kodi_db, variables as v, app
|
|||
PLAYQUEUES = []
|
||||
|
||||
|
||||
class PlaylistError(Exception):
|
||||
class PlayqueueError(Exception):
|
||||
"""
|
||||
Exception for our playlist constructs
|
||||
"""
|
||||
|
|
|
@ -7,7 +7,7 @@ from __future__ import absolute_import, division, unicode_literals
|
|||
from logging import getLogger
|
||||
import copy
|
||||
|
||||
from .common import PlaylistError, PlaylistItem, PLAYQUEUES
|
||||
from .common import PlayqueueError, PlaylistItem, PLAYQUEUES
|
||||
from .. import backgroundthread, json_rpc as js, utils, app
|
||||
|
||||
|
||||
|
@ -68,7 +68,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
|
|||
i + j, i)
|
||||
try:
|
||||
playqueue.plex_move_item(i + j, i)
|
||||
except PlaylistError:
|
||||
except PlayqueueError:
|
||||
LOG.error('Could not modify playqueue positions')
|
||||
LOG.error('This is likely caused by mixing audio and '
|
||||
'video tracks in the Kodi playqueue')
|
||||
|
@ -83,7 +83,7 @@ class PlayqueueMonitor(backgroundthread.KillableThread):
|
|||
playqueue.init(playlistitem)
|
||||
else:
|
||||
playqueue.plex_add_item(playlistitem, i)
|
||||
except PlaylistError:
|
||||
except PlayqueueError:
|
||||
LOG.warn('Couldnt add new item to Plex: %s', playlistitem)
|
||||
except IndexError:
|
||||
# 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)
|
||||
try:
|
||||
playqueue.plex_remove_item(i)
|
||||
except PlaylistError:
|
||||
except PlayqueueError:
|
||||
LOG.error('Could not delete PMS element from position %s', i)
|
||||
LOG.error('This is likely caused by mixing audio and '
|
||||
'video tracks in the Kodi playqueue')
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Monitors the Kodi playqueue and adjusts the Plex playqueue accordingly
|
||||
"""
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
from logging import getLogger
|
||||
import threading
|
||||
|
||||
from .common import PlaylistItem, PlaylistItemDummy, PlaylistError
|
||||
from .common import PlaylistItem, PlaylistItemDummy, PlayqueueError
|
||||
|
||||
from ..downloadutils import DownloadUtils as DU
|
||||
from ..plex_api import API
|
||||
|
@ -157,7 +154,7 @@ class PlayQueue(object):
|
|||
playlistitem.from_xml(xml[0])
|
||||
except (KeyError, IndexError, TypeError):
|
||||
LOG.error('Could not init Plex playlist with %s', playlistitem)
|
||||
raise PlaylistError()
|
||||
raise PlayqueueError()
|
||||
self.items.append(playlistitem)
|
||||
LOG.debug('Initialized the playqueue on the Plex side: %s', self)
|
||||
|
||||
|
@ -203,7 +200,7 @@ class PlayQueue(object):
|
|||
self.index = startpos + 1
|
||||
xml = PF.GetPlexMetadata(plex_id)
|
||||
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])
|
||||
api = API(xml[0])
|
||||
if playlistitem.resume is None:
|
||||
|
@ -255,7 +252,7 @@ class PlayQueue(object):
|
|||
else:
|
||||
xml = PF.GetPlexMetadata(plex_id)
|
||||
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')
|
||||
api = API(xml[0])
|
||||
plex_type = api.plex_type()
|
||||
|
@ -277,7 +274,7 @@ class PlayQueue(object):
|
|||
if xml is None:
|
||||
LOG.error('Could not get playqueue for plex_id %s UUID %s for %s',
|
||||
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
|
||||
self._add_intros(xml)
|
||||
# Add the main item after the trailers
|
||||
|
@ -311,7 +308,7 @@ class PlayQueue(object):
|
|||
resume = resume_dialog(resume)
|
||||
LOG.info('User chose resume: %s', resume)
|
||||
if resume is None:
|
||||
raise PlaylistError('User backed out of resume dialog')
|
||||
raise PlayqueueError('User backed out of resume dialog')
|
||||
app.PLAYSTATE.autoplay = True
|
||||
return resume
|
||||
|
||||
|
@ -374,7 +371,7 @@ class PlayQueue(object):
|
|||
"""
|
||||
Adds a PlaylistItem to both Kodi and Plex at position pos [int]
|
||||
Also changes self.items
|
||||
Raises PlaylistError
|
||||
Raises PlayqueueError
|
||||
"""
|
||||
self.kodi_add_item(item, pos, listitem)
|
||||
self.plex_add_item(item, pos)
|
||||
|
@ -382,13 +379,13 @@ class PlayQueue(object):
|
|||
def kodi_add_item(self, item, pos, listitem=None):
|
||||
"""
|
||||
Adds a PlaylistItem to Kodi only. Will not change self.items
|
||||
Raises PlaylistError
|
||||
Raises PlayqueueError
|
||||
"""
|
||||
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)))
|
||||
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)))
|
||||
LOG.debug('Adding item to Kodi playlist at position %s: %s', pos, item)
|
||||
if listitem:
|
||||
|
@ -406,14 +403,14 @@ class PlayQueue(object):
|
|||
'position': pos,
|
||||
'item': {'%sid' % item.kodi_type: item.kodi_id}})
|
||||
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)
|
||||
else:
|
||||
if item.xml is None:
|
||||
LOG.debug('Need to get metadata for item %s', item)
|
||||
item.xml = PF.GetPlexMetadata(item.plex_id)
|
||||
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])
|
||||
listitem = widgets.get_listitem(item.xml, resume=True)
|
||||
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
|
||||
the Plex side of things. Also changes self.items
|
||||
Raises PlaylistError
|
||||
Raises PlayqueueError
|
||||
"""
|
||||
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)))
|
||||
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)))
|
||||
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)
|
||||
|
@ -449,14 +446,14 @@ class PlayQueue(object):
|
|||
try:
|
||||
xml[0].attrib
|
||||
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))
|
||||
for actual_pos, xml_video_element in enumerate(xml):
|
||||
api = API(xml_video_element)
|
||||
if api.plex_id() == item.plex_id:
|
||||
break
|
||||
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])
|
||||
self.items.insert(actual_pos, item)
|
||||
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)
|
||||
answ = js.playlist_remove(self.playlistid, pos)
|
||||
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):
|
||||
"""
|
||||
|
@ -490,7 +487,7 @@ class PlayQueue(object):
|
|||
except IndexError:
|
||||
LOG.error('Could not delete item at position %s on the Plex side',
|
||||
pos)
|
||||
raise PlaylistError()
|
||||
raise PlayqueueError()
|
||||
|
||||
def plex_move_item(self, before, after):
|
||||
"""
|
||||
|
@ -499,7 +496,7 @@ class PlayQueue(object):
|
|||
Will also change self.items
|
||||
"""
|
||||
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' %
|
||||
(before, after, len(self.items)))
|
||||
LOG.debug('Moving item from %s to %s on the Plex side for %s',
|
||||
|
@ -525,7 +522,7 @@ class PlayQueue(object):
|
|||
try:
|
||||
xml[0].attrib
|
||||
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))
|
||||
self.update_details_from_xml(xml)
|
||||
self.items.insert(after, self.items.pop(before))
|
||||
|
|
|
@ -50,7 +50,7 @@ def update_playqueue_from_PMS(playqueue,
|
|||
xml = PQ.get_PMS_playlist(playlist_id=playqueue_id)
|
||||
if xml is None:
|
||||
LOG.error('Could now download playqueue %s', playqueue_id)
|
||||
raise PQ.PlaylistError()
|
||||
raise PQ.PlayqueueError()
|
||||
app.PLAYSTATE.initiated_by_plex = True
|
||||
playqueue.init_from_xml(xml,
|
||||
offset=offset,
|
||||
|
@ -81,7 +81,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
|||
xml[0].attrib
|
||||
except (AttributeError, IndexError, TypeError):
|
||||
LOG.error('Could not download Plex metadata for: %s', data)
|
||||
raise PQ.PlaylistError()
|
||||
raise PQ.PlayqueueError()
|
||||
api = API(xml[0])
|
||||
if api.plex_type() == v.PLEX_TYPE_ALBUM:
|
||||
LOG.debug('Plex music album detected')
|
||||
|
@ -90,7 +90,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
|||
xml[0].attrib
|
||||
except (TypeError, IndexError, AttributeError):
|
||||
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.init_from_xml(xml,
|
||||
transient_token=data.get('token'))
|
||||
|
@ -99,7 +99,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
|||
xml = PF.DownloadChunks('{server}/playQueues/%s' % container_key)
|
||||
if xml is None:
|
||||
LOG.error('Could not get playqueue for %s', data)
|
||||
raise PQ.PlaylistError()
|
||||
raise PQ.PlayqueueError()
|
||||
playqueue = PQ.get_playqueue_from_type(
|
||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.plex_type()])
|
||||
offset = utils.cast(float, data.get('offset')) or None
|
||||
|
@ -146,7 +146,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
|||
xml[0].attrib
|
||||
except (AttributeError, IndexError, TypeError):
|
||||
LOG.error('Could not download Plex metadata')
|
||||
raise PQ.PlaylistError()
|
||||
raise PQ.PlayqueueError()
|
||||
api = API(xml[0])
|
||||
playqueue = PQ.get_playqueue_from_type(
|
||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[api.plex_type()])
|
||||
|
@ -234,7 +234,7 @@ class PlexCompanion(backgroundthread.KillableThread):
|
|||
self._process_refresh(data)
|
||||
elif task['action'] == 'setStreams':
|
||||
self._process_streams(data)
|
||||
except PQ.PlaylistError:
|
||||
except PQ.PlayqueueError:
|
||||
LOG.error('Could not process companion data: %s', data)
|
||||
# "Play Error"
|
||||
utils.dialog('notification',
|
||||
|
|
Loading…
Reference in a new issue