2015-03-14 08:24:59 +11:00
|
|
|
#################################################################################################
|
|
|
|
# utils
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcgui
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
import json
|
|
|
|
import os
|
2015-03-20 10:48:59 +11:00
|
|
|
import cProfile
|
|
|
|
import pstats
|
|
|
|
import time
|
2015-03-14 08:24:59 +11:00
|
|
|
import inspect
|
2015-03-27 22:20:40 +11:00
|
|
|
import sqlite3
|
2015-03-30 09:43:53 +11:00
|
|
|
import string
|
|
|
|
import unicodedata
|
2015-03-14 08:24:59 +11:00
|
|
|
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
|
|
|
|
from xml.etree import ElementTree
|
|
|
|
from xml.dom import minidom
|
|
|
|
import xml.etree.cElementTree as ET
|
|
|
|
|
|
|
|
from API import API
|
|
|
|
from PlayUtils import PlayUtils
|
|
|
|
from DownloadUtils import DownloadUtils
|
|
|
|
downloadUtils = DownloadUtils()
|
2015-03-26 04:37:21 +11:00
|
|
|
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
|
2015-03-23 22:30:03 +11:00
|
|
|
language = addonSettings.getLocalizedString
|
2015-03-27 08:35:11 +11:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
|
|
|
|
def logMsg(title, msg, level = 1):
|
2015-03-19 07:34:52 +11:00
|
|
|
logLevel = int(addonSettings.getSetting("logLevel"))
|
2015-04-29 08:23:26 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
|
|
|
WINDOW.setProperty('logLevel', str(logLevel))
|
2015-03-14 08:24:59 +11:00
|
|
|
if(logLevel >= level):
|
2015-03-20 10:48:59 +11:00
|
|
|
if(logLevel == 2): # inspect.stack() is expensive
|
2015-03-14 08:24:59 +11:00
|
|
|
try:
|
|
|
|
xbmc.log(title + " -> " + inspect.stack()[1][3] + " : " + str(msg))
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
xbmc.log(title + " -> " + inspect.stack()[1][3] + " : " + str(msg.encode('utf-8')))
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
xbmc.log(title + " -> " + str(msg))
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
xbmc.log(title + " -> " + str(msg.encode('utf-8')))
|
2015-03-17 08:31:32 +11:00
|
|
|
|
|
|
|
def convertEncoding(data):
|
|
|
|
#nasty hack to make sure we have a unicode string
|
|
|
|
try:
|
|
|
|
return data.decode('utf-8')
|
|
|
|
except:
|
|
|
|
return data
|
|
|
|
|
2015-03-27 08:35:11 +11:00
|
|
|
def KodiSQL():
|
2015-04-03 20:58:21 +11:00
|
|
|
connection = sqlite3.connect(getKodiDBPath())
|
2015-05-01 21:30:21 +10:00
|
|
|
|
2015-04-03 20:58:21 +11:00
|
|
|
return connection
|
|
|
|
|
|
|
|
def getKodiDBPath():
|
2015-03-27 11:24:49 +11:00
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("13"):
|
2015-03-27 08:35:11 +11:00
|
|
|
#gotham
|
|
|
|
dbVersion = "78"
|
2015-03-27 11:24:49 +11:00
|
|
|
if xbmc.getInfoLabel("System.BuildVersion").startswith("15"):
|
2015-03-27 08:35:11 +11:00
|
|
|
#isengard
|
2015-05-02 06:14:00 +10:00
|
|
|
dbVersion = "92"
|
2015-03-27 08:35:11 +11:00
|
|
|
else:
|
|
|
|
#helix
|
|
|
|
dbVersion = "90"
|
|
|
|
|
2015-04-08 11:09:17 +10:00
|
|
|
dbPath = xbmc.translatePath("special://profile/Database/MyVideos" + dbVersion + ".db")
|
2015-04-03 20:58:21 +11:00
|
|
|
|
|
|
|
return dbPath
|
2015-03-27 11:24:49 +11:00
|
|
|
|
2015-03-14 08:24:59 +11:00
|
|
|
def checkAuthentication():
|
|
|
|
#check authentication
|
|
|
|
if addonSettings.getSetting('username') != "" and addonSettings.getSetting('ipaddress') != "":
|
|
|
|
try:
|
|
|
|
downloadUtils.authenticate()
|
|
|
|
except Exception, e:
|
2015-04-03 06:47:06 +11:00
|
|
|
logMsg("Emby authentication failed",e)
|
2015-03-14 08:24:59 +11:00
|
|
|
pass
|
|
|
|
|
|
|
|
def prettifyXml(elem):
|
|
|
|
rough_string = etree.tostring(elem, "utf-8")
|
|
|
|
reparsed = minidom.parseString(rough_string)
|
|
|
|
return reparsed.toprettyxml(indent="\t")
|
|
|
|
|
|
|
|
def get_params( paramstring ):
|
|
|
|
xbmc.log("Parameter string: " + paramstring)
|
|
|
|
param={}
|
|
|
|
if len(paramstring)>=2:
|
|
|
|
params=paramstring
|
|
|
|
|
|
|
|
if params[0] == "?":
|
|
|
|
cleanedparams=params[1:]
|
|
|
|
else:
|
|
|
|
cleanedparams=params
|
|
|
|
|
|
|
|
if (params[len(params)-1]=='/'):
|
|
|
|
params=params[0:len(params)-2]
|
|
|
|
|
|
|
|
pairsofparams=cleanedparams.split('&')
|
|
|
|
for i in range(len(pairsofparams)):
|
|
|
|
splitparams={}
|
|
|
|
splitparams=pairsofparams[i].split('=')
|
|
|
|
if (len(splitparams))==2:
|
|
|
|
param[splitparams[0]]=splitparams[1]
|
|
|
|
elif (len(splitparams))==3:
|
|
|
|
param[splitparams[0]]=splitparams[1]+"="+splitparams[2]
|
|
|
|
return param
|
|
|
|
|
2015-03-20 10:48:59 +11:00
|
|
|
def startProfiling():
|
|
|
|
pr = cProfile.Profile()
|
|
|
|
pr.enable()
|
|
|
|
return pr
|
|
|
|
|
|
|
|
def stopProfiling(pr, profileName):
|
|
|
|
pr.disable()
|
|
|
|
ps = pstats.Stats(pr)
|
|
|
|
|
2015-03-26 04:37:21 +11:00
|
|
|
addondir = xbmc.translatePath(xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('profile'))
|
2015-03-20 10:48:59 +11:00
|
|
|
|
|
|
|
fileTimeStamp = time.strftime("%Y-%m-%d %H-%M-%S")
|
|
|
|
tabFileNamepath = os.path.join(addondir, "profiles")
|
|
|
|
tabFileName = os.path.join(addondir, "profiles" , profileName + "_profile_(" + fileTimeStamp + ").tab")
|
|
|
|
|
|
|
|
if not xbmcvfs.exists(tabFileNamepath):
|
|
|
|
xbmcvfs.mkdir(tabFileNamepath)
|
|
|
|
|
|
|
|
f = open(tabFileName, 'wb')
|
|
|
|
f.write("NumbCalls\tTotalTime\tCumulativeTime\tFunctionName\tFileName\r\n")
|
|
|
|
for (key, value) in ps.stats.items():
|
|
|
|
(filename, count, func_name) = key
|
|
|
|
(ccalls, ncalls, total_time, cumulative_time, callers) = value
|
|
|
|
try:
|
|
|
|
f.write(str(ncalls) + "\t" + "{:10.4f}".format(total_time) + "\t" + "{:10.4f}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
|
|
|
|
except ValueError:
|
|
|
|
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
|
|
|
|
f.close()
|
|
|
|
|
2015-03-30 09:43:53 +11:00
|
|
|
def CleanName(filename):
|
|
|
|
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
|
|
|
cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')
|
|
|
|
return ''.join(c for c in cleanedFilename if c in validFilenameChars)
|
2015-03-18 05:41:26 +11:00
|
|
|
|
2015-04-03 06:47:06 +11:00
|
|
|
|
|
|
|
def reset():
|
2015-04-03 19:39:16 +11:00
|
|
|
|
2015-04-15 12:20:08 +10:00
|
|
|
return_value = xbmcgui.Dialog().yesno("Warning", "Are you sure you want to reset your local Kodi database?")
|
2015-04-12 23:49:36 +10:00
|
|
|
|
2015-04-03 19:39:16 +11:00
|
|
|
if return_value == 0:
|
|
|
|
return
|
2015-04-12 23:49:36 +10:00
|
|
|
|
2015-05-05 09:43:46 +10:00
|
|
|
#cleanup video nodes
|
|
|
|
import shutil
|
2015-05-06 12:45:29 +10:00
|
|
|
path = "special://profile/library/video/"
|
2015-05-05 09:43:46 +10:00
|
|
|
if xbmcvfs.exists(path):
|
|
|
|
allDirs, allFiles = xbmcvfs.listdir(path)
|
|
|
|
for dir in allDirs:
|
|
|
|
if dir.startswith("Emby "):
|
2015-05-06 12:45:29 +10:00
|
|
|
shutil.rmtree(xbmc.translatePath("special://profile/library/video/" + dir))
|
2015-05-06 00:16:34 +10:00
|
|
|
for file in allFiles:
|
|
|
|
if file.startswith("emby"):
|
|
|
|
xbmcvfs.delete(path + file)
|
2015-05-05 09:43:46 +10:00
|
|
|
|
2015-04-12 23:49:36 +10:00
|
|
|
# Ask if user information should be deleted too.
|
2015-04-15 12:20:08 +10:00
|
|
|
return_user = xbmcgui.Dialog().yesno("Warning", "Reset all Emby Addon settings?")
|
2015-04-12 23:49:36 +10:00
|
|
|
|
2015-04-15 12:20:08 +10:00
|
|
|
delete_settings = False
|
2015-04-12 23:49:36 +10:00
|
|
|
if return_user == 1:
|
2015-04-15 12:20:08 +10:00
|
|
|
delete_settings = True
|
2015-04-03 19:39:16 +11:00
|
|
|
|
|
|
|
# first stop any db sync
|
|
|
|
WINDOW = xbmcgui.Window( 10000 )
|
|
|
|
WINDOW.setProperty("SyncDatabaseShouldStop", "true")
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
while(WINDOW.getProperty("SyncDatabaseRunning") == "true"):
|
2015-04-15 12:20:08 +10:00
|
|
|
xbmc.log("Sync Running, will wait : " + str(count))
|
2015-04-03 19:39:16 +11:00
|
|
|
count += 1
|
|
|
|
if(count > 10):
|
2015-04-03 21:49:39 +11:00
|
|
|
dialog = xbmcgui.Dialog()
|
2015-04-03 19:39:16 +11:00
|
|
|
dialog.ok('Warning', 'Could not stop DB sync, you should try again.')
|
|
|
|
return
|
|
|
|
xbmc.sleep(1000)
|
2015-04-12 18:34:00 +10:00
|
|
|
|
|
|
|
# delete db table data
|
|
|
|
print "Doing DB Reset"
|
|
|
|
connection = KodiSQL()
|
|
|
|
cursor = connection.cursor( )
|
|
|
|
cursor.execute('SELECT tbl_name FROM sqlite_master WHERE type="table"')
|
|
|
|
rows = cursor.fetchall()
|
|
|
|
for row in rows:
|
|
|
|
tableName = row[0]
|
|
|
|
print tableName
|
|
|
|
if(tableName != "version"):
|
|
|
|
cursor.execute("DELETE FROM " + tableName)
|
|
|
|
connection.commit()
|
|
|
|
cursor.close()
|
|
|
|
|
|
|
|
# reset the install run flag
|
2015-04-12 19:49:02 +10:00
|
|
|
WINDOW.setProperty("SyncInstallRunDone", "false")
|
2015-04-12 18:34:00 +10:00
|
|
|
|
2015-04-15 12:20:08 +10:00
|
|
|
if (delete_settings == True):
|
2015-04-12 23:49:36 +10:00
|
|
|
addondir = xbmc.translatePath(addonSettings.getAddonInfo('profile'))
|
|
|
|
dataPath = os.path.join(addondir + "settings.xml")
|
|
|
|
xbmcvfs.delete(dataPath)
|
2015-04-15 12:20:08 +10:00
|
|
|
xbmc.log("Deleting : settings.xml")
|
2015-04-12 23:49:36 +10:00
|
|
|
|
2015-04-03 06:47:06 +11:00
|
|
|
dialog = xbmcgui.Dialog()
|
2015-04-12 23:49:36 +10:00
|
|
|
dialog.ok('Emby Reset', 'Database reset has completed, Kodi will now restart to apply the changes.')
|
2015-04-03 19:39:16 +11:00
|
|
|
xbmc.executebuiltin("RestartApp")
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
def buildVideoNodeForView(tagname, type, windowPropId):
|
2015-05-06 00:16:34 +10:00
|
|
|
#this method will build a video node for a particular Emby view (= tag in kodi)
|
2015-05-07 06:53:55 +10:00
|
|
|
#we set some window props here to for easy future reference and to be used in skins (for easy access only)
|
2015-05-06 00:16:34 +10:00
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
2015-05-06 12:45:29 +10:00
|
|
|
libraryPath = xbmc.translatePath("special://profile/library/video/Emby - %s/" %tagname)
|
2015-05-06 00:16:34 +10:00
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
#create tag node - index
|
|
|
|
xbmcvfs.mkdir(libraryPath)
|
|
|
|
nodefile = os.path.join(libraryPath, "index.xml")
|
|
|
|
root = Element("node", {"order":"0"})
|
|
|
|
SubElement(root, "label").text = "Emby - " + tagname
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - all items
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_all.xml")
|
|
|
|
root = Element("node", {"order":"1", "type":"filter"})
|
|
|
|
SubElement(root, "label").text = tagname
|
|
|
|
SubElement(root, "match").text = "all"
|
|
|
|
SubElement(root, "content").text = type
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
SubElement(root, "order", {"direction":"ascending"}).text = "sorttitle"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.title" %str(windowPropId),tagname)
|
|
|
|
path = "library://video/Emby - %s/%s_all.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.content" %str(windowPropId),path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.type" %str(windowPropId),type)
|
|
|
|
SubElement(Rule, "value").text = tagname
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - recent items
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_recent.xml")
|
|
|
|
root = Element("node", {"order":"2", "type":"filter"})
|
|
|
|
if type == "tvshows":
|
|
|
|
label = tagname + " - " + language(30170)
|
|
|
|
else:
|
|
|
|
label = tagname + " - " + language(30174)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "match").text = "all"
|
|
|
|
SubElement(root, "content").text = type
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = tagname
|
|
|
|
SubElement(root, "order", {"direction":"descending"}).text = "dateadded"
|
|
|
|
#set limit to 25 --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
SubElement(root, "limit").text = "25"
|
|
|
|
#exclude watched items --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
Rule2 = SubElement(root, "rule", {"field":"playcount","operator":"is"})
|
|
|
|
SubElement(Rule2, "value").text = "0"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recent.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_recent.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recent.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recent.content" %str(windowPropId),path)
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - inprogress items
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_progress.xml")
|
|
|
|
root = Element("node", {"order":"3", "type":"filter"})
|
|
|
|
if type == "tvshows":
|
|
|
|
label = tagname + " - " + language(30171)
|
|
|
|
else:
|
|
|
|
label = tagname + " - " + language(30177)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "match").text = "all"
|
|
|
|
SubElement(root, "content").text = type
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = tagname
|
|
|
|
#set limit to 25 --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
SubElement(root, "limit").text = "25"
|
|
|
|
Rule2 = SubElement(root, "rule", {"field":"inprogress","operator":"true"})
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogress.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_progress.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogress.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogress.content" %str(windowPropId),path)
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - add unwatched movies node for movies
|
|
|
|
if type == "movies":
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_unwatched.xml")
|
|
|
|
root = Element("node", {"order":"4", "type":"filter"})
|
|
|
|
label = tagname + " - " + language(30189)
|
|
|
|
SubElement(root, "label").text = label
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "match").text = "all"
|
2015-05-07 06:53:55 +10:00
|
|
|
SubElement(root, "content").text = "movies"
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = tagname
|
2015-05-07 06:53:55 +10:00
|
|
|
Rule = SubElement(root, "rule", {"field":"playcount","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = "0"
|
|
|
|
SubElement(root, "order", {"direction":"ascending"}).text = "sorttitle"
|
|
|
|
#set limit to 25 --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
SubElement(root, "limit").text = "25"
|
|
|
|
#exclude watched items --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
Rule2 = SubElement(root, "rule", {"field":"playcount","operator":"is"})
|
|
|
|
SubElement(Rule2, "value").text = "0"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.unwatched.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_unwatched.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.unwatched.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.unwatched.content" %str(windowPropId),path)
|
2015-05-06 00:16:34 +10:00
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
2015-05-07 06:53:55 +10:00
|
|
|
|
|
|
|
|
|
|
|
#add some additional nodes for episodes
|
|
|
|
if type == "tvshows":
|
|
|
|
#create tag node - recent episodes
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_recent_episodes.xml")
|
|
|
|
root = Element("node", {"order":"3", "type":"filter"})
|
|
|
|
label = tagname + " - " + language(30175)
|
|
|
|
SubElement(root, "label").text = label
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "match").text = "all"
|
2015-05-07 06:53:55 +10:00
|
|
|
SubElement(root, "content").text = "episodes"
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = tagname
|
|
|
|
SubElement(root, "order", {"direction":"descending"}).text = "dateadded"
|
|
|
|
#set limit to 25 --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
SubElement(root, "limit").text = "25"
|
|
|
|
#exclude watched items --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
Rule2 = SubElement(root, "rule", {"field":"playcount","operator":"is"})
|
|
|
|
SubElement(Rule2, "value").text = "0"
|
2015-05-07 06:53:55 +10:00
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recentepisodes.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_recent_episodes.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recentepisodes.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.recentepisodes.content" %str(windowPropId),path)
|
2015-05-06 00:16:34 +10:00
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - inprogress items
|
2015-05-07 06:53:55 +10:00
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_progress_episodes.xml")
|
|
|
|
root = Element("node", {"order":"4", "type":"filter"})
|
|
|
|
label = tagname + " - " + language(30178)
|
|
|
|
SubElement(root, "label").text = label
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "match").text = "all"
|
2015-05-07 06:53:55 +10:00
|
|
|
SubElement(root, "content").text = "episodes"
|
2015-05-06 00:16:34 +10:00
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = tagname
|
|
|
|
#set limit to 25 --> currently hardcoded --> TODO: add a setting for this ?
|
|
|
|
SubElement(root, "limit").text = "25"
|
|
|
|
Rule2 = SubElement(root, "rule", {"field":"inprogress","operator":"true"})
|
2015-05-07 06:53:55 +10:00
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogressepisodes.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_progress_episodes.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogressepisodes.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.inprogressepisodes.content" %str(windowPropId),path)
|
2015-05-06 00:16:34 +10:00
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
#create tag node - nextup items
|
|
|
|
nodefile = os.path.join(libraryPath, tagname + "_nextup_episodes.xml")
|
|
|
|
root = Element("node", {"order":"4", "type":"folder"})
|
|
|
|
label = tagname + " - " + language(30179)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "content").text = "episodes"
|
|
|
|
path = "plugin://plugin.video.emby/?id=%s&mode=nextup&limit=25" %tagname
|
|
|
|
SubElement(root, "path").text = path
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.nextepisodes.title" %str(windowPropId),label)
|
|
|
|
path = "library://video/Emby - %s/%s_nextup_episodes.xml"%(tagname,tagname)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.nextepisodes.path" %str(windowPropId),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.nextepisodes.content" %str(windowPropId),path)
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
def buildVideoNodesListing():
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
from ReadEmbyDB import ReadEmbyDB
|
2015-05-07 06:53:55 +10:00
|
|
|
WINDOW = xbmcgui.Window(10000)
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# the library path doesn't exist on all systems
|
2015-05-06 12:45:29 +10:00
|
|
|
if not xbmcvfs.exists("special://profile/library/"):
|
|
|
|
xbmcvfs.mkdir("special://profile/library")
|
|
|
|
if not xbmcvfs.exists("special://profile/library/video/"):
|
2015-05-06 00:16:34 +10:00
|
|
|
#we need to copy over the default items
|
|
|
|
import shutil
|
2015-05-06 12:45:29 +10:00
|
|
|
shutil.copytree(xbmc.translatePath("special://xbmc/system/library/video"), xbmc.translatePath("special://profile/library/video"))
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
#always cleanup existing Emby video nodes first because we don't want old stuff to stay in there
|
2015-05-06 12:45:29 +10:00
|
|
|
path = "special://profile/library/video/"
|
2015-05-06 00:16:34 +10:00
|
|
|
if xbmcvfs.exists(path):
|
|
|
|
allDirs, allFiles = xbmcvfs.listdir(path)
|
|
|
|
for dir in allDirs:
|
|
|
|
if dir.startswith("Emby "):
|
2015-05-06 12:45:29 +10:00
|
|
|
shutil.rmtree(xbmc.translatePath("special://profile/library/video/" + dir))
|
2015-05-06 00:16:34 +10:00
|
|
|
for file in allFiles:
|
|
|
|
if file.startswith("emby"):
|
|
|
|
xbmcvfs.delete(path + file)
|
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
#we build up a listing and set window props for all nodes we created
|
|
|
|
#the window props will be used by the main entry point to quickly build up the listing and can be used in skins (like titan) too for quick reference
|
|
|
|
#comment marcelveldt: please leave the window props as-is because I will be referencing them in titan skin...
|
|
|
|
totalNodesCount = 0
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
#build the listing for all views
|
|
|
|
views_movies = ReadEmbyDB().getCollections("movies")
|
|
|
|
if views_movies:
|
|
|
|
for view in views_movies:
|
2015-05-07 06:53:55 +10:00
|
|
|
buildVideoNodeForView(view.get('title'), "movies", totalNodesCount)
|
|
|
|
totalNodesCount +=1
|
2015-05-06 00:16:34 +10:00
|
|
|
|
|
|
|
views_shows = ReadEmbyDB().getCollections("tvshows")
|
|
|
|
if views_shows:
|
|
|
|
for view in views_shows:
|
2015-05-07 06:53:55 +10:00
|
|
|
buildVideoNodeForView(view.get('title'), "tvshows", totalNodesCount)
|
|
|
|
totalNodesCount +=1
|
|
|
|
|
|
|
|
#create tag node for emby channels
|
|
|
|
nodefile = os.path.join(xbmc.translatePath("special://profile/library/video"), "emby_channels.xml")
|
|
|
|
root = Element("node", {"order":"1", "type":"folder"})
|
|
|
|
label = "Emby - " + language(30173)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "content").text = "movies"
|
|
|
|
SubElement(root, "path").text = "plugin://plugin.video.emby/?id=0&mode=channels"
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.title" %str(totalNodesCount),label)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.type" %str(totalNodesCount),"channels")
|
|
|
|
path = "library://video/emby_channels.xml"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.path" %str(totalNodesCount),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.content" %str(totalNodesCount),path)
|
|
|
|
totalNodesCount +=1
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - favorite shows
|
|
|
|
nodefile = os.path.join(xbmc.translatePath("special://profile/library/video"),"emby_favorite_shows.xml")
|
|
|
|
root = Element("node", {"order":"1", "type":"filter"})
|
|
|
|
label = "Emby - " + language(30181)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "match").text = "all"
|
|
|
|
SubElement(root, "content").text = "tvshows"
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
SubElement(root, "order", {"direction":"ascending"}).text = "sorttitle"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = "Favorite tvshows" #do not localize the tagname itself
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.title" %str(totalNodesCount),label)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.type" %str(totalNodesCount),"favourites")
|
|
|
|
path = "library://video/emby_favorite_shows.xml"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.path" %str(totalNodesCount),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.content" %str(totalNodesCount),path)
|
|
|
|
totalNodesCount +=1
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
#create tag node - favorite movies
|
|
|
|
nodefile = os.path.join(xbmc.translatePath("special://profile/library/video"),"emby_favorite_movies.xml")
|
|
|
|
root = Element("node", {"order":"1", "type":"filter"})
|
|
|
|
label = "Emby - " + language(30180)
|
|
|
|
SubElement(root, "label").text = label
|
|
|
|
SubElement(root, "match").text = "all"
|
|
|
|
SubElement(root, "content").text = "movies"
|
|
|
|
SubElement(root, "icon").text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
SubElement(root, "order", {"direction":"ascending"}).text = "sorttitle"
|
|
|
|
Rule = SubElement(root, "rule", {"field":"tag","operator":"is"})
|
|
|
|
SubElement(Rule, "value").text = "Favorite movies" #do not localize the tagname itself
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.title" %str(totalNodesCount),label)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.type" %str(totalNodesCount),"favourites")
|
|
|
|
path = "library://video/emby_favorite_movies.xml"
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.path" %str(totalNodesCount),"ActivateWindow(Video,%s,return)"%path)
|
|
|
|
WINDOW.setProperty("Emby.nodes.%s.content" %str(totalNodesCount),path)
|
|
|
|
totalNodesCount +=1
|
|
|
|
try:
|
|
|
|
ET.ElementTree(root).write(nodefile, xml_declaration=True)
|
|
|
|
except:
|
|
|
|
ET.ElementTree(root).write(nodefile)
|
|
|
|
|
|
|
|
WINDOW.setProperty("Emby.nodes.total", str(totalNodesCount))
|
2015-05-06 00:16:34 +10:00
|
|
|
|
2015-05-07 06:53:55 +10:00
|
|
|
except Exception as e:
|
2015-05-06 00:16:34 +10:00
|
|
|
logMsg("Emby addon","Error while creating videonodes listings, restart required ?")
|
2015-05-07 06:53:55 +10:00
|
|
|
print e
|
2015-05-06 00:16:34 +10:00
|
|
|
|