mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 18:26:15 +00:00
fixed incremental sync for tvshows
This commit is contained in:
parent
c2f25724a3
commit
b0c795bdf4
3 changed files with 22 additions and 24 deletions
|
@ -25,7 +25,7 @@ movieLibrary = os.path.join(dataPath,'movies')
|
|||
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||
|
||||
class CreateFiles():
|
||||
def createSTRM(self,item,parentId=None):
|
||||
def createSTRM(self,item):
|
||||
|
||||
item_type=str(item.get("Type")).encode('utf-8')
|
||||
if item_type == "Movie":
|
||||
|
@ -37,7 +37,7 @@ class CreateFiles():
|
|||
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
||||
|
||||
if item_type == "Episode":
|
||||
itemPath = os.path.join(tvLibrary,parentId)
|
||||
itemPath = os.path.join(tvLibrary,item["SeriesId"])
|
||||
if str(item.get("IndexNumber")) != None:
|
||||
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm"
|
||||
else:
|
||||
|
@ -57,7 +57,7 @@ class CreateFiles():
|
|||
|
||||
return changes
|
||||
|
||||
def createNFO(self,item, parentId=None):
|
||||
def createNFO(self,item):
|
||||
downloadUtils = DownloadUtils()
|
||||
timeInfo = API().getTimeInfo(item)
|
||||
userData=API().getUserData(item)
|
||||
|
@ -79,7 +79,7 @@ class CreateFiles():
|
|||
nfoFile = os.path.join(itemPath,"tvshow.nfo")
|
||||
rootelement = "tvshow"
|
||||
if item_type == "Episode":
|
||||
itemPath = os.path.join(tvLibrary,parentId)
|
||||
itemPath = os.path.join(tvLibrary,item["SeriesId"])
|
||||
if str(item.get("ParentIndexNumber")) != None:
|
||||
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo"
|
||||
else:
|
||||
|
|
|
@ -245,17 +245,17 @@ class LibrarySync():
|
|||
count = 1
|
||||
|
||||
# process new episodes
|
||||
for tvshow in latestMBEpisodes:
|
||||
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
||||
for episode in latestMBEpisodes:
|
||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
||||
#only process tvshows that already exist in the db at incremental updates
|
||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"])
|
||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"])
|
||||
|
||||
if(self.ShouldStop()):
|
||||
return True
|
||||
|
||||
#we have to compare the lists somehow
|
||||
xbmc.sleep(sleepVal)
|
||||
comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber"))
|
||||
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||
matchFound = False
|
||||
if kodiEpisodes != None:
|
||||
for KodiItem in kodiEpisodes:
|
||||
|
@ -266,7 +266,7 @@ class LibrarySync():
|
|||
|
||||
if not matchFound:
|
||||
#no match so we have to create it
|
||||
WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow)
|
||||
WriteKodiDB().addEpisodeToKodiLibrary(episode)
|
||||
updateNeeded = True
|
||||
|
||||
if(self.ShouldStop()):
|
||||
|
@ -289,26 +289,24 @@ class LibrarySync():
|
|||
total = len(latestMBEpisodes) + 1
|
||||
count = 1
|
||||
|
||||
for tvshow in latestMBEpisodes:
|
||||
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
||||
for episode in latestMBEpisodes:
|
||||
if episode["SeriesId"] in allKodiTvShowsIds:
|
||||
#only process tvshows that already exist in the db at incremental updates
|
||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(tvshow["SeriesId"])
|
||||
kodiEpisodes = ReadKodiDB().getKodiEpisodes(episode["SeriesId"])
|
||||
|
||||
if(self.ShouldStop()):
|
||||
return True
|
||||
|
||||
#we have to compare the lists somehow
|
||||
xbmc.sleep(sleepVal)
|
||||
comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber"))
|
||||
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||
|
||||
if kodiEpisodes != None:
|
||||
for KodiItem in kodiEpisodes:
|
||||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||
if comparestring1 == comparestring2:
|
||||
#match found - update episode
|
||||
#WriteKodiDB().updateEpisodeToKodiLibrary(tvshow,KodiItem,tvshow)
|
||||
#TODO not sure but how to update the show
|
||||
print "TODO: Actual do the update"
|
||||
WriteKodiDB().updateEpisodeToKodiLibrary(episode,KodiItem)
|
||||
|
||||
|
||||
if(self.ShouldStop()):
|
||||
|
@ -402,14 +400,14 @@ class LibrarySync():
|
|||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||
if comparestring1 == comparestring2:
|
||||
#match found - update episode
|
||||
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem,tvshow)
|
||||
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem)
|
||||
matchFound = True
|
||||
progMessage = "Updating"
|
||||
|
||||
if not matchFound:
|
||||
#no match so we have to create it
|
||||
print "episode not found...creating it: "
|
||||
WriteKodiDB().addEpisodeToKodiLibrary(item,tvshow)
|
||||
WriteKodiDB().addEpisodeToKodiLibrary(item)
|
||||
updateNeeded = True
|
||||
progMessage = "Adding"
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ class WriteKodiDB():
|
|||
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
||||
|
||||
|
||||
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem, tvshowId ):
|
||||
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem ):
|
||||
|
||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||
port = addon.getSetting('port')
|
||||
|
@ -271,8 +271,8 @@ class WriteKodiDB():
|
|||
#add actors
|
||||
changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
||||
|
||||
CreateFiles().createNFO(MBitem, tvshowId)
|
||||
CreateFiles().createSTRM(MBitem, tvshowId)
|
||||
CreateFiles().createNFO(MBitem)
|
||||
CreateFiles().createSTRM(MBitem)
|
||||
|
||||
if changes:
|
||||
utils.logMsg("Updated item to Kodi Library", MBitem["Id"] + " - " + MBitem["Name"])
|
||||
|
@ -394,15 +394,15 @@ class WriteKodiDB():
|
|||
if changes:
|
||||
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||
|
||||
def addEpisodeToKodiLibrary(self, item, tvshowId):
|
||||
def addEpisodeToKodiLibrary(self, item):
|
||||
|
||||
changes = False
|
||||
|
||||
#create nfo file
|
||||
changes = CreateFiles().createNFO(item, tvshowId)
|
||||
changes = CreateFiles().createNFO(item)
|
||||
|
||||
# create strm file
|
||||
changes = CreateFiles().createSTRM(item, tvshowId)
|
||||
changes = CreateFiles().createSTRM(item)
|
||||
|
||||
if changes:
|
||||
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||
|
|
Loading…
Reference in a new issue