From 6f113685757ee3b31cfa7361e1a120e56bc85f50 Mon Sep 17 00:00:00 2001 From: faush01 Date: Thu, 2 Apr 2015 10:48:04 +1100 Subject: [PATCH] use existing file only if the path was the same as well --- resources/lib/WriteKodiDB.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/resources/lib/WriteKodiDB.py b/resources/lib/WriteKodiDB.py index 13d2f8d7..8af5885a 100644 --- a/resources/lib/WriteKodiDB.py +++ b/resources/lib/WriteKodiDB.py @@ -680,18 +680,23 @@ class WriteKodiDB(): path = playurl.replace(filename,"") #create the path - cursor.execute("select coalesce(max(idPath),0) as pathid from path") - pathid = cursor.fetchone()[0] - pathid = pathid + 1 - pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)" - cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1)) + cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,)) + result = cursor.fetchone() + if result != None: + pathid = result[0] + else: + cursor.execute("select coalesce(max(idPath),0) as pathid from path") + pathid = cursor.fetchone()[0] + pathid = pathid + 1 + pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)" + cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1)) playcount = None if userData.get("PlayCount") == "1": playcount = 1 #create the file if not exists - cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?",(filename,)) + cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,)) result = cursor.fetchone() if result != None: fileid = result[0] @@ -785,11 +790,16 @@ class WriteKodiDB(): path = playurl.replace(filename,"") #create the path - cursor.execute("select coalesce(max(idPath),0) as pathid from path") - pathid = cursor.fetchone()[0] - pathid = pathid + 1 - pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)" - cursor.execute(pathsql, (pathid,path,"musicvideos","metadata.local",1)) + cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,)) + result = cursor.fetchone() + if result != None: + pathid = result[0] + else: + cursor.execute("select coalesce(max(idPath),0) as pathid from path") + pathid = cursor.fetchone()[0] + pathid = pathid + 1 + pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)" + cursor.execute(pathsql, (pathid,path,"movies","metadata.local",1)) playcount = None if userData.get("PlayCount") == "1": @@ -886,13 +896,12 @@ class WriteKodiDB(): pathsql="insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)" cursor.execute(pathsql, (pathid,path,None,None,1)) - playcount = None if userData.get("PlayCount") == "1": playcount = 1 #create the file if not exists - cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?",(filename,)) + cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,)) result = cursor.fetchone() if result != None: fileid = result[0]