self kodi version

This commit is contained in:
SpootDev 2016-03-31 14:39:39 -05:00
parent d915c4539e
commit af69c9224e

View file

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