FINAL fix for the doubled episodes.

Yeah for real now :-)
This commit is contained in:
Marcel van der Veldt 2015-03-30 00:43:53 +02:00
parent debac27631
commit 4458fa6fda
4 changed files with 37 additions and 21 deletions

View file

@ -48,13 +48,13 @@ class CreateFiles():
if item_type == "Episode":
itemPath = os.path.join(tvLibrary,item["SeriesId"])
if str(item.get("IndexNumber")) != None:
filenamestr = self.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm"
filenamestr = utils.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").strm"
else:
filenamestr = self.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S0E0 " + self.CleanName(utils.convertEncoding(item.get("Name"))) + " (" + item["Id"] + ").strm"
filenamestr = utils.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S0E0 " + utils.CleanName(utils.convertEncoding(item.get("Name"))) + " (" + item["Id"] + ").strm"
strmFile = os.path.join(itemPath,filenamestr)
changes = False
if not xbmcvfs.exists(strmFile) and not xbmcvfs.exists(strmFile.replace(".strm",".emby")):
if not xbmcvfs.exists(strmFile):
changes = True
xbmcvfs.mkdir(itemPath)
text_file = open(strmFile, "w")
@ -108,9 +108,9 @@ class CreateFiles():
if item_type == "Episode":
itemPath = os.path.join(tvLibrary,item["SeriesId"])
if str(item.get("ParentIndexNumber")) != None:
filenamestr = self.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo"
filenamestr = utils.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S" + str(item.get("ParentIndexNumber")) + "E" + str(item.get("IndexNumber")) + " (" + item["Id"] + ").nfo"
else:
filenamestr = self.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S0E0 " + self.CleanName(utils.convertEncoding(item["Name"])) + " (" + item["Id"] + ").nfo"
filenamestr = utils.CleanName(utils.convertEncoding(item.get("SeriesName"))) + " S0E0 " + utils.CleanName(utils.convertEncoding(item["Name"])) + " (" + item["Id"] + ").nfo"
nfoFile = os.path.join(itemPath,filenamestr)
rootelement = "episodedetails"
@ -333,8 +333,5 @@ class CreateFiles():
fanartFile = os.path.join(fanartDir,"fanart" + str(index) + ".jpg")
xbmcvfs.copy(backgroundUrl,fanartFile)
def CleanName(self, filename):
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')
return ''.join(c for c in cleanedFilename if c in validFilenameChars)

View file

@ -541,6 +541,7 @@ class LibrarySync():
episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
kodiEpisodes = None
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
if allKodiTVShows != None:
kodishow = allKodiTVShows.get(tvshow,None)
if kodishow != None:

View file

@ -13,6 +13,8 @@ import pstats
import time
import inspect
import sqlite3
import string
import unicodedata
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
from xml.etree import ElementTree
from xml.dom import minidom
@ -243,6 +245,9 @@ def stopProfiling(pr, profileName):
f.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
f.close()
def CleanName(filename):
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
cleanedFilename = unicodedata.normalize('NFKD', filename).encode('ASCII', 'ignore')
return ''.join(c for c in cleanedFilename if c in validFilenameChars)

View file

@ -407,9 +407,15 @@ class WriteKodiDB():
#update/check all artwork
changes |= self.updateArtWork(KodiItem,MBitem)
#set Filename
#set Filename (also submit strmfilepath to rename that if path has changed to original location)
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode")
itemPath = os.path.join(tvLibrary,MBitem["SeriesId"])
if str(MBitem.get("IndexNumber")) != None:
filenamestr = utils.CleanName(utils.convertEncoding(MBitem.get("SeriesName"))) + " S" + str(MBitem.get("ParentIndexNumber")) + "E" + str(MBitem.get("IndexNumber")) + " (" + MBitem["Id"] + ").strm"
else:
filenamestr = utils.CleanName(utils.convertEncoding(MBitem.get("SeriesName"))) + " S0E0 " + utils.CleanName(utils.convertEncoding(MBitem.get("Name"))) + " (" + MBitem["Id"] + ").strm"
strmFile = os.path.join(itemPath,filenamestr)
self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode", strmFile)
#update common properties
duration = (int(timeInfo.get('Duration'))*60)
@ -775,8 +781,7 @@ class WriteKodiDB():
xbmc.sleep(100)
utils.logMsg("episode deleted succesfully!",episodeid)
else:
utils.logMsg("episode not found in kodi DB",episodeid)
utils.logMsg("episode not found in kodi DB",episodeid)
def addTVShowToKodiLibrary( self, item ):
itemPath = os.path.join(tvLibrary,item["Id"])
@ -866,8 +871,7 @@ class WriteKodiDB():
connection.commit()
cursor.close()
def setKodiFilename(self, id, oldFileName, newFileName, fileType):
def setKodiFilename(self, id, oldFileName, newFileName, fileType, strmFile=None):
#use sqlite to set the filename in DB -- needed to avoid problems with resumepoints etc
#todo --> submit PR to kodi team to get this added to the jsonrpc api
#todo --> extend support for musicvideos
@ -887,6 +891,10 @@ class WriteKodiDB():
cursor = connection.cursor( )
utils.logMsg("MB3 Sync","setting filename in kodi db..." + fileType + ": " + str(id))
try:
print oldFileName
except:
pass
if fileType == "tvshow":
#for tvshows we only store the path in DB
@ -942,11 +950,16 @@ class WriteKodiDB():
finally:
cursor.close()
#rename the old strmfile to prevent Kodi from scanning it again
if oldFileName.endswith(".strm"):
if xbmcvfs.exists(oldFileName):
oldFileName_renamed = oldFileName.replace(".strm",".emby")
xbmcvfs.rename(oldFileName,oldFileName_renamed)
#rename the old strmfile to prevent Kodi from scanning it again
if strmFile != None:
filename = strmFile
else:
filename = oldFileName
if filename.endswith(".strm"):
if xbmcvfs.exists(filename):
oldFileName_renamed = filename.replace(".strm",".emby")
xbmcvfs.rename(filename,oldFileName_renamed)
def AddActorsToMedia(self, KodiItem, people, mediatype):