Add artists and albums to the database

This commit is contained in:
bjschuma 2009-12-30 22:41:42 -05:00
parent 8bc5b9e25a
commit 54dd1463ff
3 changed files with 48 additions and 13 deletions

View File

@ -13,6 +13,7 @@ opt = []
from bt.message import write
from tools import database
import settings
import re
import tagpy
@ -72,14 +73,23 @@ def run(file=None):
except:
return
# Add an artist
artist = None
if t.artist=="":
artist = (None,"Unknown",)
artists = settings.get("artists")
# Find artist information
artist = t.artist
if artist == "":
artist = "Unknown Artist"
if (artist in artists.keys())==False:
arid = database.count("artist")
database.insert("artist", (arid, artist) )
artists[artist] = arid
else:
artist = (None,t.artist,)
#write(t.artist)
database.insert("artist", artist )
#database.insert("files",(file,))
#except:
# pass
arid = artists[artist]
album = t.album
if album == "":
album = "Unknown Album"
alid = database.count("album")
database.insert("album", (alid, arid, album) )

View File

@ -16,6 +16,7 @@ import tagpy
from bt.message import write
from bt.file import *
import settings
from manager import manager
#from library import *
from tools import database
@ -52,6 +53,8 @@ def run(args=None):
return
space = ' '
path = expandPath( space.join(args) )
settings.set("artists",dict())
database.open()
scan(path)

View File

@ -44,17 +44,24 @@ def create():
CREATE TABLE artist
(
arid INTEGER PRIMARY KEY AUTOINCREMENT,
arid INTEGER PRIMARY KEY,
name TEXT UNIQUE
);
CREATE TABLE album
(
alid INTEGER PRIMARY KEY,
artid INTEGER,
name TEXT UNIQUE
);
UPDATE SQLITE_SEQUENCE SET seq = 1 WHERE name = 'artist';
""")
global vals
vals["files"] = "?"
vals["artist"]= "?,?"
vals["album"] = "?,?,?"
@ -97,4 +104,19 @@ def count(table):
if conn == None:
open()
result = conn.execute('select count(*) from '+ table)
return result.fetchone()[0]
return result.fetchone()[0]
def select(select,table,where=None):
global conn
if conn == None:
open()
statement = 'select '+select+' from '+table
if not (where==None):
statement += ' where '+where
print statement
#return statement
result = conn.execute(statement)
#print result.fetchone()
#return result.fetchone()
return (0,)