From a3b42a04477248227150c6935154472d12f9e4ad Mon Sep 17 00:00:00 2001
From: xnappo <cnappi@gmail.com>
Date: Sun, 22 Mar 2015 16:22:03 -0500
Subject: [PATCH] Use collections instead of views for tags

---
 resources/lib/ReadEmbyDB.py | 50 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/resources/lib/ReadEmbyDB.py b/resources/lib/ReadEmbyDB.py
index 849b6a46..ae73615c 100644
--- a/resources/lib/ReadEmbyDB.py
+++ b/resources/lib/ReadEmbyDB.py
@@ -186,7 +186,6 @@ class ReadEmbyDB():
                 result = result['Items']
         return result
     
-    
     def getCollections(self, type):
         #Build a list of the user views
         userid = DownloadUtils().getUserId()  
@@ -194,6 +193,55 @@ class ReadEmbyDB():
         port = addon.getSetting('port')
         host = addon.getSetting('ipaddress')
         server = host + ":" + port
+        downloadUtils = DownloadUtils()
+        
+        try:
+            jsonData = downloadUtils.downloadUrl("http://" + server + "/mediabrowser/Users/" + userid + "/Items/Root?format=json")
+        except Exception, msg:
+            error = "Get connect : " + str(msg)
+            xbmc.log (error)
+            return []
+        
+        if(jsonData == ""):
+            return []
+            
+        result = json.loads(jsonData)
+        
+        parentid = result.get("Id")
+        
+        htmlpath = ("http://%s/mediabrowser/Users/" % server)
+        jsonData = downloadUtils.downloadUrl(htmlpath + userid + "/items?ParentId=" + parentid + "&Sortby=SortName&format=json")
+        collections=[]
+        
+        if(jsonData == ""):
+            printDebug("No Json data")
+            return []
+        
+        result = json.loads(jsonData)
+        result = result.get("Items")
+        
+        for item in result:
+            if(item.get("RecursiveItemCount") != 0):
+                Temp = item.get("Name")
+                Name = Temp.encode('utf-8')
+                section = item.get("CollectionType")
+                type = item.get("CollectionType")
+                if type == None:
+                    type = "None" # User may not have declared the type
+                if type == type:
+                    collections.append( {'title'      : item.get("Name"),
+                            'type'           : type,
+                            'id'             : item.get("Id")})
+        print "paco!" + str (collections)
+        return collections
+    
+    def getViewCollections(self, type):
+        #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 )