2016-04-01 04:32:40 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import json
|
2016-07-25 13:39:40 +10:00
|
|
|
import logging
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcplugin
|
|
|
|
|
|
|
|
import playutils
|
|
|
|
import playbackutils
|
|
|
|
import embydb_functions as embydb
|
|
|
|
import read_embyserver as embyserver
|
2016-07-25 13:39:40 +10:00
|
|
|
from utils import window, settings, language as lang, kodiSQL
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
2016-04-01 04:32:40 +11:00
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
#################################################################################################
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
class Playlist():
|
2016-04-01 04:32:40 +11:00
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
def __init__(self):
|
2016-04-01 04:32:40 +11:00
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
self.userid = window('emby_currUser')
|
|
|
|
self.server = window('emby_server%s' % self.userid)
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
self.emby = embyserver.Read_EmbyServer()
|
|
|
|
|
|
|
|
|
|
|
|
def playAll(self, itemids, startat):
|
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
embyconn = kodiSQL('emby')
|
2016-04-01 04:32:40 +11:00
|
|
|
embycursor = embyconn.cursor()
|
|
|
|
emby_db = embydb.Embydb_Functions(embycursor)
|
|
|
|
|
|
|
|
player = xbmc.Player()
|
|
|
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
|
|
playlist.clear()
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("---*** PLAY ALL ***---")
|
|
|
|
log.info("Items: %s and start at: %s" % (itemids, startat))
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
started = False
|
|
|
|
window('emby_customplaylist', value="true")
|
|
|
|
|
|
|
|
if startat != 0:
|
|
|
|
# Seek to the starting position
|
|
|
|
window('emby_customplaylist.seektime', str(startat))
|
|
|
|
|
|
|
|
for itemid in itemids:
|
|
|
|
embydb_item = emby_db.getItem_byId(itemid)
|
|
|
|
try:
|
|
|
|
dbid = embydb_item[0]
|
|
|
|
mediatype = embydb_item[4]
|
|
|
|
except TypeError:
|
|
|
|
# Item is not found in our database, add item manually
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("Item was not found in the database, manually adding item.")
|
2016-04-01 04:32:40 +11:00
|
|
|
item = self.emby.getItem(itemid)
|
|
|
|
self.addtoPlaylist_xbmc(playlist, item)
|
|
|
|
else:
|
|
|
|
# Add to playlist
|
|
|
|
self.addtoPlaylist(dbid, mediatype)
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("Adding %s to playlist." % itemid)
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
if not started:
|
|
|
|
started = True
|
|
|
|
player.play(playlist)
|
|
|
|
|
|
|
|
self.verifyPlaylist()
|
|
|
|
embycursor.close()
|
|
|
|
|
|
|
|
def modifyPlaylist(self, itemids):
|
|
|
|
|
2016-06-17 07:24:07 +10:00
|
|
|
embyconn = kodiSQL('emby')
|
2016-04-01 04:32:40 +11:00
|
|
|
embycursor = embyconn.cursor()
|
|
|
|
emby_db = embydb.Embydb_Functions(embycursor)
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("---*** ADD TO PLAYLIST ***---")
|
|
|
|
log.info("Items: %s" % itemids)
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
player = xbmc.Player()
|
|
|
|
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
|
|
|
|
|
|
|
|
for itemid in itemids:
|
|
|
|
embydb_item = emby_db.getItem_byId(itemid)
|
|
|
|
try:
|
|
|
|
dbid = embydb_item[0]
|
|
|
|
mediatype = embydb_item[4]
|
|
|
|
except TypeError:
|
|
|
|
# Item is not found in our database, add item manually
|
|
|
|
item = self.emby.getItem(itemid)
|
|
|
|
self.addtoPlaylist_xbmc(playlist, item)
|
|
|
|
else:
|
|
|
|
# Add to playlist
|
|
|
|
self.addtoPlaylist(dbid, mediatype)
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("Adding %s to playlist." % itemid)
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
self.verifyPlaylist()
|
|
|
|
embycursor.close()
|
|
|
|
return playlist
|
|
|
|
|
|
|
|
def addtoPlaylist(self, dbid=None, mediatype=None, url=None):
|
|
|
|
|
|
|
|
pl = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "Playlist.Add",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'playlistid': 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if dbid is not None:
|
|
|
|
pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
|
|
|
|
else:
|
|
|
|
pl['params']['item'] = {'file': url}
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.debug(xbmc.executeJSONRPC(json.dumps(pl)))
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
def addtoPlaylist_xbmc(self, playlist, item):
|
|
|
|
|
|
|
|
playurl = playutils.PlayUtils(item).getPlayUrl()
|
|
|
|
if not playurl:
|
|
|
|
# Playurl failed
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("Failed to retrieve playurl.")
|
2016-04-01 04:32:40 +11:00
|
|
|
return
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.info("Playurl: %s" % playurl)
|
2016-04-01 04:32:40 +11:00
|
|
|
listitem = xbmcgui.ListItem()
|
|
|
|
playbackutils.PlaybackUtils(item).setProperties(playurl, listitem)
|
|
|
|
|
|
|
|
playlist.add(playurl, listitem)
|
|
|
|
|
|
|
|
def insertintoPlaylist(self, position, dbid=None, mediatype=None, url=None):
|
|
|
|
|
|
|
|
pl = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "Playlist.Insert",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'playlistid': 1,
|
|
|
|
'position': position
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if dbid is not None:
|
|
|
|
pl['params']['item'] = {'%sid' % mediatype: int(dbid)}
|
|
|
|
else:
|
|
|
|
pl['params']['item'] = {'file': url}
|
|
|
|
|
2016-07-25 13:39:40 +10:00
|
|
|
log.debug(xbmc.executeJSONRPC(json.dumps(pl)))
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
def verifyPlaylist(self):
|
|
|
|
|
|
|
|
pl = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "Playlist.GetItems",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'playlistid': 1
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 13:39:40 +10:00
|
|
|
log.debug(xbmc.executeJSONRPC(json.dumps(pl)))
|
2016-04-01 04:32:40 +11:00
|
|
|
|
|
|
|
def removefromPlaylist(self, position):
|
|
|
|
|
|
|
|
pl = {
|
|
|
|
|
|
|
|
'jsonrpc': "2.0",
|
|
|
|
'id': 1,
|
|
|
|
'method': "Playlist.Remove",
|
|
|
|
'params': {
|
|
|
|
|
|
|
|
'playlistid': 1,
|
|
|
|
'position': position
|
|
|
|
}
|
|
|
|
}
|
2016-07-25 13:39:40 +10:00
|
|
|
log.debug(xbmc.executeJSONRPC(json.dumps(pl)))
|