fixes for the path sync actions

not working yet --> episodes updates are skipped ?
This commit is contained in:
Marcel van der Veldt 2015-03-29 18:20:02 +02:00
parent b8481129cf
commit bc207a7268
2 changed files with 94 additions and 71 deletions

View file

@ -63,8 +63,6 @@ class ReadKodiDB():
return embyId return embyId
def getKodiMovies(self,fullInfo = False): def getKodiMovies(self,fullInfo = False):
#returns all movies in Kodi db #returns all movies in Kodi db
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
@ -129,9 +127,9 @@ class ReadKodiDB():
#returns all tvshows in Kodi db inserted by MB #returns all tvshows in Kodi db inserted by MB
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
if fullInfo: if fullInfo:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.emby"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "lastplayed", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "premiered", "rating", "thumbnail", "playcount", "lastplayed", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
else: else:
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "plugin.video.emby"}, "properties": ["sorttitle", "title", "playcount", "lastplayed", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "properties": ["sorttitle", "title", "playcount", "lastplayed", imdbnumber, "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
tvshows = None tvshows = None
@ -144,18 +142,14 @@ class ReadKodiDB():
if(tvshows != None and len(tvshows) > 0): if(tvshows != None and len(tvshows) > 0):
kodiShowMap = {} kodiShowMap = {}
for kodishow in tvshows: for kodishow in tvshows:
filepath = kodishow["file"] key = kodishow["imdbnumber"] #extract the id from the imdb number
filepath = filepath.replace(tvLibrary + os.sep, "")
filepath = filepath.replace(".strm", "")
filepath = filepath.split(os.sep)[0]
key = filepath #extract the id from the file path
kodiShowMap[key] = kodishow kodiShowMap[key] = kodishow
return kodiShowMap return kodiShowMap
def getKodiTVShow(self, id): def getKodiTVShow(self, id):
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "lastplayed", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "is", "field": "imdbnumber", "value": "' + id + '"}, "properties": ["art", "genre", "plot", "mpaa", "cast", "studio", "sorttitle", "title", "originaltitle", "imdbnumber", "year", "lastplayed", "premiered", "rating", "thumbnail", "playcount", "file", "fanart"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
tvshow = None tvshow = None
if(jsonobject.has_key('result')): if(jsonobject.has_key('result')):
@ -168,7 +162,7 @@ class ReadKodiDB():
def getKodiEpisodes(self, id, fullInfo = True, returnmap = True): def getKodiEpisodes(self, id, fullInfo = True, returnmap = True):
xbmc.sleep(sleepVal) xbmc.sleep(sleepVal)
episodes = None episodes = None
json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "path", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}') json_response = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": { "filter": {"operator": "contains", "field": "imdbnumber", "value": "' + id + '"}, "properties": ["title", "file"], "sort": { "order": "ascending", "method": "label", "ignorearticle": true } }, "id": "libTvShows"}')
jsonobject = json.loads(json_response.decode('utf-8','replace')) jsonobject = json.loads(json_response.decode('utf-8','replace'))
tvshow = None tvshow = None
if(jsonobject.has_key('result')): if(jsonobject.has_key('result')):

View file

@ -76,9 +76,7 @@ class WriteKodiDB():
#set Filename #set Filename
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem) playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
if not playurl.startswith("http"): self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie")
if playurl != KodiItem["file"]:
self.setKodiFilename(KodiItem["movieid"], playurl, "movie")
#update common properties #update common properties
duration = (int(timeInfo.get('Duration'))*60) duration = (int(timeInfo.get('Duration'))*60)
@ -149,9 +147,6 @@ class WriteKodiDB():
#add actors #add actors
changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"), "movie") changes |= self.AddActorsToMedia(KodiItem,MBitem.get("People"), "movie")
CreateFiles().createSTRM(MBitem)
CreateFiles().createNFO(MBitem)
#add theme music #add theme music
if addon.getSetting("syncThemeMusic") == "true": if addon.getSetting("syncThemeMusic") == "true":
CreateFiles().copyThemeMusic(MBitem) CreateFiles().copyThemeMusic(MBitem)
@ -298,10 +293,8 @@ class WriteKodiDB():
#set Filename #set Filename
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem) playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
self.setKodiFilename(KodiItem["movieid"], playurl, "movie") self.setKodiFilename(KodiItem["movieid"], KodiItem["file"], playurl, "movie")
CreateFiles().createSTRM(MBitem)
CreateFiles().createNFO(MBitem)
#add theme music #add theme music
if addon.getSetting("syncThemeMusic") == "true": if addon.getSetting("syncThemeMusic") == "true":
@ -333,6 +326,12 @@ class WriteKodiDB():
changes = False changes = False
#set Filename
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
#make sure that the path always ends with a slash
playurl = playurl + "/"
self.setKodiFilename(KodiItem["tvshowid"], KodiItem["file"], playurl, "tvshow")
#update/check all artwork #update/check all artwork
changes |= self.updateArtWork(KodiItem,MBitem) changes |= self.updateArtWork(KodiItem,MBitem)
@ -410,9 +409,7 @@ class WriteKodiDB():
#set Filename #set Filename
playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem) playurl = PlayUtils().getPlayUrl(server, MBitem["Id"], MBitem)
if not playurl.startswith("http"): self.setKodiFilename(KodiItem["episodeid"], KodiItem["file"], playurl, "episode")
if playurl != KodiItem["file"]:
self.setKodiFilename(KodiItem["episodeid"], playurl, "episode")
#update common properties #update common properties
duration = (int(timeInfo.get('Duration'))*60) duration = (int(timeInfo.get('Duration'))*60)
@ -437,9 +434,6 @@ 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)
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"])
@ -866,24 +860,59 @@ class WriteKodiDB():
cursor.close() cursor.close()
def setKodiFilename(self, id, filenameAndPath, fileType): 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
filenameAndPath = utils.convertEncoding(filenameAndPath)
if "\\" in filenameAndPath: oldFileName = utils.convertEncoding(oldFileName)
filename = filenameAndPath.rsplit("\\",1)[-1] newFileName = utils.convertEncoding(newFileName)
path = filenameAndPath.replace(filename,"")
elif "/" in filenameAndPath: print "setting filename for ID..." + str(id) + "...Type-->" + fileType
filename = filenameAndPath.rsplit("/",1)[-1] print oldFileName
path = filenameAndPath.replace(filename,"") print newFileName
# only perform changes if the path actually differs
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"):
utils.logMsg("MB3 Sync","setting filename in kodi db..." + fileType + ": " + str(id))
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))
if fileType == "tvshow":
#for tvshows we only store the path in DB
cursor.execute("SELECT idPath as pathid FROM tvshowlinkpath WHERE idShow = ?",(id,))
result = cursor.fetchone()
if result != None:
pathid = result[0]
cursor.execute("UPDATE path SET strPath = ? WHERE idPath = ?", (newFileName,pathid))
cursor.execute("UPDATE path SET noUpdate = ? WHERE idPath = ?", (1,pathid))
cursor.execute("UPDATE path SET idParentPath = ? WHERE idPath = ?", (None,pathid))
else:
#process movies and episodes
if "\\" in newFileName:
filename = newFileName.rsplit("\\",1)[-1]
path = newFileName.replace(filename,"")
elif "/" in newFileName:
filename = newFileName.rsplit("/",1)[-1]
path = newFileName.replace(filename,"")
if fileType == "movie":
strContent = "movies"
strScraper = "metadata.local"
elif fileType == "episode":
strContent = None
strScraper = None
# we need to store both the path and the filename seperately in the kodi db
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:
@ -892,30 +921,30 @@ class WriteKodiDB():
cursor.execute("select coalesce(max(idPath),0) as pathid from path") cursor.execute("select coalesce(max(idPath),0) as pathid from path")
pathid = cursor.fetchone()[0] pathid = cursor.fetchone()[0]
pathid = pathid + 1 pathid = pathid + 1
pathsql="insert into path(idPath, strPath) values(?, ?)" pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
cursor.execute(pathsql, (pathid,path)) cursor.execute(pathsql, (pathid,path,strContent,strScraper,1))
'''
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
pathid = cursor.fetchone()[0]
pathid = pathid + 1
pathsql="insert into path(idPath, strPath) values(?, ?)"
cursor.execute(pathsql, (pathid,path))
'''
if fileType == "episode": if fileType == "episode":
cursor.execute("SELECT idFile as fileidid 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]
if fileType == "movie": if fileType == "movie":
cursor.execute("SELECT idFile as fileidid 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]
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)) cursor.execute("UPDATE files SET idPath = ? WHERE idFile = ?", (pathid,fileid))
try:
connection.commit() connection.commit()
finally:
cursor.close() 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)
def AddActorsToMedia(self, KodiItem, people, mediatype): def AddActorsToMedia(self, KodiItem, people, mediatype):