changes to prevent doubled paths and support for transcoding
This commit is contained in:
parent
52bd5b662e
commit
1388eda326
2 changed files with 112 additions and 96 deletions
|
@ -251,3 +251,12 @@ def CleanName(filename):
|
||||||
return ''.join(c for c in cleanedFilename if c in validFilenameChars)
|
return ''.join(c for c in cleanedFilename if c in validFilenameChars)
|
||||||
|
|
||||||
|
|
||||||
|
def removeDirectory(path):
|
||||||
|
if xbmcvfs.exists(path):
|
||||||
|
allDirs, allFiles = xbmcvfs.listdir(path)
|
||||||
|
for dir in allDirs:
|
||||||
|
xbmcvfs.rmdir(os.path.join(path,dir))
|
||||||
|
for file in allFiles:
|
||||||
|
xbmcvfs.delete(os.path.join(path,file))
|
||||||
|
|
||||||
|
xbmcvfs.rmdir(path)
|
||||||
|
|
|
@ -76,7 +76,11 @@ class WriteKodiDB():
|
||||||
|
|
||||||
#set Filename
|
#set Filename
|
||||||
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
||||||
self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie")
|
docleanup = self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie")
|
||||||
|
#if the path has been set directly in the DB, cleanup the locally created files to import the media-item into the Kodi DB to prevent Kodi from scanning it again.
|
||||||
|
if docleanup:
|
||||||
|
itemPath = os.path.join(movieLibrary,MBitem["Id"])
|
||||||
|
utils.removeDirectory(os.path.join(movieLibrary,MBitem["Id"] + os.sep))
|
||||||
|
|
||||||
#update common properties
|
#update common properties
|
||||||
duration = (int(timeInfo.get('Duration'))*60)
|
duration = (int(timeInfo.get('Duration'))*60)
|
||||||
|
@ -330,7 +334,13 @@ class WriteKodiDB():
|
||||||
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
|
||||||
#make sure that the path always ends with a slash
|
#make sure that the path always ends with a slash
|
||||||
playurl = playurl + "/"
|
playurl = playurl + "/"
|
||||||
self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow")
|
docleanup = self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow")
|
||||||
|
|
||||||
|
#if the path has been set directly in the DB, cleanup the locally created nfo file to import the tvshow into the Kodi DB to prevent Kodi from scanning it again.
|
||||||
|
if docleanup:
|
||||||
|
nfoPath = os.path.join(tvLibrary,MBitem["Id"],"tvshow.nfo")
|
||||||
|
print "about to delete file--> " + nfoPath
|
||||||
|
os.remove(nfoPath)
|
||||||
|
|
||||||
#update/check all artwork
|
#update/check all artwork
|
||||||
changes |= self.updateArtWork(KodiItem,MBitem)
|
changes |= self.updateArtWork(KodiItem,MBitem)
|
||||||
|
@ -409,13 +419,16 @@ class WriteKodiDB():
|
||||||
|
|
||||||
#set Filename (also submit strmfilepath to rename that if path has changed to original location)
|
#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)
|
||||||
itemPath = os.path.join(tvLibrary,MBitem["SeriesId"])
|
docleanup = self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode")
|
||||||
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"
|
#if the path has been set directly in the DB, cleanup the locally created files to import the media-item into the Kodi DB to prevent Kodi from scanning it again.
|
||||||
else:
|
if docleanup:
|
||||||
filenamestr = utils.CleanName(utils.convertEncoding(MBitem.get("SeriesName"))) + " S0E0 " + utils.CleanName(utils.convertEncoding(MBitem.get("Name"))) + " (" + MBitem["Id"] + ").strm"
|
path = os.path.join(tvLibrary,MBitem["SeriesId"] + os.sep)
|
||||||
strmFile = os.path.join(itemPath,filenamestr)
|
if xbmcvfs.exists(path):
|
||||||
self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode", strmFile)
|
allDirs, allFiles = xbmcvfs.listdir(path)
|
||||||
|
for file in allFiles:
|
||||||
|
if MBitem["Id"] in file:
|
||||||
|
xbmcvfs.delete(os.path.join(path,file))
|
||||||
|
|
||||||
#update common properties
|
#update common properties
|
||||||
duration = (int(timeInfo.get('Duration'))*60)
|
duration = (int(timeInfo.get('Duration'))*60)
|
||||||
|
@ -741,13 +754,9 @@ class WriteKodiDB():
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveMovie", "params": { "movieid": %i}, "id": 1 }' %(kodiItem["movieid"]))
|
||||||
|
|
||||||
path = os.path.join(movieLibrary,id)
|
path = os.path.join(movieLibrary,id + os.sep)
|
||||||
allDirs, allFiles = xbmcvfs.listdir(path)
|
utils.removeDirectory(path)
|
||||||
for dir in allDirs:
|
|
||||||
xbmcvfs.rmdir(os.path.join(path,dir))
|
|
||||||
for file in allFiles:
|
|
||||||
xbmcvfs.delete(os.path.join(path,file))
|
|
||||||
xbmcvfs.rmdir(path)
|
|
||||||
|
|
||||||
def deleteMusicVideoFromKodiLibrary(self, id ):
|
def deleteMusicVideoFromKodiLibrary(self, id ):
|
||||||
utils.logMsg("deleting musicvideo from Kodi library",id)
|
utils.logMsg("deleting musicvideo from Kodi library",id)
|
||||||
|
@ -806,15 +815,9 @@ class WriteKodiDB():
|
||||||
if kodiItem != None:
|
if kodiItem != None:
|
||||||
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.RemoveTVShow", "params": { "tvshowid": %i}, "id": 1 }' %(kodiItem["tvshowid"]))
|
||||||
|
|
||||||
path = os.path.join(tvLibrary,id)
|
path = os.path.join(tvLibrary,id + os.sep)
|
||||||
allDirs, allFiles = xbmcvfs.listdir(path)
|
utils.removeDirectory(path)
|
||||||
for dir in allDirs:
|
|
||||||
xbmcvfs.rmdir(os.path.join(path,dir))
|
|
||||||
for file in allFiles:
|
|
||||||
xbmcvfs.delete(os.path.join(path,file))
|
|
||||||
succes = xbmcvfs.rmdir(path)
|
|
||||||
if not succes:
|
|
||||||
utils.logMsg("Error deleting TV show with ID ",id)
|
|
||||||
|
|
||||||
def updateSeasonArtwork(self,MBitem, KodiItem):
|
def updateSeasonArtwork(self,MBitem, KodiItem):
|
||||||
#use sqlite to set the season artwork because no method in API available for this
|
#use sqlite to set the season artwork because no method in API available for this
|
||||||
|
@ -871,46 +874,36 @@ 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
|
||||||
|
#return True if any action is performed, False if no action is performed
|
||||||
#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
|
||||||
|
|
||||||
|
actionPerformed = False
|
||||||
|
|
||||||
oldFileName = utils.convertEncoding(oldFileName)
|
oldFileName = utils.convertEncoding(oldFileName)
|
||||||
newFileName = utils.convertEncoding(newFileName)
|
newFileName = utils.convertEncoding(newFileName)
|
||||||
|
|
||||||
|
|
||||||
# only perform changes if the path actually differs
|
# only perform changes if the path actually differs
|
||||||
if oldFileName != newFileName:
|
if oldFileName != newFileName:
|
||||||
|
|
||||||
# play from stream is not supported, that has to use the old method of playing through the addon itself
|
|
||||||
# TODO --> if you change from stream to local you have to rescan, this can be fixed here ?
|
|
||||||
if not newFileName.startswith("http"):
|
|
||||||
|
|
||||||
xbmc.sleep(sleepVal)
|
xbmc.sleep(sleepVal)
|
||||||
connection = utils.KodiSQL()
|
connection = utils.KodiSQL()
|
||||||
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))
|
||||||
#utils.logMsg("MB3 Sync","Old Name : " + oldFileName)
|
utils.logMsg("MB3 Sync","old filename -->" + oldFileName)
|
||||||
#utils.logMsg("MB3 Sync","New Name : " + newFileName)
|
utils.logMsg("MB3 Sync","new filename -->" + newFileName)
|
||||||
try:
|
|
||||||
print oldFileName
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if fileType == "tvshow":
|
if fileType == "tvshow" and not newFileName.startswith("http"):
|
||||||
#for tvshows we only store the path in DB
|
#for tvshows we only store the path in DB
|
||||||
|
|
||||||
cursor.execute("SELECT idPath as pathid FROM tvshowlinkpath WHERE idShow = ?",(id,))
|
cursor.execute("SELECT idPath as pathid FROM tvshowlinkpath WHERE idShow = ?",(id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result != None:
|
|
||||||
pathid = result[0]
|
pathid = result[0]
|
||||||
cursor.execute("UPDATE path SET strPath = ? WHERE idPath = ?", (newFileName,pathid))
|
cursor.execute("UPDATE path SET strPath = ?, noUpdate = ?, idParentPath = ? WHERE idPath = ?", (newFileName,1,None,pathid))
|
||||||
cursor.execute("UPDATE path SET noUpdate = ? WHERE idPath = ?", (1,pathid))
|
|
||||||
cursor.execute("UPDATE path SET idParentPath = ? WHERE idPath = ?", (None,pathid))
|
|
||||||
else:
|
else:
|
||||||
#process movies and episodes
|
# we need to store both the path and the filename seperately in the kodi db so we split them up
|
||||||
if "\\" in newFileName:
|
if "\\" in newFileName:
|
||||||
filename = newFileName.rsplit("\\",1)[-1]
|
filename = newFileName.rsplit("\\",1)[-1]
|
||||||
path = newFileName.replace(filename,"")
|
path = newFileName.replace(filename,"")
|
||||||
|
@ -918,14 +911,15 @@ class WriteKodiDB():
|
||||||
filename = newFileName.rsplit("/",1)[-1]
|
filename = newFileName.rsplit("/",1)[-1]
|
||||||
path = newFileName.replace(filename,"")
|
path = newFileName.replace(filename,"")
|
||||||
|
|
||||||
if fileType == "movie":
|
#if we want to use transcoding/play from stream we pass on the complete http path
|
||||||
strContent = "movies"
|
#in this case both the path and filename are set to the addonpath
|
||||||
strScraper = "metadata.local"
|
if newFileName.startswith("http"):
|
||||||
elif fileType == "episode":
|
path = newFileName
|
||||||
strContent = None
|
|
||||||
strScraper = None
|
|
||||||
|
|
||||||
# we need to store both the path and the filename seperately in the kodi db
|
######### PROCESS EPISODE ############
|
||||||
|
if fileType == "episode":
|
||||||
|
|
||||||
|
#create the path - return id if already exists
|
||||||
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result != None:
|
if result != None:
|
||||||
|
@ -935,34 +929,47 @@ class WriteKodiDB():
|
||||||
pathid = cursor.fetchone()[0]
|
pathid = cursor.fetchone()[0]
|
||||||
pathid = pathid + 1
|
pathid = pathid + 1
|
||||||
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
|
||||||
cursor.execute(pathsql, (pathid,path,strContent,strScraper,1))
|
cursor.execute(pathsql, (pathid,path,None,None,1))
|
||||||
|
|
||||||
if fileType == "episode":
|
#get the file and the current path id
|
||||||
cursor.execute("SELECT idFile as fileid FROM episode WHERE idEpisode = ?",(id,))
|
cursor.execute("SELECT idFile as fileid FROM episode WHERE idEpisode = ?",(id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
fileid = result[0]
|
fileid = result[0]
|
||||||
|
cursor.execute("SELECT idPath as curpathid FROM files WHERE idFile = ?",(fileid,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
curpathid = result[0]
|
||||||
|
|
||||||
|
#remove the old path if different
|
||||||
|
if curpathid != pathid:
|
||||||
|
cursor.execute("DELETE FROM path WHERE idPath = ?",(curpathid,))
|
||||||
|
|
||||||
|
#set the new path and filename to the episode
|
||||||
|
cursor.execute("UPDATE files SET idPath = ?, strFilename = ? WHERE idFile = ?", (pathid,filename,fileid))
|
||||||
|
|
||||||
|
|
||||||
|
######### PROCESS MOVIE ############
|
||||||
if fileType == "movie":
|
if fileType == "movie":
|
||||||
cursor.execute("SELECT idFile as fileid FROM movie WHERE idMovie = ?",(id,))
|
cursor.execute("SELECT idFile as fileid FROM movie WHERE idMovie = ?",(id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
fileid = result[0]
|
fileid = result[0]
|
||||||
|
#write the new filename to the DB
|
||||||
cursor.execute("UPDATE files SET strFilename = ? WHERE idFile = ?", (filename,fileid))
|
cursor.execute("UPDATE files SET strFilename = ? WHERE idFile = ?", (filename,fileid))
|
||||||
cursor.execute("UPDATE files SET idPath = ? WHERE idFile = ?", (pathid,fileid))
|
#set the new path
|
||||||
|
cursor.execute("SELECT idPath as pathid FROM files WHERE idFile = ?",(fileid,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
pathid = result[0]
|
||||||
|
cursor.execute("UPDATE path SET strPath = ?, strContent = ?, strScraper = ?, noUpdate = ?, idParentPath = ? WHERE idPath = ?", (path, "movies", "metadata.local", 1, None, pathid))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
connection.commit()
|
connection.commit()
|
||||||
|
actionPerformed = True
|
||||||
|
except:
|
||||||
|
utils.logMsg("MB3 Sync","Error setting filename in kodi db for: " + fileType + ": " + str(id))
|
||||||
|
actionPerformed = False
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
#rename the old strmfile to prevent Kodi from scanning it again
|
return actionPerformed
|
||||||
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):
|
def AddActorsToMedia(self, KodiItem, people, mediatype):
|
||||||
|
|
Loading…
Reference in a new issue