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')
|
tvLibrary = os.path.join(dataPath,'tvshows')
|
||||||
|
|
||||||
class CreateFiles():
|
class CreateFiles():
|
||||||
def createSTRM(self,item,parentId=None):
|
def createSTRM(self,item):
|
||||||
|
|
||||||
item_type=str(item.get("Type")).encode('utf-8')
|
item_type=str(item.get("Type")).encode('utf-8')
|
||||||
if item_type == "Movie":
|
if item_type == "Movie":
|
||||||
|
@ -37,7 +37,7 @@ class CreateFiles():
|
||||||
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
strmFile = os.path.join(itemPath,item["Id"] + ".strm")
|
||||||
|
|
||||||
if item_type == "Episode":
|
if item_type == "Episode":
|
||||||
itemPath = os.path.join(tvLibrary,parentId)
|
itemPath = os.path.join(tvLibrary,item["SeriesId"])
|
||||||
if str(item.get("IndexNumber")) != None:
|
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"
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm"
|
||||||
else:
|
else:
|
||||||
|
@ -57,7 +57,7 @@ class CreateFiles():
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
|
|
||||||
def createNFO(self,item, parentId=None):
|
def createNFO(self,item):
|
||||||
downloadUtils = DownloadUtils()
|
downloadUtils = DownloadUtils()
|
||||||
timeInfo = API().getTimeInfo(item)
|
timeInfo = API().getTimeInfo(item)
|
||||||
userData=API().getUserData(item)
|
userData=API().getUserData(item)
|
||||||
|
@ -79,7 +79,7 @@ class CreateFiles():
|
||||||
nfoFile = os.path.join(itemPath,"tvshow.nfo")
|
nfoFile = os.path.join(itemPath,"tvshow.nfo")
|
||||||
rootelement = "tvshow"
|
rootelement = "tvshow"
|
||||||
if item_type == "Episode":
|
if item_type == "Episode":
|
||||||
itemPath = os.path.join(tvLibrary,parentId)
|
itemPath = os.path.join(tvLibrary,item["SeriesId"])
|
||||||
if str(item.get("ParentIndexNumber")) != None:
|
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"
|
filenamestr = self.CleanName(item.get("SeriesName")).encode('utf-8') + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -245,17 +245,17 @@ class LibrarySync():
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
# process new episodes
|
# process new episodes
|
||||||
for tvshow in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
if episode["SeriesId"] 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(episode["SeriesId"])
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber"))
|
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||||
matchFound = False
|
matchFound = False
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
for KodiItem in kodiEpisodes:
|
for KodiItem in kodiEpisodes:
|
||||||
|
@ -266,7 +266,7 @@ class LibrarySync():
|
||||||
|
|
||||||
if not matchFound:
|
if not matchFound:
|
||||||
#no match so we have to create it
|
#no match so we have to create it
|
||||||
WriteKodiDB().addEpisodeToKodiLibrary(tvshow,tvshow)
|
WriteKodiDB().addEpisodeToKodiLibrary(episode)
|
||||||
updateNeeded = True
|
updateNeeded = True
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -289,26 +289,24 @@ class LibrarySync():
|
||||||
total = len(latestMBEpisodes) + 1
|
total = len(latestMBEpisodes) + 1
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
for tvshow in latestMBEpisodes:
|
for episode in latestMBEpisodes:
|
||||||
if tvshow["SeriesId"] in allKodiTvShowsIds:
|
if episode["SeriesId"] 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(episode["SeriesId"])
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
#we have to compare the lists somehow
|
#we have to compare the lists somehow
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
comparestring1 = str(tvshow.get("ParentIndexNumber")) + "-" + str(tvshow.get("IndexNumber"))
|
comparestring1 = str(episode.get("ParentIndexNumber")) + "-" + str(episode.get("IndexNumber"))
|
||||||
|
|
||||||
if kodiEpisodes != None:
|
if kodiEpisodes != None:
|
||||||
for KodiItem in kodiEpisodes:
|
for KodiItem in kodiEpisodes:
|
||||||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||||
if comparestring1 == comparestring2:
|
if comparestring1 == comparestring2:
|
||||||
#match found - update episode
|
#match found - update episode
|
||||||
#WriteKodiDB().updateEpisodeToKodiLibrary(tvshow,KodiItem,tvshow)
|
WriteKodiDB().updateEpisodeToKodiLibrary(episode,KodiItem)
|
||||||
#TODO not sure but how to update the show
|
|
||||||
print "TODO: Actual do the update"
|
|
||||||
|
|
||||||
|
|
||||||
if(self.ShouldStop()):
|
if(self.ShouldStop()):
|
||||||
|
@ -402,14 +400,14 @@ class LibrarySync():
|
||||||
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
comparestring2 = str(KodiItem["season"]) + "-" + str(KodiItem["episode"])
|
||||||
if comparestring1 == comparestring2:
|
if comparestring1 == comparestring2:
|
||||||
#match found - update episode
|
#match found - update episode
|
||||||
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem,tvshow)
|
WriteKodiDB().updateEpisodeToKodiLibrary(item,KodiItem)
|
||||||
matchFound = True
|
matchFound = True
|
||||||
progMessage = "Updating"
|
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: "
|
print "episode not found...creating it: "
|
||||||
WriteKodiDB().addEpisodeToKodiLibrary(item,tvshow)
|
WriteKodiDB().addEpisodeToKodiLibrary(item)
|
||||||
updateNeeded = True
|
updateNeeded = True
|
||||||
progMessage = "Adding"
|
progMessage = "Adding"
|
||||||
|
|
||||||
|
|
|
@ -219,7 +219,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 updateEpisodeToKodiLibrary( self, MBitem, KodiItem, tvshowId ):
|
def updateEpisodeToKodiLibrary( self, MBitem, KodiItem ):
|
||||||
|
|
||||||
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
port = addon.getSetting('port')
|
port = addon.getSetting('port')
|
||||||
|
@ -271,8 +271,8 @@ class WriteKodiDB():
|
||||||
#add actors
|
#add actors
|
||||||
changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
changes = self.AddActorsToMedia(KodiItem,MBitem.get("People"),"episode")
|
||||||
|
|
||||||
CreateFiles().createNFO(MBitem, tvshowId)
|
CreateFiles().createNFO(MBitem)
|
||||||
CreateFiles().createSTRM(MBitem, tvshowId)
|
CreateFiles().createSTRM(MBitem)
|
||||||
|
|
||||||
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"])
|
||||||
|
@ -394,15 +394,15 @@ class WriteKodiDB():
|
||||||
if changes:
|
if changes:
|
||||||
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
utils.logMsg("MB3 Sync","Added movie to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||||
|
|
||||||
def addEpisodeToKodiLibrary(self, item, tvshowId):
|
def addEpisodeToKodiLibrary(self, item):
|
||||||
|
|
||||||
changes = False
|
changes = False
|
||||||
|
|
||||||
#create nfo file
|
#create nfo file
|
||||||
changes = CreateFiles().createNFO(item, tvshowId)
|
changes = CreateFiles().createNFO(item)
|
||||||
|
|
||||||
# create strm file
|
# create strm file
|
||||||
changes = CreateFiles().createSTRM(item, tvshowId)
|
changes = CreateFiles().createSTRM(item)
|
||||||
|
|
||||||
if changes:
|
if changes:
|
||||||
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
utils.logMsg("MB3 Sync","Added episode to Kodi Library",item["Id"] + " - " + item["Name"])
|
||||||
|
|
Loading…
Reference in a new issue