From 1971eb8655c96319c6b7386030f06c7a2d05e561 Mon Sep 17 00:00:00 2001 From: shaun Date: Sun, 15 Mar 2015 15:18:34 +1100 Subject: [PATCH 1/2] create a empty sources.xml to work with if one does not exist --- resources/lib/Utils.py | 52 ++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/resources/lib/Utils.py b/resources/lib/Utils.py index 7ee26cf7..ae73cdc1 100644 --- a/resources/lib/Utils.py +++ b/resources/lib/Utils.py @@ -53,7 +53,7 @@ def checkKodiSources(): xbmcvfs.mkdir(dataPath) if not xbmcvfs.exists(movieLibrary + os.sep): xbmcvfs.mkdir(movieLibrary) - rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies") + rebootRequired = addKodiSource("mediabrowser_movies",movieLibrary,"movies") if not xbmcvfs.exists(tvLibrary + os.sep): xbmcvfs.mkdir(tvLibrary) rebootRequired = addKodiSource("mediabrowser_tvshows",tvLibrary,"tvshows") @@ -86,31 +86,33 @@ def addKodiSource(name, path, type): else: error = True - if error: - # if adding to the database failed, manually add it to sources.xml - sourcesFile = xbmc.translatePath( "special://profile/sources.xml" ) - if xbmcvfs.exists(sourcesFile): - tree = ET.ElementTree(file=sourcesFile) - root = tree.getroot() - videosources = root.find("video") - #remove any existing entries for this path - allsources = videosources.findall("source") - if allsources != None: - for source in allsources: - if source.find("name").text == name: - videosources.remove(source) - # add the new source - source = SubElement(videosources,'source') - SubElement(source, "name").text = name - SubElement(source, "path").text = path - tree.write(sourcesFile) + # add it to sources.xml + sourcesFile = xbmc.translatePath( "special://profile/sources.xml" ) + + # add an emply sources file to work with + if xbmcvfs.exists(sourcesFile) == False: + sources = Element("sources") + video = SubElement(sources, "video") + ET.ElementTree(sources).write(sourcesFile) + + if xbmcvfs.exists(sourcesFile): + tree = ET.ElementTree(file=sourcesFile) + root = tree.getroot() + videosources = root.find("video") + #remove any existing entries for this path + allsources = videosources.findall("source") + if allsources != None: + for source in allsources: + if source.find("name").text == name: + videosources.remove(source) + # add the new source + source = SubElement(videosources,'source') + SubElement(source, "name").text = name + SubElement(source, "path").text = path + tree.write(sourcesFile) #return bool that reboot is needed and manual add of path to kodi - return True - else: - #return false that no reboot is needed - return False - - + #return True + def checkAuthentication(): #check authentication From a579eebe7e063c420bd9bfc5305ce5b06e0cc421 Mon Sep 17 00:00:00 2001 From: xnappo Date: Sun, 15 Mar 2015 09:10:26 -0500 Subject: [PATCH 2/2] Add getCollections method --- resources/lib/LibrarySync.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py index ae6f497b..972dbf80 100644 --- a/resources/lib/LibrarySync.py +++ b/resources/lib/LibrarySync.py @@ -133,7 +133,6 @@ class LibrarySync(): downloadUtils = DownloadUtils() userid = downloadUtils.getUserId() - if fullinfo: url = server + '/mediabrowser/Users/' + userid + '/Items?&SortBy=SortName&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Ascending&IncludeItemTypes=Movie&format=json&ImageTypeLimit=1' else: @@ -614,3 +613,32 @@ class LibrarySync(): tvshow = tvshows[0] return tvshow + + def getCollections(self): + #Build a list of the user views + userid = DownloadUtils().getUserId() + addon = xbmcaddon.Addon(id='plugin.video.mb3sync') + port = addon.getSetting('port') + host = addon.getSetting('ipaddress') + server = host + ":" + port + + viewsUrl = server + "/mediabrowser/Users/" + userid + "/Views?format=json&ImageTypeLimit=1" + jsonData = DownloadUtils().downloadUrl(viewsUrl, suppress=True, popup=0 ) + + if(jsonData != ""): + views = json.loads(jsonData) + views = views.get("Items") + collections=[] + for view in views: + if(view.get("ChildCount") != 0): + Name =(view.get("Name")).encode('utf-8') + + total = str(view.get("ChildCount")) + type = view.get("CollectionType") + if type == None: + type = "None" # User may not have declared the type + if type == "movies" or type == "tvshows": + collections.append( {'title' : Name, + 'type' : type, + 'id' : view.get("Id")}) + return collections \ No newline at end of file