This commit is contained in:
SpootDev 2016-03-31 12:32:40 -05:00
parent 16f3bbf3e4
commit 60b53bddf1

View file

@ -1,204 +1,201 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
################################################################################################# #################################################################################################
import json import json
import xbmc import xbmc
import xbmcgui import xbmcgui
import xbmcplugin import xbmcplugin
import clientinfo import clientinfo
import playutils import playutils
import playbackutils import playbackutils
import embydb_functions as embydb import embydb_functions as embydb
import read_embyserver as embyserver import read_embyserver as embyserver
import utils import utils
################################################################################################# #################################################################################################
class Playlist(): class Playlist():
def __init__(self): def __init__(self):
self.clientInfo = clientinfo.ClientInfo() self.clientInfo = clientinfo.ClientInfo()
self.addonName = self.clientInfo.getAddonName() self.addonName = self.clientInfo.getAddonName()
self.userid = utils.window('emby_currUser') self.userid = utils.window('emby_currUser')
self.server = utils.window('emby_server%s' % self.userid) self.server = utils.window('emby_server%s' % self.userid)
self.emby = embyserver.Read_EmbyServer() self.emby = embyserver.Read_EmbyServer()
def logMsg(self, msg, lvl=1): def logMsg(self, msg, lvl=1):
self.className = self.__class__.__name__ self.className = self.__class__.__name__
utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl) utils.logMsg("%s %s" % (self.addonName, self.className), msg, lvl)
def playAll(self, itemids, startat): def playAll(self, itemids, startat):
log = self.logMsg window = utils.window
window = utils.window
embyconn = utils.kodiSQL('emby')
embyconn = utils.kodiSQL('emby') embycursor = embyconn.cursor()
embycursor = embyconn.cursor() emby_db = embydb.Embydb_Functions(embycursor)
emby_db = embydb.Embydb_Functions(embycursor)
player = xbmc.Player()
player = xbmc.Player() playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) playlist.clear()
playlist.clear()
self.logMsg("---*** PLAY ALL ***---", 1)
log("---*** PLAY ALL ***---", 1) self.logMsg("Items: %s and start at: %s" % (itemids, startat), 1)
log("Items: %s and start at: %s" % (itemids, startat), 1)
started = False
started = False window('emby_customplaylist', value="true")
window('emby_customplaylist', value="true")
if startat != 0:
if startat != 0: # Seek to the starting position
# Seek to the starting position window('emby_customplaylist.seektime', str(startat))
window('emby_customplaylist.seektime', str(startat))
for itemid in itemids:
for itemid in itemids: embydb_item = emby_db.getItem_byId(itemid)
embydb_item = emby_db.getItem_byId(itemid) try:
try: dbid = embydb_item[0]
dbid = embydb_item[0] mediatype = embydb_item[4]
mediatype = embydb_item[4] except TypeError:
except TypeError: # Item is not found in our database, add item manually
# Item is not found in our database, add item manually self.logMsg("Item was not found in the database, manually adding item.", 1)
log("Item was not found in the database, manually adding item.", 1) item = self.emby.getItem(itemid)
item = self.emby.getItem(itemid) self.addtoPlaylist_xbmc(playlist, item)
self.addtoPlaylist_xbmc(playlist, item) else:
else: # Add to playlist
# Add to playlist self.addtoPlaylist(dbid, mediatype)
self.addtoPlaylist(dbid, mediatype)
self.logMsg("Adding %s to playlist." % itemid, 1)
log("Adding %s to playlist." % itemid, 1)
if not started:
if not started: started = True
started = True player.play(playlist)
player.play(playlist)
self.verifyPlaylist()
self.verifyPlaylist() embycursor.close()
embycursor.close()
def modifyPlaylist(self, itemids):
def modifyPlaylist(self, itemids):
embyconn = utils.kodiSQL('emby')
log = self.logMsg embycursor = embyconn.cursor()
emby_db = embydb.Embydb_Functions(embycursor)
embyconn = utils.kodiSQL('emby')
embycursor = embyconn.cursor() self.logMsg("---*** ADD TO PLAYLIST ***---", 1)
emby_db = embydb.Embydb_Functions(embycursor) self.logMsg("Items: %s" % itemids, 1)
log("---*** ADD TO PLAYLIST ***---", 1) player = xbmc.Player()
log("Items: %s" % itemids, 1) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
player = xbmc.Player() for itemid in itemids:
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) embydb_item = emby_db.getItem_byId(itemid)
try:
for itemid in itemids: dbid = embydb_item[0]
embydb_item = emby_db.getItem_byId(itemid) mediatype = embydb_item[4]
try: except TypeError:
dbid = embydb_item[0] # Item is not found in our database, add item manually
mediatype = embydb_item[4] item = self.emby.getItem(itemid)
except TypeError: self.addtoPlaylist_xbmc(playlist, item)
# Item is not found in our database, add item manually else:
item = self.emby.getItem(itemid) # Add to playlist
self.addtoPlaylist_xbmc(playlist, item) self.addtoPlaylist(dbid, mediatype)
else:
# Add to playlist self.logMsg("Adding %s to playlist." % itemid, 1)
self.addtoPlaylist(dbid, mediatype)
self.verifyPlaylist()
log("Adding %s to playlist." % itemid, 1) embycursor.close()
return playlist
self.verifyPlaylist()
embycursor.close() def addtoPlaylist(self, dbid=None, mediatype=None, url=None):
return playlist
pl = {
def addtoPlaylist(self, dbid=None, mediatype=None, url=None):
'jsonrpc': "2.0",
pl = { 'id': 1,
'method': "Playlist.Add",
'jsonrpc': "2.0", 'params': {
'id': 1,
'method': "Playlist.Add", 'playlistid': 1
'params': { }
}
'playlistid': 1 if dbid is not None:
} pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
} else:
if dbid is not None: pl['params']['item'] = {'file': url}
pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
else: result = xbmc.executeJSONRPC(json.dumps(pl))
pl['params']['item'] = {'file': url} self.logMsg(result, 2)
result = xbmc.executeJSONRPC(json.dumps(pl)) def addtoPlaylist_xbmc(self, playlist, item):
self.logMsg(result, 2)
itemid = item['Id']
def addtoPlaylist_xbmc(self, playlist, item): playurl = playutils.PlayUtils(item).getPlayUrl()
if not playurl:
itemid = item['Id'] # Playurl failed
playurl = playutils.PlayUtils(item).getPlayUrl() self.logMsg("Failed to retrieve playurl.", 1)
if not playurl: return
# Playurl failed
self.logMsg("Failed to retrieve playurl.", 1) self.logMsg("Playurl: %s" % playurl)
return listitem = xbmcgui.ListItem()
playbackutils.PlaybackUtils(item).setProperties(playurl, listitem)
self.logMsg("Playurl: %s" % playurl)
listitem = xbmcgui.ListItem() playlist.add(playurl, listitem)
playbackutils.PlaybackUtils(item).setProperties(playurl, listitem)
def insertintoPlaylist(self, position, dbid=None, mediatype=None, url=None):
playlist.add(playurl, listitem)
pl = {
def insertintoPlaylist(self, position, dbid=None, mediatype=None, url=None):
'jsonrpc': "2.0",
pl = { 'id': 1,
'method': "Playlist.Insert",
'jsonrpc': "2.0", 'params': {
'id': 1,
'method': "Playlist.Insert", 'playlistid': 1,
'params': { 'position': position
}
'playlistid': 1, }
'position': position if dbid is not None:
} pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
} else:
if dbid is not None: pl['params']['item'] = {'file': url}
pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
else: result = xbmc.executeJSONRPC(json.dumps(pl))
pl['params']['item'] = {'file': url} self.logMsg(result, 2)
result = xbmc.executeJSONRPC(json.dumps(pl)) def verifyPlaylist(self):
self.logMsg(result, 2)
pl = {
def verifyPlaylist(self):
'jsonrpc': "2.0",
pl = { 'id': 1,
'method': "Playlist.GetItems",
'jsonrpc': "2.0", 'params': {
'id': 1,
'method': "Playlist.GetItems", 'playlistid': 1
'params': { }
}
'playlistid': 1 result = xbmc.executeJSONRPC(json.dumps(pl))
} self.logMsg(result, 2)
}
result = xbmc.executeJSONRPC(json.dumps(pl)) def removefromPlaylist(self, position):
self.logMsg(result, 2)
pl = {
def removefromPlaylist(self, position):
'jsonrpc': "2.0",
pl = { 'id': 1,
'method': "Playlist.Remove",
'jsonrpc': "2.0", 'params': {
'id': 1,
'method': "Playlist.Remove", 'playlistid': 1,
'params': { 'position': position
}
'playlistid': 1, }
'position': position result = xbmc.executeJSONRPC(json.dumps(pl))
}
}
result = xbmc.executeJSONRPC(json.dumps(pl))
self.logMsg(result, 2) self.logMsg(result, 2)