Code cleanup
This commit is contained in:
parent
d8a7218625
commit
dec4b077d5
1 changed files with 22 additions and 17 deletions
|
@ -21,18 +21,22 @@ class Playlist():
|
||||||
"""
|
"""
|
||||||
Initiate with Playlist(typus='video' or 'music')
|
Initiate with Playlist(typus='video' or 'music')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, typus=None):
|
def __init__(self, typus=None):
|
||||||
self.userid = utils.window('currUserId')
|
self.userid = utils.window('currUserId')
|
||||||
self.server = utils.window('pms_server')
|
self.server = utils.window('pms_server')
|
||||||
if typus == 'video':
|
if typus == 'video':
|
||||||
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
||||||
|
self.logMsg('Initiated video playlist', 1)
|
||||||
elif typus == 'music':
|
elif typus == 'music':
|
||||||
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
|
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
|
||||||
|
self.logMsg('Initiated music playlist', 1)
|
||||||
else:
|
else:
|
||||||
self.playlist = None
|
self.playlist = None
|
||||||
|
if self.playlist is not None:
|
||||||
|
self.playlistId = self.playlist.getPlayListId()
|
||||||
|
|
||||||
def __initiatePlaylist(self, itemids):
|
def _initiatePlaylist(self, itemids):
|
||||||
|
self.logMsg('Initiating playlist', 1)
|
||||||
playlist = None
|
playlist = None
|
||||||
with embydb.GetEmbyDB() as emby_db:
|
with embydb.GetEmbyDB() as emby_db:
|
||||||
for itemid in itemids:
|
for itemid in itemids:
|
||||||
|
@ -40,9 +44,12 @@ class Playlist():
|
||||||
try:
|
try:
|
||||||
mediatype = embydb_item[4]
|
mediatype = embydb_item[4]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
self.logMsg('Couldnt find item %s in Kodi db' % itemid, 1)
|
self.logMsg('Couldnt find item %s in Kodi db'
|
||||||
|
% itemid, 1)
|
||||||
item = PlexFunctions.GetPlexMetadata(itemid)
|
item = PlexFunctions.GetPlexMetadata(itemid)
|
||||||
if item in (None, 401):
|
if item in (None, 401):
|
||||||
|
self.logMsg('Couldnt find item %s on PMS, trying next'
|
||||||
|
% itemid, 1)
|
||||||
continue
|
continue
|
||||||
if PlexAPI.API(item[0]).getType() == 'track':
|
if PlexAPI.API(item[0]).getType() == 'track':
|
||||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
|
||||||
|
@ -58,9 +65,9 @@ class Playlist():
|
||||||
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
||||||
self.logMsg('Video playlist initiated', 1)
|
self.logMsg('Video playlist initiated', 1)
|
||||||
break
|
break
|
||||||
if playlist is not None:
|
|
||||||
playlist.clear()
|
|
||||||
self.playlist = playlist
|
self.playlist = playlist
|
||||||
|
if self.playlist is not None:
|
||||||
|
self.playlistId = self.playlist.getPlayListId()
|
||||||
|
|
||||||
def _addToPlaylist(self, itemids, startPlayer=False):
|
def _addToPlaylist(self, itemids, startPlayer=False):
|
||||||
started = False
|
started = False
|
||||||
|
@ -78,7 +85,7 @@ class Playlist():
|
||||||
% itemid, -1)
|
% itemid, -1)
|
||||||
else:
|
else:
|
||||||
self.logMsg('Downloaded item metadata, adding now', 1)
|
self.logMsg('Downloaded item metadata, adding now', 1)
|
||||||
self.addtoPlaylist_xbmc(item)
|
self._addtoPlaylist_xbmc(item[0])
|
||||||
else:
|
else:
|
||||||
# Add to playlist
|
# Add to playlist
|
||||||
self.logMsg("Adding %s PlexId %s, KodiId %s to playlist."
|
self.logMsg("Adding %s PlexId %s, KodiId %s to playlist."
|
||||||
|
@ -93,7 +100,7 @@ class Playlist():
|
||||||
self.logMsg("Items: %s and start at: %s" % (itemids, startat), 1)
|
self.logMsg("Items: %s and start at: %s" % (itemids, startat), 1)
|
||||||
|
|
||||||
if self.playlist is None:
|
if self.playlist is None:
|
||||||
self.__initiatePlaylist(itemids)
|
self._initiatePlaylist(itemids)
|
||||||
if self.playlist is None:
|
if self.playlist is None:
|
||||||
self.logMsg('Could not create playlist, abort', -1)
|
self.logMsg('Could not create playlist, abort', -1)
|
||||||
return
|
return
|
||||||
|
@ -109,7 +116,7 @@ class Playlist():
|
||||||
self.logMsg("---*** ADD TO PLAYLIST ***---", 1)
|
self.logMsg("---*** ADD TO PLAYLIST ***---", 1)
|
||||||
self.logMsg("Items: %s" % itemids, 1)
|
self.logMsg("Items: %s" % itemids, 1)
|
||||||
|
|
||||||
self.__initiatePlaylist(itemids)
|
self._initiatePlaylist(itemids)
|
||||||
self._addToPlaylist(itemids, startPlayer=True)
|
self._addToPlaylist(itemids, startPlayer=True)
|
||||||
|
|
||||||
self.verifyPlaylist()
|
self.verifyPlaylist()
|
||||||
|
@ -121,13 +128,11 @@ class Playlist():
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pl = {
|
pl = {
|
||||||
|
|
||||||
'jsonrpc': "2.0",
|
'jsonrpc': "2.0",
|
||||||
'id': 1,
|
'id': 1,
|
||||||
'method': "Playlist.Add",
|
'method': "Playlist.Add",
|
||||||
'params': {
|
'params': {
|
||||||
|
'playlistid': self.playlistId
|
||||||
'playlistid': self.playlist.getPlayListId()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if dbid is not None:
|
if dbid is not None:
|
||||||
|
@ -138,8 +143,8 @@ class Playlist():
|
||||||
self.logMsg('JSONRPC question: %s' % json.dumps(pl), 2)
|
self.logMsg('JSONRPC question: %s' % json.dumps(pl), 2)
|
||||||
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2)
|
self.logMsg(xbmc.executeJSONRPC(json.dumps(pl)), 2)
|
||||||
|
|
||||||
def addtoPlaylist_xbmc(self, item):
|
def _addtoPlaylist_xbmc(self, item):
|
||||||
API = PlexAPI.API(item[0])
|
API = PlexAPI.API(item)
|
||||||
params = {
|
params = {
|
||||||
'mode': "play",
|
'mode': "play",
|
||||||
'dbid': 999999999,
|
'dbid': 999999999,
|
||||||
|
@ -150,7 +155,7 @@ class Playlist():
|
||||||
% urlencode(params)
|
% urlencode(params)
|
||||||
|
|
||||||
listitem = API.CreateListItemFromPlexItem()
|
listitem = API.CreateListItemFromPlexItem()
|
||||||
playbackutils.PlaybackUtils(item[0]).setArtwork(listitem)
|
playbackutils.PlaybackUtils(item).setArtwork(listitem)
|
||||||
|
|
||||||
self.playlist.add(playurl, listitem)
|
self.playlist.add(playurl, listitem)
|
||||||
|
|
||||||
|
@ -163,7 +168,7 @@ class Playlist():
|
||||||
'method': "Playlist.Insert",
|
'method': "Playlist.Insert",
|
||||||
'params': {
|
'params': {
|
||||||
|
|
||||||
'playlistid': self.playlist.getPlayListId(),
|
'playlistid': self.playlistId,
|
||||||
'position': position
|
'position': position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,7 +189,7 @@ class Playlist():
|
||||||
'method': "Playlist.GetItems",
|
'method': "Playlist.GetItems",
|
||||||
'params': {
|
'params': {
|
||||||
|
|
||||||
'playlistid': self.playlist.getPlayListId(),
|
'playlistid': self.playlistId,
|
||||||
'properties': ['title', 'file']
|
'properties': ['title', 'file']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +204,7 @@ class Playlist():
|
||||||
'method': "Playlist.Remove",
|
'method': "Playlist.Remove",
|
||||||
'params': {
|
'params': {
|
||||||
|
|
||||||
'playlistid': self.playlist.getPlayListId(),
|
'playlistid': self.playlistId,
|
||||||
'position': position
|
'position': position
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue