2015-12-25 07:07:00 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import xml.etree.ElementTree as etree
|
|
|
|
|
|
|
|
import xbmc
|
|
|
|
import xbmcaddon
|
|
|
|
import xbmcvfs
|
|
|
|
|
|
|
|
import clientinfo
|
|
|
|
import utils
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
class VideoNodes(object):
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
clientInfo = clientinfo.ClientInfo()
|
|
|
|
self.addonName = clientInfo.getAddonName()
|
|
|
|
|
2016-02-17 19:13:37 +11:00
|
|
|
self.kodiversion = int(xbmc.getInfoLabel('System.BuildVersion')[:2])
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
def logMsg(self, msg, lvl=1):
|
|
|
|
|
|
|
|
className = self.__class__.__name__
|
|
|
|
utils.logMsg("%s %s" % (self.addonName, className), msg, lvl)
|
|
|
|
|
|
|
|
|
|
|
|
def commonRoot(self, order, label, tagname, roottype=1):
|
|
|
|
|
|
|
|
if roottype == 0:
|
|
|
|
# Index
|
|
|
|
root = etree.Element('node', attrib={'order': "%s" % order})
|
|
|
|
elif roottype == 1:
|
|
|
|
# Filter
|
|
|
|
root = etree.Element('node', attrib={'order': "%s" % order, 'type': "filter"})
|
|
|
|
etree.SubElement(root, 'match').text = "all"
|
|
|
|
# Add tag rule
|
|
|
|
rule = etree.SubElement(root, 'rule', attrib={'field': "tag", 'operator': "is"})
|
|
|
|
etree.SubElement(rule, 'value').text = tagname
|
|
|
|
else:
|
|
|
|
# Folder
|
|
|
|
root = etree.Element('node', attrib={'order': "%s" % order, 'type': "folder"})
|
|
|
|
|
|
|
|
etree.SubElement(root, 'label').text = label
|
|
|
|
etree.SubElement(root, 'icon').text = "special://home/addons/plugin.video.emby/icon.png"
|
|
|
|
|
|
|
|
return root
|
|
|
|
|
2016-02-23 17:00:24 +11:00
|
|
|
def viewNode(self, indexnumber, tagname, mediatype, viewtype, viewid, delete=False):
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
window = utils.window
|
2015-12-25 07:07:00 +11:00
|
|
|
kodiversion = self.kodiversion
|
|
|
|
|
|
|
|
if viewtype == "mixed":
|
2016-02-23 17:00:24 +11:00
|
|
|
dirname = "%s - %s" % (viewid, mediatype)
|
2015-12-25 07:07:00 +11:00
|
|
|
else:
|
2016-02-23 17:00:24 +11:00
|
|
|
dirname = viewid
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
path = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
|
|
|
|
nodepath = xbmc.translatePath(
|
|
|
|
"special://profile/library/video/Emby - %s/" % dirname).decode('utf-8')
|
|
|
|
|
|
|
|
# Verify the video directory
|
|
|
|
if not xbmcvfs.exists(path):
|
|
|
|
shutil.copytree(
|
2016-01-05 16:06:47 +11:00
|
|
|
src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'),
|
|
|
|
dst=xbmc.translatePath("special://profile/library/video").decode('utf-8'))
|
2015-12-25 07:07:00 +11:00
|
|
|
xbmcvfs.exists(path)
|
|
|
|
|
|
|
|
# Create the node directory
|
2016-02-17 19:13:37 +11:00
|
|
|
if not xbmcvfs.exists(nodepath) and not mediatype == "photos":
|
2015-12-25 07:07:00 +11:00
|
|
|
# We need to copy over the default items
|
|
|
|
xbmcvfs.mkdirs(nodepath)
|
|
|
|
else:
|
|
|
|
if delete:
|
|
|
|
dirs, files = xbmcvfs.listdir(nodepath)
|
|
|
|
for file in files:
|
|
|
|
xbmcvfs.delete(nodepath + file)
|
|
|
|
|
|
|
|
self.logMsg("Sucessfully removed videonode: %s." % tagname, 1)
|
|
|
|
return
|
|
|
|
|
|
|
|
# Create index entry
|
|
|
|
nodeXML = "%sindex.xml" % nodepath
|
|
|
|
# Set windows property
|
|
|
|
path = "library://video/Emby - %s/" % dirname
|
|
|
|
for i in range(1, indexnumber):
|
|
|
|
# Verify to make sure we don't create duplicates
|
2016-02-04 23:22:33 +11:00
|
|
|
if window('Emby.nodes.%s.index' % i) == path:
|
2015-12-25 07:07:00 +11:00
|
|
|
return
|
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
if mediatype == "photos":
|
2016-01-22 21:10:42 +11:00
|
|
|
path = "plugin://plugin.video.emby/?id=%s&mode=getsubfolders" % indexnumber
|
2016-01-12 08:20:34 +11:00
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
window('Emby.nodes.%s.index' % indexnumber, value=path)
|
2016-01-12 08:20:34 +11:00
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
# Root
|
2016-02-17 19:13:37 +11:00
|
|
|
if not mediatype == "photos":
|
2016-02-23 10:56:08 +11:00
|
|
|
if viewtype == "mixed":
|
2016-02-23 13:42:23 +11:00
|
|
|
specialtag = "%s - %s" % (tagname, mediatype)
|
|
|
|
root = self.commonRoot(order=0, label=specialtag, tagname=tagname, roottype=0)
|
2016-02-23 10:56:08 +11:00
|
|
|
else:
|
|
|
|
root = self.commonRoot(order=0, label=tagname, tagname=tagname, roottype=0)
|
2016-01-12 08:20:34 +11:00
|
|
|
try:
|
|
|
|
utils.indent(root)
|
|
|
|
except: pass
|
|
|
|
etree.ElementTree(root).write(nodeXML)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
nodetypes = {
|
|
|
|
|
|
|
|
'1': "all",
|
|
|
|
'2': "recent",
|
|
|
|
'3': "recentepisodes",
|
|
|
|
'4': "inprogress",
|
|
|
|
'5': "inprogressepisodes",
|
|
|
|
'6': "unwatched",
|
2016-01-06 18:59:41 +11:00
|
|
|
'7': "nextepisodes",
|
2015-12-25 07:07:00 +11:00
|
|
|
'8': "sets",
|
|
|
|
'9': "genres",
|
|
|
|
'10': "random",
|
2016-01-13 11:03:35 +11:00
|
|
|
'11': "recommended",
|
2015-12-25 07:07:00 +11:00
|
|
|
}
|
|
|
|
mediatypes = {
|
|
|
|
# label according to nodetype per mediatype
|
2016-01-13 11:03:35 +11:00
|
|
|
'movies':
|
|
|
|
{
|
2015-12-25 07:07:00 +11:00
|
|
|
'1': tagname,
|
|
|
|
'2': 30174,
|
|
|
|
'4': 30177,
|
|
|
|
'6': 30189,
|
|
|
|
'8': 20434,
|
|
|
|
'9': 135,
|
|
|
|
'10': 30229,
|
2016-01-13 11:03:35 +11:00
|
|
|
'11': 30230
|
|
|
|
},
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-01-13 11:03:35 +11:00
|
|
|
'tvshows':
|
|
|
|
{
|
2015-12-25 07:07:00 +11:00
|
|
|
'1': tagname,
|
|
|
|
'2': 30170,
|
|
|
|
'3': 30175,
|
|
|
|
'4': 30171,
|
|
|
|
'5': 30178,
|
|
|
|
'7': 30179,
|
|
|
|
'9': 135,
|
|
|
|
'10': 30229,
|
2016-01-13 11:03:35 +11:00
|
|
|
'11': 30230
|
|
|
|
},
|
2016-01-12 08:20:34 +11:00
|
|
|
|
2016-01-13 11:03:35 +11:00
|
|
|
'homevideos':
|
|
|
|
{
|
2016-01-12 08:20:34 +11:00
|
|
|
'1': tagname,
|
2016-01-13 11:03:35 +11:00
|
|
|
'2': 30251,
|
|
|
|
'11': 30253
|
|
|
|
},
|
2016-01-12 08:20:34 +11:00
|
|
|
|
2016-01-13 11:03:35 +11:00
|
|
|
'photos':
|
|
|
|
{
|
2016-01-12 08:20:34 +11:00
|
|
|
'1': tagname,
|
2016-01-13 11:03:35 +11:00
|
|
|
'2': 30252,
|
|
|
|
'8': 30255,
|
|
|
|
'11': 30254
|
|
|
|
},
|
2016-02-04 23:22:33 +11:00
|
|
|
|
2016-01-19 06:17:14 +11:00
|
|
|
'musicvideos':
|
|
|
|
{
|
|
|
|
'1': tagname,
|
|
|
|
'2': 30256,
|
|
|
|
'4': 30257,
|
|
|
|
'6': 30258
|
2016-02-04 23:22:33 +11:00
|
|
|
}
|
2015-12-25 07:07:00 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
nodes = mediatypes[mediatype]
|
|
|
|
for node in nodes:
|
|
|
|
|
|
|
|
nodetype = nodetypes[node]
|
2016-02-23 17:00:24 +11:00
|
|
|
nodeXML = "%s%s_%s.xml" % (nodepath, viewid, nodetype)
|
2015-12-25 07:07:00 +11:00
|
|
|
# Get label
|
|
|
|
stringid = nodes[node]
|
2016-02-17 19:13:37 +11:00
|
|
|
if node != "1":
|
2015-12-25 07:07:00 +11:00
|
|
|
label = utils.language(stringid)
|
|
|
|
if not label:
|
|
|
|
label = xbmc.getLocalizedString(stringid)
|
|
|
|
else:
|
|
|
|
label = stringid
|
|
|
|
|
|
|
|
# Set window properties
|
2016-01-13 11:03:35 +11:00
|
|
|
if (mediatype == "homevideos" or mediatype == "photos") and nodetype == "all":
|
2016-01-12 08:20:34 +11:00
|
|
|
# Custom query
|
2016-02-04 23:22:33 +11:00
|
|
|
path = ("plugin://plugin.video.emby/?id=%s&mode=browsecontent&type=%s"
|
|
|
|
% (tagname, mediatype))
|
2016-01-13 11:03:35 +11:00
|
|
|
elif (mediatype == "homevideos" or mediatype == "photos"):
|
2016-01-12 08:20:34 +11:00
|
|
|
# Custom query
|
2016-02-04 23:22:33 +11:00
|
|
|
path = ("plugin://plugin.video.emby/?id=%s&mode=browsecontent&type=%s&folderid=%s"
|
|
|
|
% (tagname, mediatype, nodetype))
|
2016-01-12 08:20:34 +11:00
|
|
|
elif nodetype == "nextepisodes":
|
2015-12-25 07:07:00 +11:00
|
|
|
# Custom query
|
|
|
|
path = "plugin://plugin.video.emby/?id=%s&mode=nextup&limit=25" % tagname
|
|
|
|
elif kodiversion == 14 and nodetype == "recentepisodes":
|
|
|
|
# Custom query
|
|
|
|
path = "plugin://plugin.video.emby/?id=%s&mode=recentepisodes&limit=25" % tagname
|
|
|
|
elif kodiversion == 14 and nodetype == "inprogressepisodes":
|
|
|
|
# Custom query
|
|
|
|
path = "plugin://plugin.video.emby/?id=%s&mode=inprogressepisodes&limit=25"% tagname
|
|
|
|
else:
|
2016-02-23 17:00:24 +11:00
|
|
|
path = "library://video/Emby - %s/%s_%s.xml" % (dirname, viewid, nodetype)
|
2016-01-12 08:20:34 +11:00
|
|
|
|
|
|
|
if mediatype == "photos":
|
|
|
|
windowpath = "ActivateWindow(Pictures,%s,return)" % path
|
|
|
|
else:
|
|
|
|
windowpath = "ActivateWindow(Video,%s,return)" % path
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if nodetype == "all":
|
|
|
|
|
|
|
|
if viewtype == "mixed":
|
2016-02-23 17:00:24 +11:00
|
|
|
templabel = "%s - %s" % (tagname, mediatype)
|
2015-12-25 07:07:00 +11:00
|
|
|
else:
|
|
|
|
templabel = label
|
|
|
|
|
|
|
|
embynode = "Emby.nodes.%s" % indexnumber
|
2016-02-04 23:22:33 +11:00
|
|
|
window('%s.title' % embynode, value=templabel)
|
|
|
|
window('%s.path' % embynode, value=windowpath)
|
|
|
|
window('%s.content' % embynode, value=path)
|
|
|
|
window('%s.type' % embynode, value=mediatype)
|
2015-12-25 07:07:00 +11:00
|
|
|
else:
|
|
|
|
embynode = "Emby.nodes.%s.%s" % (indexnumber, nodetype)
|
2016-02-04 23:22:33 +11:00
|
|
|
window('%s.title' % embynode, value=label)
|
|
|
|
window('%s.path' % embynode, value=windowpath)
|
|
|
|
window('%s.content' % embynode, value=path)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
if mediatype == "photos":
|
|
|
|
# For photos, we do not create a node in videos but we do want the window props
|
|
|
|
# to be created.
|
|
|
|
# To do: add our photos nodes to kodi picture sources somehow
|
2016-01-12 08:20:34 +11:00
|
|
|
continue
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
if xbmcvfs.exists(nodeXML):
|
|
|
|
# Don't recreate xml if already exists
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Create the root
|
2016-02-04 23:22:33 +11:00
|
|
|
if (nodetype == "nextepisodes" or mediatype == "homevideos" or
|
|
|
|
(kodiversion == 14 and nodetype in ('recentepisodes', 'inprogressepisodes'))):
|
2015-12-25 07:07:00 +11:00
|
|
|
# Folder type with plugin path
|
|
|
|
root = self.commonRoot(order=node, label=label, tagname=tagname, roottype=2)
|
|
|
|
etree.SubElement(root, 'path').text = path
|
|
|
|
etree.SubElement(root, 'content').text = "episodes"
|
|
|
|
else:
|
|
|
|
root = self.commonRoot(order=node, label=label, tagname=tagname)
|
|
|
|
if nodetype in ('recentepisodes', 'inprogressepisodes'):
|
|
|
|
etree.SubElement(root, 'content').text = "episodes"
|
|
|
|
else:
|
|
|
|
etree.SubElement(root, 'content').text = mediatype
|
|
|
|
|
|
|
|
limit = "25"
|
|
|
|
# Elements per nodetype
|
|
|
|
if nodetype == "all":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle"
|
|
|
|
|
|
|
|
elif nodetype == "recent":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "descending"}).text = "dateadded"
|
|
|
|
etree.SubElement(root, 'limit').text = limit
|
|
|
|
rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"})
|
|
|
|
etree.SubElement(rule, 'value').text = "0"
|
|
|
|
|
|
|
|
elif nodetype == "inprogress":
|
|
|
|
etree.SubElement(root, 'rule', {'field': "inprogress", 'operator': "true"})
|
|
|
|
etree.SubElement(root, 'limit').text = limit
|
|
|
|
|
|
|
|
elif nodetype == "genres":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle"
|
|
|
|
etree.SubElement(root, 'group').text = "genres"
|
|
|
|
|
|
|
|
elif nodetype == "unwatched":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle"
|
|
|
|
rule = etree.SubElement(root, "rule", {'field': "playcount", 'operator': "is"})
|
|
|
|
etree.SubElement(rule, 'value').text = "0"
|
|
|
|
|
|
|
|
elif nodetype == "sets":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle"
|
|
|
|
etree.SubElement(root, 'group').text = "sets"
|
|
|
|
|
|
|
|
elif nodetype == "random":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "random"
|
|
|
|
etree.SubElement(root, 'limit').text = limit
|
|
|
|
|
|
|
|
elif nodetype == "recommended":
|
|
|
|
etree.SubElement(root, 'order', {'direction': "descending"}).text = "rating"
|
|
|
|
etree.SubElement(root, 'limit').text = limit
|
|
|
|
rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"})
|
|
|
|
etree.SubElement(rule, 'value').text = "0"
|
|
|
|
rule2 = etree.SubElement(root, 'rule',
|
|
|
|
attrib={'field': "rating", 'operator': "greaterthan"})
|
|
|
|
etree.SubElement(rule2, 'value').text = "7"
|
|
|
|
|
|
|
|
elif nodetype == "recentepisodes":
|
|
|
|
# Kodi Isengard, Jarvis
|
|
|
|
etree.SubElement(root, 'order', {'direction': "descending"}).text = "dateadded"
|
|
|
|
etree.SubElement(root, 'limit').text = limit
|
|
|
|
rule = etree.SubElement(root, 'rule', {'field': "playcount", 'operator': "is"})
|
|
|
|
etree.SubElement(rule, 'value').text = "0"
|
|
|
|
|
|
|
|
elif nodetype == "inprogressepisodes":
|
|
|
|
# Kodi Isengard, Jarvis
|
|
|
|
etree.SubElement(root, 'limit').text = "25"
|
|
|
|
rule = etree.SubElement(root, 'rule',
|
|
|
|
attrib={'field': "inprogress", 'operator':"true"})
|
|
|
|
|
|
|
|
try:
|
|
|
|
utils.indent(root)
|
|
|
|
except: pass
|
|
|
|
etree.ElementTree(root).write(nodeXML)
|
|
|
|
|
|
|
|
def singleNode(self, indexnumber, tagname, mediatype, itemtype):
|
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
window = utils.window
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
tagname = tagname.encode('utf-8')
|
|
|
|
cleantagname = utils.normalize_nodes(tagname)
|
|
|
|
nodepath = xbmc.translatePath("special://profile/library/video/").decode('utf-8')
|
|
|
|
nodeXML = "%semby_%s.xml" % (nodepath, cleantagname)
|
2016-02-17 19:13:37 +11:00
|
|
|
path = "library://video/emby_%s.xml" % cleantagname
|
2016-01-06 20:08:16 +11:00
|
|
|
windowpath = "ActivateWindow(Video,%s,return)" % path
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
# Create the video node directory
|
|
|
|
if not xbmcvfs.exists(nodepath):
|
|
|
|
# We need to copy over the default items
|
|
|
|
shutil.copytree(
|
|
|
|
src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'),
|
|
|
|
dst=xbmc.translatePath("special://profile/library/video").decode('utf-8'))
|
|
|
|
xbmcvfs.exists(path)
|
|
|
|
|
|
|
|
labels = {
|
|
|
|
|
|
|
|
'Favorite movies': 30180,
|
|
|
|
'Favorite tvshows': 30181,
|
|
|
|
'channels': 30173
|
|
|
|
}
|
|
|
|
label = utils.language(labels[tagname])
|
|
|
|
embynode = "Emby.nodes.%s" % indexnumber
|
2016-02-04 23:22:33 +11:00
|
|
|
window('%s.title' % embynode, value=label)
|
|
|
|
window('%s.path' % embynode, value=windowpath)
|
|
|
|
window('%s.content' % embynode, value=path)
|
|
|
|
window('%s.type' % embynode, value=itemtype)
|
2015-12-25 07:07:00 +11:00
|
|
|
|
|
|
|
if xbmcvfs.exists(nodeXML):
|
|
|
|
# Don't recreate xml if already exists
|
|
|
|
return
|
|
|
|
|
|
|
|
if itemtype == "channels":
|
|
|
|
root = self.commonRoot(order=1, label=label, tagname=tagname, roottype=2)
|
|
|
|
etree.SubElement(root, 'path').text = "plugin://plugin.video.emby/?id=0&mode=channels"
|
|
|
|
else:
|
|
|
|
root = self.commonRoot(order=1, label=label, tagname=tagname)
|
|
|
|
etree.SubElement(root, 'order', {'direction': "ascending"}).text = "sorttitle"
|
|
|
|
|
|
|
|
etree.SubElement(root, 'content').text = mediatype
|
|
|
|
|
|
|
|
try:
|
|
|
|
utils.indent(root)
|
|
|
|
except: pass
|
|
|
|
etree.ElementTree(root).write(nodeXML)
|
|
|
|
|
|
|
|
def clearProperties(self):
|
|
|
|
|
2016-02-04 23:22:33 +11:00
|
|
|
window = utils.window
|
|
|
|
|
2015-12-25 07:07:00 +11:00
|
|
|
self.logMsg("Clearing nodes properties.", 1)
|
2016-02-04 23:22:33 +11:00
|
|
|
embyprops = window('Emby.nodes.total')
|
2015-12-25 07:07:00 +11:00
|
|
|
propnames = [
|
|
|
|
|
|
|
|
"index","path","title","content",
|
|
|
|
"inprogress.content","inprogress.title",
|
|
|
|
"inprogress.content","inprogress.path",
|
|
|
|
"nextepisodes.title","nextepisodes.content",
|
|
|
|
"nextepisodes.path","unwatched.title",
|
|
|
|
"unwatched.content","unwatched.path",
|
|
|
|
"recent.title","recent.content","recent.path",
|
|
|
|
"recentepisodes.title","recentepisodes.content",
|
|
|
|
"recentepisodes.path","inprogressepisodes.title",
|
|
|
|
"inprogressepisodes.content","inprogressepisodes.path"
|
|
|
|
]
|
|
|
|
|
|
|
|
if embyprops:
|
|
|
|
totalnodes = int(embyprops)
|
|
|
|
for i in range(totalnodes):
|
|
|
|
for prop in propnames:
|
2016-02-04 23:22:33 +11:00
|
|
|
window('Emby.nodes.%s.%s' % (str(i), prop), clear=True)
|