mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Add/Update TV Shows for Incremental TV Sync
This commit is contained in:
parent
c72027f6a2
commit
cde774fc9e
3 changed files with 122 additions and 98 deletions
|
@ -299,11 +299,10 @@ class LibrarySync():
|
||||||
|
|
||||||
for view in views:
|
for view in views:
|
||||||
|
|
||||||
|
|
||||||
progressTitle = "Sync DB : Processing " + view.get('title') + " " + str(viewCurrent) + " of " + str(viewCount)
|
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 fullsync == False:
|
||||||
|
|
||||||
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(fullinfo = True, itemList = itemList)
|
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(fullinfo = True, itemList = itemList)
|
||||||
utils.logMsg("Sync TV", "Inc Sync Started on : " + str(len(latestMBEpisodes)) + " : " + str(itemList), 1)
|
utils.logMsg("Sync TV", "Inc Sync Started on : " + str(len(latestMBEpisodes)) + " : " + str(itemList), 1)
|
||||||
|
@ -311,28 +310,57 @@ class LibrarySync():
|
||||||
if latestMBEpisodes != None:
|
if latestMBEpisodes != None:
|
||||||
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
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):
|
if(pDialog != None):
|
||||||
pDialog.update(0, progressTitle)
|
pDialog.update(0, progressTitle)
|
||||||
total = len(latestMBEpisodes) + 1
|
total = len(latestMBEpisodes) + 1
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
# process new episodes
|
# process new episodes
|
||||||
for episode in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
if(self.ShouldStop(pDialog)):
|
||||||
#only process tvshows that already exist in the db at incremental updates
|
return False
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
WriteKodiDB().addEpisodeToKodiLibrary(episode, connection, cursor)
|
||||||
return False
|
progressAction = "Adding"
|
||||||
|
totalItemsAdded += 1
|
||||||
WriteKodiDB().addEpisodeToKodiLibrary(episode, connection, cursor)
|
|
||||||
progressAction = "Adding"
|
# update progress bar
|
||||||
totalItemsAdded += 1
|
if(pDialog != None):
|
||||||
|
percentage = int(((float(count) / float(total)) * 100))
|
||||||
# update progress bar
|
pDialog.update(percentage, progressTitle, progressAction + " Episode: " + str(count))
|
||||||
if(pDialog != None):
|
count += 1
|
||||||
percentage = int(((float(count) / float(total)) * 100))
|
|
||||||
pDialog.update(percentage, progressTitle, progressAction + " Episode: " + str(count))
|
|
||||||
count += 1
|
|
||||||
|
|
||||||
#process updates
|
#process updates
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
|
@ -342,34 +370,34 @@ class LibrarySync():
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
for episode in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
if(self.ShouldStop(pDialog)):
|
||||||
#only process tvshows that already exist in the db at incremental updates
|
return False
|
||||||
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
|
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
|
||||||
kodishow = allKodiTVShows.get(episode["SeriesId"],None)
|
kodishow = allKodiTVShows.get(episode["SeriesId"],None)
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(kodishow["tvshowid"],True,True)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
userData = API().getUserData(episode)
|
userData = API().getUserData(episode)
|
||||||
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
|
WINDOW.setProperty("EmbyUserKey" + userData.get("Key"), episode.get('Id') + ";;" + episode.get("Type"))
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||||
|
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
KodiItem = kodiEpisodes.get(comparestring1, None)
|
KodiItem = kodiEpisodes.get(comparestring1, None)
|
||||||
if(KodiItem != None):
|
if(KodiItem != None):
|
||||||
WriteKodiDB().updateEpisodeToKodiLibrary(episode, KodiItem, connection, cursor)
|
WriteKodiDB().updateEpisodeToKodiLibrary(episode, KodiItem, connection, cursor)
|
||||||
|
|
||||||
if(self.ShouldStop(pDialog)):
|
if(self.ShouldStop(pDialog)):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# update progress bar
|
# update progress bar
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
percentage = int(((float(count) / float(total)) * 100))
|
percentage = int(((float(count) / float(total)) * 100))
|
||||||
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
|
pDialog.update(percentage, progressTitle, "Updating Episode: " + str(count))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
# full sync --> Tv shows and Episodes
|
# full sync --> Tv shows and Episodes
|
||||||
|
@ -390,6 +418,7 @@ class LibrarySync():
|
||||||
total = len(tvShowData) + 1
|
total = len(tvShowData) + 1
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
|
# add TV Shows
|
||||||
for item in tvShowData:
|
for item in tvShowData:
|
||||||
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
|
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
|
||||||
allTVShows.append(item["Id"])
|
allTVShows.append(item["Id"])
|
||||||
|
@ -410,13 +439,42 @@ class LibrarySync():
|
||||||
pDialog.update(percentage, progressTitle, "Adding Tv Show: " + str(count))
|
pDialog.update(percentage, progressTitle, "Adding Tv Show: " + str(count))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
#process episodes first before updating tvshows
|
if(pDialog != None):
|
||||||
allEpisodes = list()
|
progressTitle = "Sync DB : Processing TV Shows"
|
||||||
|
pDialog.update(0, progressTitle, "")
|
||||||
showTotal = len(viewTVShows)
|
total = len(viewTVShows) + 1
|
||||||
showCurrent = 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
|
||||||
|
|
||||||
|
|
||||||
# do episode adds
|
# do episode adds
|
||||||
|
allEpisodes = list()
|
||||||
|
showTotal = len(viewTVShows)
|
||||||
|
showCurrent = 1
|
||||||
for tvshow in viewTVShows:
|
for tvshow in viewTVShows:
|
||||||
|
|
||||||
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
|
||||||
|
@ -447,38 +505,6 @@ class LibrarySync():
|
||||||
|
|
||||||
showCurrent += 1
|
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
|
# do episode updates
|
||||||
showCurrent = 1
|
showCurrent = 1
|
||||||
for tvshow in viewTVShows:
|
for tvshow in viewTVShows:
|
||||||
|
|
|
@ -107,7 +107,7 @@ class ReadEmbyDB():
|
||||||
|
|
||||||
downloadUtils = DownloadUtils()
|
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 )
|
jsonData = downloadUtils.downloadUrl(url, suppress=False, popup=1 )
|
||||||
if jsonData != None and jsonData != "":
|
if jsonData != None and jsonData != "":
|
||||||
result = json.loads(jsonData)
|
result = json.loads(jsonData)
|
||||||
|
|
|
@ -285,7 +285,7 @@ class WriteKodiDB():
|
||||||
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
|
||||||
def updateTVShowToKodiLibrary( self, MBitem, KodiItem,connection, cursor ):
|
def updateTVShowToKodiLibrary( self, MBitem, KodiItem,connection, cursor ):
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
addon = xbmcaddon.Addon(id='plugin.video.emby')
|
||||||
port = addon.getSetting('port')
|
port = addon.getSetting('port')
|
||||||
host = addon.getSetting('ipaddress')
|
host = addon.getSetting('ipaddress')
|
||||||
|
@ -303,22 +303,21 @@ class WriteKodiDB():
|
||||||
|
|
||||||
changes = False
|
changes = False
|
||||||
|
|
||||||
|
|
||||||
#set Filename
|
#set Filename
|
||||||
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
||||||
#make sure that the path always ends with a slash
|
#make sure that the path always ends with a slash
|
||||||
playurl = playurl + "/"
|
playurl = playurl + "/"
|
||||||
self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow", MBitem["Id"], connection, cursor)
|
self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow", MBitem["Id"], connection, cursor)
|
||||||
|
|
||||||
#update/check all artwork
|
#update/check all artwork
|
||||||
changes |= self.updateArtWork(KodiItem,MBitem)
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
||||||
|
|
||||||
#update common properties
|
#update common properties
|
||||||
if MBitem.get("PremiereDate") != None:
|
if MBitem.get("PremiereDate") != None:
|
||||||
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
premieredatelist = (MBitem.get("PremiereDate")).split("T")
|
||||||
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.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")
|
||||||
|
@ -330,10 +329,8 @@ class WriteKodiDB():
|
||||||
changes |= self.updateProperty(KodiItem,"title",utils.convertEncoding(MBitem["Name"]),"tvshow")
|
changes |= self.updateProperty(KodiItem,"title",utils.convertEncoding(MBitem["Name"]),"tvshow")
|
||||||
changes |= self.updateProperty(KodiItem,"plot",utils.convertEncoding(API().getOverview(MBitem)),"tvshow")
|
changes |= self.updateProperty(KodiItem,"plot",utils.convertEncoding(API().getOverview(MBitem)),"tvshow")
|
||||||
|
|
||||||
|
# we use this to store the Emby ID so make sure we use that
|
||||||
if MBitem.get("ProviderIds") != None:
|
changes |= self.updateProperty(KodiItem, "imdbnumber", MBitem.get("Id"), "tvshow")
|
||||||
if MBitem.get("ProviderIds").get("Imdb") != None:
|
|
||||||
changes |= self.updateProperty(KodiItem,"imdbnumber",MBitem.get("ProviderIds").get("Imdb"),"tvshow")
|
|
||||||
|
|
||||||
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
|
changes |= self.updatePropertyArray(KodiItem,"genre",MBitem.get("Genres"),"tvshow")
|
||||||
|
|
||||||
|
@ -343,7 +340,7 @@ class WriteKodiDB():
|
||||||
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"tvshow")
|
changes |= self.updatePropertyArray(KodiItem,"studio",studios,"tvshow")
|
||||||
|
|
||||||
# FIXME --> ProductionLocations not returned by MB3 server !?
|
# FIXME --> ProductionLocations not returned by MB3 server !?
|
||||||
changes |= self.updatePropertyArray(KodiItem,"country",MBitem.get("ProductionLocations"),"tvshow")
|
changes |= self.updatePropertyArray(KodiItem, "country", MBitem.get("ProductionLocations"), "tvshow")
|
||||||
|
|
||||||
#add actors
|
#add actors
|
||||||
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"tvshow", connection, cursor)
|
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"),"tvshow", connection, cursor)
|
||||||
|
@ -353,7 +350,7 @@ class WriteKodiDB():
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem, connection, cursor ):
|
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem, connection, cursor ):
|
||||||
|
@ -672,7 +669,7 @@ class WriteKodiDB():
|
||||||
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
|
jsoncommand = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": %i, "%s": %s}, "id": 1 }'
|
||||||
|
|
||||||
pendingChanges = False
|
pendingChanges = False
|
||||||
if propertyCollection != None:
|
if (propertyCollection != None and KodiItem.get(propertyName) != None):
|
||||||
currentvalues = set(KodiItem[propertyName])
|
currentvalues = set(KodiItem[propertyName])
|
||||||
for item in propertyCollection:
|
for item in propertyCollection:
|
||||||
if not item in currentvalues:
|
if not item in currentvalues:
|
||||||
|
@ -944,6 +941,7 @@ class WriteKodiDB():
|
||||||
season = 0
|
season = 0
|
||||||
if MBitem.get("ParentIndexNumber") != None:
|
if MBitem.get("ParentIndexNumber") != None:
|
||||||
season = int(MBitem.get("ParentIndexNumber"))
|
season = int(MBitem.get("ParentIndexNumber"))
|
||||||
|
else:
|
||||||
utils.logMsg("Emby","Error adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
utils.logMsg("Emby","Error adding episode to Kodi Library, no ParentIndexNumber - ID: " + MBitem["Id"] + " - " + MBitem["Name"])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue