From c92454bb92d5c1ebc2fd9f3de0ddf23c38b4c273 Mon Sep 17 00:00:00 2001
From: angelblue05 <tamara.angel05@gmail.com>
Date: Tue, 8 Sep 2015 13:36:49 -0500
Subject: [PATCH] Support mixed content and undefined collection

Undefined collection - when rich presentation is disabled.
---
 resources/lib/LibrarySync.py | 23 +++++++++++++++++++----
 resources/lib/ReadEmbyDB.py  | 12 ++++++++++--
 resources/lib/VideoNodes.py  | 12 ++++++++++--
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/resources/lib/LibrarySync.py b/resources/lib/LibrarySync.py
index abd80c44..46235165 100644
--- a/resources/lib/LibrarySync.py
+++ b/resources/lib/LibrarySync.py
@@ -236,6 +236,15 @@ class LibrarySync(threading.Thread):
             allEmbyMovies = ReadEmbyDB().getMovies(view.get('id'))
             allKodiMovies = ReadKodiDB().getKodiMovies(connection, cursor)
             
+            for kodimovie in allKodiMovies:
+                allKodiMovieIds.append(kodimovie[1])
+            
+            title = view.get('title')
+            content = view.get('content')
+
+            if content == "mixed":
+                title = "%s - Movies" % title
+            
             for kodimovie in allKodiMovies:
                 allKodiMovieIds.append(kodimovie[1])
             
@@ -263,10 +272,10 @@ class LibrarySync(threading.Thread):
                             kodiMovie = kodimovie
                           
                     if kodiMovie == None:
-                        WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
+                        WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, title)
                     else:
                         if kodiMovie[2] != API().getChecksum(item):
-                            WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
+                            WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, title)
           
           
        
@@ -367,6 +376,12 @@ class LibrarySync(threading.Thread):
             allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'))
             allKodiTvShows = ReadKodiDB().getKodiTvShows(connection, cursor)
             
+            title = view.get('title')
+            content = view.get('content')
+
+            if content == "mixed":
+                title = "%s - TV Shows" % title
+            
             total = len(allEmbyTvShows) + 1
             count = 1
             
@@ -396,11 +411,11 @@ class LibrarySync(threading.Thread):
                           
                     if kodiShow == None:
                         # Tv show doesn't exist in Kodi yet so proceed and add it
-                        WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
+                        WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, title)
                     else:
                         # If there are changes to the item, perform a full sync of the item
                         if kodiShow[2] != API().getChecksum(item):
-                            WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
+                            WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, title)
                             
                     #### PROCESS EPISODES ######
                     self.EpisodesFullSync(connection,cursor,item["Id"])
diff --git a/resources/lib/ReadEmbyDB.py b/resources/lib/ReadEmbyDB.py
index 37bea6de..6bb9a6c0 100644
--- a/resources/lib/ReadEmbyDB.py
+++ b/resources/lib/ReadEmbyDB.py
@@ -291,13 +291,21 @@ class ReadEmbyDB():
             for item in result:
                 if item['RecursiveItemCount']:
                     name = item['Name']
-                    itemtype = item.get('CollectionType', "movies")
+                    itemtype = item.get('CollectionType')
+                    content = itemtype
+
+                    if itemtype is None and type in ("movies", "tvshows"):
+                        # Mixed content or rich presentation is disabled
+                        itemtype = type
+                        content = "mixed"
 
                     if itemtype == type and name != "Collections":
                         collections.append({
+                            
                             'title': name,
                             'type': itemtype,
-                            'id': item['Id']
+                            'id': item['Id'],
+                            'content': content
                         })
 
         return collections
diff --git a/resources/lib/VideoNodes.py b/resources/lib/VideoNodes.py
index 57772d09..0e1089d5 100644
--- a/resources/lib/VideoNodes.py
+++ b/resources/lib/VideoNodes.py
@@ -331,13 +331,21 @@ class VideoNodes():
             views_movies = ReadEmbyDB().getCollections("movies")
             if views_movies:
                 for view in views_movies:
-                    self.buildVideoNodeForView(view.get('title'), "movies", totalNodesCount)
+                    title = view.get('title')
+                    content = view.get('content')
+                    if content == "mixed":
+                        title = "%s - Movies" % title
+                    self.buildVideoNodeForView(title, "movies", totalNodesCount)
                     totalNodesCount +=1
                     
             views_shows = ReadEmbyDB().getCollections("tvshows")
             if views_shows:
                 for view in views_shows:
-                    self.buildVideoNodeForView(view.get('title'), "tvshows", totalNodesCount)
+                    title = view.get('title')
+                    content = view.get('content')
+                    if content == "mixed":
+                        title = "%s - TV Shows" % title
+                    self.buildVideoNodeForView(title, "tvshows", totalNodesCount)
                     totalNodesCount +=1
 
             #create tag node for emby channels