Added tags for TV collections
This commit is contained in:
parent
b880555829
commit
b5e2e0948e
4 changed files with 386 additions and 369 deletions
|
@ -287,8 +287,18 @@ class LibrarySync():
|
||||||
totalItemsAdded = 0
|
totalItemsAdded = 0
|
||||||
totalItemsUpdated = 0
|
totalItemsUpdated = 0
|
||||||
totalItemsDeleted = 0
|
totalItemsDeleted = 0
|
||||||
|
allTVShows = list()
|
||||||
|
allMB3EpisodeIds = list() #for use with deletions
|
||||||
|
|
||||||
progressTitle = "Sync DB : Processing Episodes"
|
views = ReadEmbyDB().getCollections("tvshows")
|
||||||
|
viewCount = len(views)
|
||||||
|
viewCurrent = 1
|
||||||
|
progressTitle = ""
|
||||||
|
|
||||||
|
for view in views:
|
||||||
|
|
||||||
|
|
||||||
|
progressTitle = "Sync DB : Processing " + view.get('title') + " " + str(viewCurrent) + " of " + str(viewCount)
|
||||||
|
|
||||||
# incremental sync --> new episodes only
|
# incremental sync --> new episodes only
|
||||||
if not fullsync:
|
if not fullsync:
|
||||||
|
@ -326,7 +336,6 @@ class LibrarySync():
|
||||||
progressAction = "Checking"
|
progressAction = "Checking"
|
||||||
if not matchFound:
|
if not matchFound:
|
||||||
#no match so we have to create it
|
#no match so we have to create it
|
||||||
print "creating episode in incremental sync!"
|
|
||||||
WriteKodiDB().addEpisodeToKodiLibrary(episode,connection, cursor)
|
WriteKodiDB().addEpisodeToKodiLibrary(episode,connection, cursor)
|
||||||
progressAction = "Adding"
|
progressAction = "Adding"
|
||||||
totalItemsAdded += 1
|
totalItemsAdded += 1
|
||||||
|
@ -380,11 +389,9 @@ class LibrarySync():
|
||||||
|
|
||||||
# full sync --> Tv shows and Episodes
|
# full sync --> Tv shows and Episodes
|
||||||
if fullsync:
|
if fullsync:
|
||||||
allTVShows = list()
|
|
||||||
allMB3EpisodeIds = list() #for use with deletions
|
|
||||||
allKodiEpisodeIds = [] # for use with deletions
|
allKodiEpisodeIds = [] # for use with deletions
|
||||||
|
viewTVShows = list()
|
||||||
tvShowData = ReadEmbyDB().getTVShows(True,True)
|
tvShowData = ReadEmbyDB().getTVShows(id = view.get('id') , fullinfo = True, fullSync = True)
|
||||||
allKodiIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
allKodiIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
|
@ -402,6 +409,9 @@ class LibrarySync():
|
||||||
for item in tvShowData:
|
for item in tvShowData:
|
||||||
if item.get('IsFolder'):
|
if item.get('IsFolder'):
|
||||||
allTVShows.append(item["Id"])
|
allTVShows.append(item["Id"])
|
||||||
|
viewTVShows.append(item["Id"])
|
||||||
|
item['Tag'] = []
|
||||||
|
item['Tag'].append(view.get('title'))
|
||||||
progMessage = "Processing"
|
progMessage = "Processing"
|
||||||
if item["Id"] not in allKodiIds:
|
if item["Id"] not in allKodiIds:
|
||||||
WriteKodiDB().addTVShowToKodiLibrary(item,connection, cursor)
|
WriteKodiDB().addTVShowToKodiLibrary(item,connection, cursor)
|
||||||
|
@ -419,11 +429,11 @@ class LibrarySync():
|
||||||
#process episodes first before updating tvshows
|
#process episodes first before updating tvshows
|
||||||
allEpisodes = list()
|
allEpisodes = list()
|
||||||
|
|
||||||
showTotal = len(allTVShows)
|
showTotal = len(viewTVShows)
|
||||||
showCurrent = 1
|
showCurrent = 1
|
||||||
|
|
||||||
# do episode adds
|
# do episode adds
|
||||||
for tvshow in allTVShows:
|
for tvshow in viewTVShows:
|
||||||
|
|
||||||
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
|
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
|
||||||
|
@ -485,14 +495,15 @@ class LibrarySync():
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
progressTitle = "Sync DB : Processing TV Shows"
|
progressTitle = "Sync DB : Processing TV Shows"
|
||||||
pDialog.update(0, progressTitle, "")
|
pDialog.update(0, progressTitle, "")
|
||||||
total = len(allTVShows) + 1
|
total = len(viewTVShows) + 1
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
#process updates at TV Show level
|
#process updates at TV Show level
|
||||||
allKodiTVShows = ReadKodiDB().getKodiTvShows(True)
|
allKodiTVShows = ReadKodiDB().getKodiTvShows(True)
|
||||||
for item in tvShowData:
|
for item in tvShowData:
|
||||||
if item.get('IsFolder'):
|
if item.get('IsFolder'):
|
||||||
|
item['Tag'] = []
|
||||||
|
item['Tag'].append(view.get('title'))
|
||||||
if allKodiTVShows != None:
|
if allKodiTVShows != None:
|
||||||
kodishow = allKodiTVShows.get(item["Id"],None)
|
kodishow = allKodiTVShows.get(item["Id"],None)
|
||||||
else:
|
else:
|
||||||
|
@ -514,7 +525,7 @@ class LibrarySync():
|
||||||
|
|
||||||
# do episode updates
|
# do episode updates
|
||||||
showCurrent = 1
|
showCurrent = 1
|
||||||
for tvshow in allTVShows:
|
for tvshow in viewTVShows:
|
||||||
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
|
|
||||||
kodiEpisodes = None
|
kodiEpisodes = None
|
||||||
|
@ -581,9 +592,9 @@ class LibrarySync():
|
||||||
|
|
||||||
# DELETES -- EPISODES
|
# DELETES -- EPISODES
|
||||||
# process any deletes only at fullsync
|
# process any deletes only at fullsync
|
||||||
allMB3EpisodeIds = set(allMB3EpisodeIds)
|
allMB3EpisodeIdsSet = set(allMB3EpisodeIds)
|
||||||
for episode in allKodiEpisodeIds:
|
for episode in allKodiEpisodeIds:
|
||||||
if episode.get('episodeid') not in allMB3EpisodeIds:
|
if episode.get('episodeid') not in allMB3EpisodeIdsSet:
|
||||||
WINDOW.setProperty("embyid" + str(episode.get('episodeid')),"deleted")
|
WINDOW.setProperty("embyid" + str(episode.get('episodeid')),"deleted")
|
||||||
WriteKodiDB().deleteEpisodeFromKodiLibrary(episode.get('episodeid'),episode.get('tvshowid'))
|
WriteKodiDB().deleteEpisodeFromKodiLibrary(episode.get('episodeid'),episode.get('tvshowid'))
|
||||||
totalItemsDeleted += 1
|
totalItemsDeleted += 1
|
||||||
|
@ -834,8 +845,13 @@ class LibrarySync():
|
||||||
if processTvShows:
|
if processTvShows:
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
pDialog.update(0, "Processing TV Episodes", "")
|
pDialog.update(0, "Processing TV Episodes", "")
|
||||||
|
views = ReadEmbyDB().getCollections("tvshows")
|
||||||
|
viewCount = len(views)
|
||||||
|
viewCurrent = 1
|
||||||
|
progressTitle = ""
|
||||||
|
for view in views:
|
||||||
|
|
||||||
tvshowData = ReadEmbyDB().getTVShows(fullinfo = False, fullSync = True)
|
tvshowData = ReadEmbyDB().getTVShows(id = view.get('id'), fullinfo = False, fullSync = True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -116,7 +116,7 @@ class ReadEmbyDB():
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def getTVShows(self, fullinfo = False, fullSync = False):
|
def getTVShows(self, id, fullinfo = False, fullSync = False):
|
||||||
result = None
|
result = None
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
|
@ -134,9 +134,9 @@ class ReadEmbyDB():
|
||||||
|
|
||||||
|
|
||||||
if fullinfo:
|
if fullinfo:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?' + sortstring + '&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + id + sortstring + '&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
||||||
else:
|
else:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?' + sortstring + '&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + id + sortstring + '&Fields=CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Series&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=0)
|
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=0)
|
||||||
if jsonData != None and jsonData != "":
|
if jsonData != None and jsonData != "":
|
||||||
|
@ -257,12 +257,12 @@ class ReadEmbyDB():
|
||||||
Temp = item.get("Name")
|
Temp = item.get("Name")
|
||||||
Name = Temp.encode('utf-8')
|
Name = Temp.encode('utf-8')
|
||||||
section = item.get("CollectionType")
|
section = item.get("CollectionType")
|
||||||
type = item.get("CollectionType")
|
itemtype = item.get("CollectionType")
|
||||||
if type == None:
|
if itemtype == None:
|
||||||
type = "None" # User may not have declared the type
|
itemtype = "None" # User may not have declared the type
|
||||||
if type == type and item.get("Name") != "Collections":
|
if itemtype == type and item.get("Name") != "Collections":
|
||||||
collections.append( {'title' : item.get("Name"),
|
collections.append( {'title' : item.get("Name"),
|
||||||
'type' : type,
|
'type' : itemtype,
|
||||||
'id' : item.get("Id")})
|
'id' : item.get("Id")})
|
||||||
return collections
|
return collections
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ class ReadKodiDB():
|
||||||
#returns all tvshows in Kodi db inserted by MB
|
#returns all tvshows in Kodi db inserted by MB
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
if fullInfo:
|
if fullInfo:
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "lastplayed", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "lastplayed", "file", "fanart", "tag"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
||||||
else:
|
else:
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["sorttitle", "title", "playcount", "lastplayed", "imdbnumber", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["sorttitle", "title", "playcount", "lastplayed", "imdbnumber", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
|
@ -158,7 +158,7 @@ class ReadKodiDB():
|
||||||
|
|
||||||
def getKodiTVShow(self, id):
|
def getKodiTVShow(self, id):
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "lastplayed", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "lastplayed", "premiered", "rating", "thumbnail", "playcount", "file", "fanart", "tag"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
|
||||||
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
jsonobject = json.loads(json_response.decode('utf-8','replace'))
|
||||||
tvshow = None
|
tvshow = None
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
|
|
|
@ -314,6 +314,7 @@ class WriteKodiDB():
|
||||||
premieredate = premieredatelist[0]
|
premieredate = premieredatelist[0]
|
||||||
changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
|
changes |= self.updateProperty(KodiItem,"premiered",premieredate,"tvshow")
|
||||||
|
|
||||||
|
changes |= self.updatePropertyArray(KodiItem,"tag",MBitem.get("Tag"),"tvshow")
|
||||||
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
|
changes |= self.updateProperty(KodiItem,"mpaa",MBitem.get("OfficialRating"),"tvshow")
|
||||||
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"tvshow")
|
changes |= self.updateProperty(KodiItem,"lastplayed",MBitem.get("LastPlayedDate"),"tvshow")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue