mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
incremental episodes sync and new settings
This commit is contained in:
parent
380b934316
commit
deb0fa57c1
3 changed files with 57 additions and 19 deletions
|
@ -214,22 +214,23 @@ class LibrarySync():
|
||||||
|
|
||||||
# incremental sync --> new episodes only
|
# incremental sync --> new episodes only
|
||||||
if not fullsync:
|
if not fullsync:
|
||||||
latestMBEpisodes = ReadEmbyDB().getTVShows(True,True)
|
latestMBEpisodes = ReadEmbyDB().getLatestEpisodes(True)
|
||||||
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds())
|
allKodiTvShowsIds = set(ReadKodiDB().getKodiTvShowsIds(True))
|
||||||
|
|
||||||
|
updateNeeded = False
|
||||||
|
|
||||||
|
# process new episodes
|
||||||
for tvshow in latestMBEpisodes:
|
for tvshow in latestMBEpisodes:
|
||||||
|
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
||||||
if tvshow["ParentId"] in allKodiTvShowsIds:
|
|
||||||
#only process tvshows that already exist in the db at incremental updates
|
#only process tvshows that already exist in the db at incremental updates
|
||||||
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"])
|
||||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["ParentId"])
|
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if(pDialog != None):
|
if(pDialog != None):
|
||||||
pDialog.update(0, "Sync DB : Processing Episodes")
|
pDialog.update(0, "Sync DB : Processing Episodes")
|
||||||
total = len(episodeData) + 1
|
total = len(latestMBEpisodes) + 1
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
|
@ -240,17 +241,12 @@ class LibrarySync():
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
for KodiItem in kodiEpisodes:
|
for KodiItem in kodiEpisodes:
|
||||||
|
|
||||||
allEpisodes.append(KodiItem["episodeid"])
|
|
||||||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||||
if comparestring1 == comparestring2:
|
if comparestring1 == comparestring2:
|
||||||
#match found - update episode
|
|
||||||
WriteKodiDB().updateEpisodeToKodiLibrary(tvshow,KodiItem,tvshow)
|
|
||||||
matchFound = True
|
matchFound = True
|
||||||
progMessage = "Updating"
|
|
||||||
|
|
||||||
if not matchFound:
|
if not matchFound:
|
||||||
#no match so we have to create it
|
#no match so we have to create it
|
||||||
print "episode not found...creating it: "
|
|
||||||
WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow)
|
WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow)
|
||||||
updateNeeded = True
|
updateNeeded = True
|
||||||
progMessage = "Adding"
|
progMessage = "Adding"
|
||||||
|
@ -264,6 +260,48 @@ class LibrarySync():
|
||||||
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
#initiate library update and wait for finish before processing any updates
|
||||||
|
if updateNeeded:
|
||||||
|
self.doKodiLibraryUpdate()
|
||||||
|
updateNeeded = False
|
||||||
|
|
||||||
|
#process updates
|
||||||
|
for tvshow in latestMBEpisodes:
|
||||||
|
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
||||||
|
#only process tvshows that already exist in the db at incremental updates
|
||||||
|
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"])
|
||||||
|
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
if(pDialog != None):
|
||||||
|
pDialog.update(0, "Sync DB : Processing Episodes")
|
||||||
|
total = len(latestMBEpisodes) + 1
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
#we have to compare the lists somehow
|
||||||
|
xbmc.sleep(sleepVal)
|
||||||
|
comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber"))
|
||||||
|
progMessage = "Processing"
|
||||||
|
if kodiEpisodes != None:
|
||||||
|
for KodiItem in kodiEpisodes:
|
||||||
|
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||||
|
if comparestring1 == comparestring2:
|
||||||
|
#match found - update episode
|
||||||
|
|
||||||
|
progMessage = "Updating"
|
||||||
|
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
# update progress bar
|
||||||
|
if(pDialog != None):
|
||||||
|
percentage = int(((float(count) / float(total)) * 100))
|
||||||
|
pDialog.update(percentage, message=progMessage + " Episode: " + str(count))
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
|
||||||
# full sync --> Tv shows and Episodes
|
# full sync --> Tv shows and Episodes
|
||||||
if fullsync:
|
if fullsync:
|
||||||
allTVShows = list()
|
allTVShows = list()
|
||||||
|
|
|
@ -107,9 +107,9 @@ class ReadEmbyDB():
|
||||||
userid = downloadUtils.getUserId()
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
if fullinfo:
|
if fullinfo:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,AirTime,DateCreated,MediaStreams,People,Overview&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
else:
|
else:
|
||||||
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
url = server + '/mediabrowser/Users/' + userid + '/Items?Limit=20&SortBy=DateCreated&IsVirtualUnaired=false&IsMissing=False&Fields=ParentId,Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Descending&IncludeItemTypes=Episode&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ class ReadKodiDB():
|
||||||
filepath = filepath.split(os.sep)[0]
|
filepath = filepath.split(os.sep)[0]
|
||||||
id = filepath
|
id = filepath
|
||||||
else:
|
else:
|
||||||
id = str(kodimovie["movieid"])
|
id = str(kodishow["tvshowid"])
|
||||||
allKodiTvShowsIds.append(id)
|
allKodiTvShowsIds.append(id)
|
||||||
|
|
||||||
return allKodiTvShowsIds
|
return allKodiTvShowsIds
|
||||||
|
@ -98,7 +98,7 @@ class ReadKodiDB():
|
||||||
if(jsonobject.has_key('result')):
|
if(jsonobject.has_key('result')):
|
||||||
result = jsonobject['result']
|
result = jsonobject['result']
|
||||||
if(result.has_key('tvshows')):
|
if(result.has_key('tvshows')):
|
||||||
movies = result['tvshows']
|
tvshows = result['tvshows']
|
||||||
|
|
||||||
return tvshows
|
return tvshows
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue