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 total
|
||||||
global scanned
|
global scanned
|
||||||
global added
|
global added
|
||||||
|
global root
|
||||||
|
global libid
|
||||||
total = 0
|
total = 0
|
||||||
added = 0
|
added = 0
|
||||||
scanned = 0
|
scanned = 0
|
||||||
|
root = ""
|
||||||
|
|
||||||
|
|
||||||
def incr(path):
|
def incr(path):
|
||||||
|
@ -27,6 +30,48 @@ def incr(path):
|
||||||
total += 1
|
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):
|
def addtrk(path):
|
||||||
global added
|
global added
|
||||||
global scanned
|
global scanned
|
||||||
|
@ -38,15 +83,12 @@ def addtrk(path):
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
artist = t.artist
|
arid = insartalb("artist", t.artist)
|
||||||
if artist == "":
|
alid = insartalb("album", t.album)
|
||||||
artist = "Unknown Artist"
|
|
||||||
sel = sql.Select("id","artist","name='"+artist.replace("\'","\'\'")+"'")
|
a = f.audioProperties()
|
||||||
result = sel.execute().fetchall()
|
instrk(arid, alid, t.title, a.length, path)
|
||||||
write(result)
|
|
||||||
if result == []:
|
|
||||||
ins = sql.Insert("artist",[None,artist])
|
|
||||||
ins.execute()
|
|
||||||
|
|
||||||
|
|
||||||
def scan((dir,func)):
|
def scan((dir,func)):
|
||||||
|
@ -63,6 +105,8 @@ def go(name):
|
||||||
global total
|
global total
|
||||||
global added
|
global added
|
||||||
global scanned
|
global scanned
|
||||||
|
global root
|
||||||
|
global libid
|
||||||
total = 0
|
total = 0
|
||||||
added = 0
|
added = 0
|
||||||
scanned = 0
|
scanned = 0
|
||||||
|
@ -71,8 +115,9 @@ def go(name):
|
||||||
result = sel.execute().fetchall()
|
result = sel.execute().fetchall()
|
||||||
if result == []:
|
if result == []:
|
||||||
return
|
return
|
||||||
libid = result[0][0]
|
libid = str(result[0][0])
|
||||||
path = result[0][1]
|
path = result[0][1]
|
||||||
|
root = path
|
||||||
|
|
||||||
# Start a thread to count the total number of files to scan
|
# Start a thread to count the total number of files to scan
|
||||||
totthr = needle.Needle(scan,(path,incr))
|
totthr = needle.Needle(scan,(path,incr))
|
||||||
|
|
Loading…
Reference in New Issue