Add/Update TV Shows for Incremental TV Sync

This commit is contained in:
shaun 2015-04-16 10:44:43 +10:00
parent c72027f6a2
commit cde774fc9e
3 changed files with 122 additions and 98 deletions

View file

@ -299,11 +299,10 @@ class LibrarySync():
for view in views:
progressTitle = "Sync DB : Processing " + view.get('title') + " " + str(viewCurrent) + " of " + str(viewCount)
# incremental sync --> new episodes only
if not fullsync:
if fullsync == False:
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(fullinfo = True, itemList = itemList)
utils.logMsg("Sync TV", "Inc Sync Started on : " + str(len(latestMBEpisodes)) + " : " + str(itemList), 1)
@ -311,6 +310,38 @@ class LibrarySync():
if latestMBEpisodes != None:
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True))
# get included TV Shows
showList = []
for episode in latestMBEpisodes:
if(episode["SeriesId"] not in showList):
showList.append(episode["SeriesId"])
utils.logMsg("Incremental TV Sync", "Included TV Show List : " + str(showList), 0)
if(pDialog != None):
pDialog.update(0, progressTitle)
total = len(showList) + 1
count = 1
# process included TV Shows
for showID in showList:
embyTvShow = ReadEmbyDB().getFullItem(showID)
if(showID not in allKodiTvShowsIds):
utils.logMsg("Incremental TV Sync", "Adding TV Show : " + embyTvShow.get("Name"), 1)
WriteKodiDB().addTVShowToKodiLibrary(embyTvShow, connection, cursor)
kodiTvShow = ReadKodiDB().getKodiTVShow(showID)
utils.logMsg("Incremental TV Sync", "Updating TV Show : " + embyTvShow.get("Name"), 1)
WriteKodiDB().updateTVShowToKodiLibrary(embyTvShow, kodiTvShow, connection, cursor)
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, progressTitle, "Processing TV Shows : " + str(count))
count += 1
if(pDialog != None):
pDialog.update(0, progressTitle)
total = len(latestMBEpisodes) + 1
@ -318,9 +349,6 @@ class LibrarySync():
# process new episodes
for episode in latestMBEpisodes:
if episode["SeriesId"] in allKodiTvShowsIds:
#only process tvshows that already exist in the db at incremental updates
if(self.ShouldStop(pDialog)):
return False
@ -342,8 +370,8 @@ class LibrarySync():
count = 1
for episode in latestMBEpisodes:
if episode["SeriesId"] in allKodiTvShowsIds:
#only process tvshows that already exist in the db at incremental updates
if(self.ShouldStop(pDialog)):
return False
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
kodishow = allKodiTVShows.get(episode["SeriesId"],None)
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
@ -390,6 +418,7 @@ class LibrarySync():
total = len(tvShowData) + 1
count = 1
# add TV Shows
for item in tvShowData:
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
allTVShows.append(item["Id"])
@ -410,13 +439,42 @@ class LibrarySync():
pDialog.update(percentage, progressTitle, "Adding Tv Show: " + str(count))
count += 1
#process episodes first before updating tvshows
allEpisodes = list()
if(pDialog != None):
progressTitle = "Sync DB : Processing TV Shows"
pDialog.update(0, progressTitle, "")
total = len(viewTVShows) + 1
count = 1
# update TV Shows
allKodiTVShows = ReadKodiDB().getKodiTvShows(True)
for item in tvShowData:
if item.get('IsFolder'):
item['Tag'] = []
item['Tag'].append(view.get('title'))
if allKodiTVShows != None:
kodishow = allKodiTVShows.get(item["Id"],None)
else:
kodishow = None
if(kodishow != None):
updated = WriteKodiDB().updateTVShowToKodiLibrary(item,kodishow,connection, cursor)
if(updated):
totalItemsUpdated += 1
if(self.ShouldStop(pDialog)):
return False
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, progressTitle, "Updating Tv Show: " + str(count))
count += 1
showTotal = len(viewTVShows)
showCurrent = 1
# do episode adds
allEpisodes = list()
showTotal = len(viewTVShows)
showCurrent = 1
for tvshow in viewTVShows:
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
@ -447,38 +505,6 @@ class LibrarySync():
showCurrent += 1
if(pDialog != None):
progressTitle = "Sync DB : Processing TV Shows"
pDialog.update(0, progressTitle, "")
total = len(viewTVShows) + 1
count = 1
#process updates at TV Show level
allKodiTVShows = ReadKodiDB().getKodiTvShows(True)
for item in tvShowData:
if item.get('IsFolder'):
item['Tag'] = []
item['Tag'].append(view.get('title'))
if allKodiTVShows != None:
kodishow = allKodiTVShows.get(item["Id"],None)
else:
kodishow = None
if(kodishow != None):
updated = WriteKodiDB().updateTVShowToKodiLibrary(item,kodishow,connection, cursor)
if(updated):
totalItemsUpdated += 1
if(self.ShouldStop(pDialog)):
return False
# update progress bar
if(pDialog != None):
percentage = int(((float(count) / float(total)) * 100))
pDialog.update(percentage, progressTitle, "Updating Tv Show: " + str(count))
count += 1
# do episode updates
showCurrent = 1
for tvshow in viewTVShows:

View file

@ -107,7 +107,7 @@ class ReadEmbyDB():
downloadUtils = DownloadUtils()
url = "%s/mediabrowser/Users/%s/Items/%s?format=json" % (server, userid, id)
url = "%s/mediabrowser/Users/%s/Items/%s?format=json&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview" % (server, userid, id)
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=1 )
if jsonData != None and jsonData != "":
result = json.loads(jsonData)

View file

@ -303,7 +303,6 @@ class WriteKodiDB():
changes = False
#set Filename
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
#make sure that the path always ends with a slash
@ -330,10 +329,8 @@ class WriteKodiDB():
changes |= self.updateProperty(KodiItem,"title",utils.convertEncoding(MBitem["Name"]),"tvshow")
changes |= self.updateProperty(KodiItem,"plot",utils.convertEncoding(API().getOverview(MBitem)),"tvshow")
if MBitem.get("ProviderIds") != None:
if MBitem.get("ProviderIds").get("Imdb") != None:
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"tvshow")
# we use this to store the Emby ID so make sure we use that
changes |= self.updateProperty(KodiItem, "imdbnumber", MBitem.get("Id"), "tvshow")
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
@ -672,7 +669,7 @@ class WriteKodiDB():
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
pendingChanges = False
if propertyCollection != None:
if (propertyCollection != None and KodiItem.get(propertyName) != None):
currentvalues = set(KodiItem[propertyName])
for item in propertyCollection:
if not item in currentvalues:
@ -944,6 +941,7 @@ class WriteKodiDB():
season = 0
if MBitem.get("ParentIndexNumber") != None:
season = int(MBitem.get("ParentIndexNumber"))
else:
utils.logMsg("Emby","Error adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
return False