From cbdf7d9dba95cc31c5e827c374b41481f14f5ade Mon Sep 17 00:00:00 2001 From: bjschuma Date: Fri, 1 Jan 2010 21:00:12 -0500 Subject: [PATCH] Can create multiple libraries --- src/core/create.py | 67 ++++++++++++++++++++++++++++++++++++++ src/core/extract.py | 3 +- src/core/tools/database.py | 46 +++++++++++++------------- 3 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 src/core/create.py diff --git a/src/core/create.py b/src/core/create.py new file mode 100644 index 00000000..9d48edf0 --- /dev/null +++ b/src/core/create.py @@ -0,0 +1,67 @@ +# This is a simple test plugin, to make sure everything is working + +__author__="bjschuma" +__date__ ="$Jan 1, 2010 6:33:06 PM$" + + +global name, app, type, path, opt +name = "create" +app = "ocarina" +type = "core" +path = "" +opt = [] + +from bt.message import write +from bt.file import * +from tools import database +from manager import manager +import settings + + +# Called every time the plugin is enabled +def open(): + pass + + +# Called every time the plugin is stopped +def close(): + pass + + +def library(args): + name = "Default" + root = "" + if len(args) >= 1: + name = args[0] + if len(args) >= 2: + space = ' ' + root = expandPath( space.join(args[1:]) ) + + #next = settings.get("nextlib") + database.open() + next = database.count('library') + database.insert('library',(next,name,root) ) + database.close() + + if not root == "": + manager.run("scan",[root]) + + +# Called when the plugin needs to perform some action +def run(args=None): + l = len(args) + if args[0] == "library": + library(args[1:]) + #name = "Default" + #root = "" + #if l >= 2: + # name = args[1] + #if l >= 3: + # space = ' ' + # root = expandPath( space.join(args[2:]) ) + #database.open() + #database.insert('library',(name,root) ) + #database.close() + #if not root=="": + # manager.run("scan",[root]) + diff --git a/src/core/extract.py b/src/core/extract.py index 05e9f438..edf87b23 100644 --- a/src/core/extract.py +++ b/src/core/extract.py @@ -80,6 +80,7 @@ def run(file=None): if artist == "": artist = "Unknown Artist" + # If artist does not exist yet, insert into database if (artist in artists.keys())==False: arid = database.count("artist") database.insert("artist", (arid, artist) ) @@ -92,4 +93,4 @@ def run(file=None): album = "Unknown Album" alid = database.count("album") - database.insert("album", (alid, arid, album) ) + database.insert("album", (alid, album) ) diff --git a/src/core/tools/database.py b/src/core/tools/database.py index e096fb8c..7399bec0 100644 --- a/src/core/tools/database.py +++ b/src/core/tools/database.py @@ -44,24 +44,31 @@ def create(): CREATE TABLE artist ( - arid INTEGER PRIMARY KEY, + id INTEGER PRIMARY KEY, name TEXT UNIQUE ); CREATE TABLE album ( - alid INTEGER PRIMARY KEY, - artid INTEGER, + id INTEGER PRIMARY KEY, name TEXT UNIQUE ); + CREATE TABLE library + ( + libid INTEGER PRIMARY KEY AUTOINCREMENT, + name TEXT UNIQUE, + path TEXT UNIQUE + ); + """) global vals vals["files"] = "?" vals["artist"]= "?,?" - vals["album"] = "?,?,?" + vals["album"] = "?,?" + vals["library"] = "?,?,?" @@ -88,35 +95,30 @@ def init(): close() -def insert(table, values): +def execute(statement, values=None): global conn if conn == None: open() + + if values == None: + return conn.execute(statement) + else: + return conn.execute(statement,values) + + +def insert(table, values): global vals - #c = conn.cursor() - #t = (file,) - conn.execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values) - #c.close() + execute('INSERT OR IGNORE INTO ' + table + ' VALUES(' + vals[table] + ')',values) def count(table): - global conn - if conn == None: - open() - result = conn.execute('select count(*) from '+ table) - return result.fetchone()[0] + return execute('select count(*) from ' + table).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,) \ No newline at end of file + result = execute(statement) + return result \ No newline at end of file