Can insert artists, albums, tracks and associate tracks with a library
This commit is contained in:
parent
b391dedc85
commit
b673309a20
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue