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": if item_type == "Episode":
itemPath = os.path.join(tvLibrary,item["SeriesId"]) itemPath = os.path.join(tvLibrary,item["SeriesId"])
if str(item.get("IndexNumber")) != None: 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: 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) strmFile = os.path.join(itemPath,filenamestr)
changes = False changes = False
if not xbmcvfs.exists(strmFile) and not xbmcvfs.exists(strmFile.replace(".strm",".emby")): if not xbmcvfs.exists(strmFile):
changes = True changes = True
xbmcvfs.mkdir(itemPath) xbmcvfs.mkdir(itemPath)
text_file = open(strmFile, "w") text_file = open(strmFile, "w")
@ -108,9 +108,9 @@ class CreateFiles():
if item_type == "Episode": if item_type == "Episode":
itemPath = os.path.join(tvLibrary,item["SeriesId"]) itemPath = os.path.join(tvLibrary,item["SeriesId"])
if str(item.get("ParentIndexNumber")) != None: 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: 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) nfoFile = os.path.join(itemPath,filenamestr)
rootelement = "episodedetails" rootelement = "episodedetails"
@ -333,8 +333,5 @@ class CreateFiles():
fanartFile = os.path.join(fanartDir,"fanart" + str(index) + ".jpg") fanartFile = os.path.join(fanartDir,"fanart" + str(index) + ".jpg")
xbmcvfs.copy(backgroundUrl,fanartFile) 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) episodeData = ReadEmbyDB().getEpisodes(tvshow,True)
kodiEpisodes = None kodiEpisodes = None
allKodiTVShows = ReadKodiDB().getKodiTvShows(False)
if allKodiTVShows != None: if allKodiTVShows != None:
kodishow = allKodiTVShows.get(tvshow,None) kodishow = allKodiTVShows.get(tvshow,None)
if kodishow != None: if kodishow != None:

View file

@ -13,6 +13,8 @@ import pstats
import time import time
import inspect import inspect
import sqlite3 import sqlite3
import string
import unicodedata
from xml.etree.ElementTree import Element, SubElement, Comment, tostring from xml.etree.ElementTree import Element, SubElement, Comment, tostring
from xml.etree import ElementTree from xml.etree import ElementTree
from xml.dom import minidom 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.write(str(ncalls) + "\t" + "{0}".format(total_time) + "\t" + "{0}".format(cumulative_time) + "\t" + func_name + "\t" + filename + "\r\n")
f.close() 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 #update/check all artwork
changes |= self.updateArtWork(KodiItem,MBitem) 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) 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 #update common properties
duration = (int(timeInfo.get('Duration'))*60) duration = (int(timeInfo.get('Duration'))*60)
@ -777,7 +783,6 @@ class WriteKodiDB():
else: else:
utils.logMsg("episode not found in kodi DB",episodeid) utils.logMsg("episode not found in kodi DB",episodeid)
def addTVShowToKodiLibrary( self, item ): def addTVShowToKodiLibrary( self, item ):
itemPath = os.path.join(tvLibrary,item["Id"]) itemPath = os.path.join(tvLibrary,item["Id"])
@ -866,8 +871,7 @@ class WriteKodiDB():
connection.commit() connection.commit()
cursor.close() cursor.close()
def setKodiFilename(self, id, oldFileName, newFileName, fileType, strmFile=None):
def setKodiFilename(self, id, oldFileName, newFileName, fileType):
#use sqlite to set the filename in DB -- needed to avoid problems with resumepoints etc #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 --> submit PR to kodi team to get this added to the jsonrpc api
#todo --> extend support for musicvideos #todo --> extend support for musicvideos
@ -887,6 +891,10 @@ class WriteKodiDB():
cursor = connection.cursor( ) cursor = connection.cursor( )
utils.logMsg("MB3 Sync","setting filename in kodi db..." + fileType + ": " + str(id)) utils.logMsg("MB3 Sync","setting filename in kodi db..." + fileType + ": " + str(id))
try:
print oldFileName
except:
pass
if fileType == "tvshow": if fileType == "tvshow":
#for tvshows we only store the path in DB #for tvshows we only store the path in DB
@ -943,10 +951,15 @@ class WriteKodiDB():
cursor.close() cursor.close()
#rename the old strmfile to prevent Kodi from scanning it again #rename the old strmfile to prevent Kodi from scanning it again
if oldFileName.endswith(".strm"): if strmFile != None:
if xbmcvfs.exists(oldFileName): filename = strmFile
oldFileName_renamed = oldFileName.replace(".strm",".emby") else:
xbmcvfs.rename(oldFileName,oldFileName_renamed) 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): def AddActorsToMedia(self, KodiItem, people, mediatype):