From b673309a208ca5fb95c79033e318298f628ebf8d Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sun, 31 Jan 2010 15:09:26 -0500 Subject: [PATCH] Can insert artists, albums, tracks and associate tracks with a library --- src/core/ct/update.py | 65 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/src/core/ct/update.py b/src/core/ct/update.py index 2cc4a18a..197c556b 100644 --- a/src/core/ct/update.py +++ b/src/core/ct/update.py @@ -17,9 +17,12 @@ import tagpy global total global scanned global added +global root +global libid total = 0 added = 0 scanned = 0 +root = "" def incr(path): @@ -27,6 +30,48 @@ def incr(path): total += 1 +# Call to insert either an artist or an album +def insartalb(table,value): + if value == "": + value = "Unknown "+table.title() + #value = value.replace("\'","\'\'") + sel = sql.Select("id",table,'name="' + value + '"') + result = sel.execute().fetchall() + if result == []: + ins = sql.Insert(table,[None,value]) + ins.execute() + result = sel.execute().fetchall() + return result[0][0] + + +# Call to insert a new track +def instrk(arid, alid, title, length, path): + global root + global libid + if title == "": + title = "Unknown Title" + + path = path[len(root):] + + sel = sql.Select("id","track",'path="'+path+'"') + result = sel.execute().fetchall() + + if result == []: + ins = sql.Insert("track", [None, arid, alid, 0, length, title, path] ) + ins.execute() + result = sel.execute().fetchall() + + trid = str(result[0][0]) + + where = "library='"+libid+"' AND track='"+trid+"'" + sel = sql.Select("*","libtrack",where) + result = sel.execute().fetchall() + if result == []: + ins = sql.Insert("libtrack",[int(libid),int(trid)]) + ins.execute() + + + def addtrk(path): global added global scanned @@ -38,15 +83,12 @@ def addtrk(path): except: return - artist = t.artist - if artist == "": - artist = "Unknown Artist" - sel = sql.Select("id","artist","name='"+artist.replace("\'","\'\'")+"'") - result = sel.execute().fetchall() - write(result) - if result == []: - ins = sql.Insert("artist",[None,artist]) - ins.execute() + arid = insartalb("artist", t.artist) + alid = insartalb("album", t.album) + + a = f.audioProperties() + instrk(arid, alid, t.title, a.length, path) + def scan((dir,func)): @@ -63,6 +105,8 @@ def go(name): global total global added global scanned + global root + global libid total = 0 added = 0 scanned = 0 @@ -71,8 +115,9 @@ def go(name): result = sel.execute().fetchall() if result == []: return - libid = result[0][0] + libid = str(result[0][0]) path = result[0][1] + root = path # Start a thread to count the total number of files to scan totthr = needle.Needle(scan,(path,incr))