Store more track information (play count, location)

This commit is contained in:
bjschuma 2010-01-02 01:03:58 -05:00
parent 947aa73411
commit b9d36e264e
4 changed files with 51 additions and 21 deletions

View File

@ -31,20 +31,24 @@ def close():
def library(args): def library(args):
name = "Default" name = "Default"
root = "" root = ""
if len(args) >= 1:
name = args[0]
if len(args) >= 2: if len(args) >= 2:
name = args[0]
#if len(args) >= 2:
space = ' ' space = ' '
root = expandPath( space.join(args[1:]) ) root = expandPath( space.join(args[1:]) )
else:
return
#next = settings.get("nextlib") if checkDir(root) == False:
return
# Insert the library into the database
database.open() database.open()
next = database.count('library') next = database.count('library')
database.insert('library',(next,name,root) ) database.insert('library',(next,name,root) )
database.close() database.close()
if not root == "": manager.run("scan",[root])
manager.run("scan",[root])
# Called when the plugin needs to perform some action # Called when the plugin needs to perform some action

View File

@ -72,6 +72,12 @@ def run(file=None):
if file == None: if file == None:
return return
if len(file) < 2:
return
root = file[0]
file = file[1]
if validFile(file) == False: if validFile(file) == False:
return return
@ -82,20 +88,28 @@ def run(file=None):
return return
# Find artist information # Find artist information
artist = t.artist#.replace("\'","\'\'") artist = t.artist
if artist == "": if artist == "":
artist = "Unknown Artist" artist = "Unknown Artist"
# Insert the artist of it is new
arid,inserted = findId("artist",artist) arid,inserted = findId("artist",artist)
if inserted == False: if inserted == False:
database.insert("artist", (arid, artist) ) database.insert("artist", (arid, artist) )
album = t.album#.replace("\'","\'\'") # Find album information
album = t.album
if album == "": if album == "":
album = "Unknown Album" album = "Unknown Album"
# Insert the album if it is new
#alid = database.count("album")
alid,inserted = findId("album",album) alid,inserted = findId("album",album)
if inserted == False: if inserted == False:
database.insert("album", (alid, album) ) database.insert("album", (alid, album) )
#database.commit()
# Find the track information
title = t.title
if title == "":
title = "Unknown Title"
# Insert the track if it is new
trid,inserted = findId("track",title)
if inserted == False:
database.insert("track", (trid,arid,alid,0,title,file[len(root):]))

View File

@ -22,6 +22,7 @@ from manager import manager
from tools import database from tools import database
#from library.scan import scan #from library.scan import scan
global root
# Called every time the plugin is enabled # Called every time the plugin is enabled
def open(): def open():
@ -42,7 +43,8 @@ def scan(dir):
scan(path) scan(path)
else: else:
write(path,True) write(path,True)
manager.run("extract", path) global root
manager.run("extract", (root,path))
#database.insert(path) #database.insert(path)
#self.files += [path] #self.files += [path]
@ -52,16 +54,19 @@ def run(args=None):
if args == None: if args == None:
return return
space = ' ' space = ' '
path = expandPath( space.join(args) ) global root
root = expandPath( space.join(args) )
database.open() database.open()
scan(path) scan(root)
#count = str(database.count("files")) #count = str(database.count("files"))
count = str(database.count("artist")) count = str(database.count("artist"))
write("Library contains "+count+" artists.") write("Library contains "+count+" artists.")
count = str(database.count("album")) count = str(database.count("album"))
write("Library contains "+count+" albums.") write("Library contains "+count+" albums.")
count = str(database.count("track"))
write("Library contains "+count+" tracks.")
database.close() database.close()

View File

@ -61,6 +61,16 @@ def create():
path TEXT UNIQUE path TEXT UNIQUE
); );
CREATE TABLE track
(
id INTEGER PRIMARY KEY,
artist INTEGER,
album INTEGER,
count INTEGER,
name TEXT,
path TEXT UNIQUE
);
""") """)
@ -69,6 +79,7 @@ def create():
vals["artist"]= "?,?" vals["artist"]= "?,?"
vals["album"] = "?,?" vals["album"] = "?,?"
vals["library"] = "?,?,?" vals["library"] = "?,?,?"
vals["track"] = "?,?,?,?,?,?"
@ -127,9 +138,5 @@ def select(select,table,where=None):
if not (where==None): if not (where==None):
statement += ' where '+where statement += ' where '+where
#print statement #print statement
try: result = execute(statement)
result = execute(statement) return result
return result
except:
print statement
return None