Can list and switch between libraries

This commit is contained in:
bjschuma 2010-01-05 17:25:49 -05:00
parent 7cbb901229
commit 2c26652772
6 changed files with 130 additions and 19 deletions

View File

@ -66,6 +66,15 @@ def findId(table,name):
return result[0],True return result[0],True
def insLibTrk(trid):
libid = settings.get("curlib")
lib = str(libid)
trk = str(trid)
result = database.select("*","libtrack","track="+trk+" and library="+lib).fetchone()
if result == None:
return True,libid
return False,-1
# Called when the plugin needs to perform some action # Called when the plugin needs to perform some action
def run(file=None): def run(file=None):
@ -114,3 +123,7 @@ def run(file=None):
if inserted == False: if inserted == False:
a = f.audioProperties() a = f.audioProperties()
database.insert("track", (trid,arid,alid,0,a.length,title,file[len(root):])) database.insert("track", (trid,arid,alid,0,a.length,title,file[len(root):]))
ins,libid = insLibTrk(trid)
if ins == True:
database.insert("libtrack", (libid,trid))

44
src/core/lslib.py Normal file
View File

@ -0,0 +1,44 @@
# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 5, 2010 4:15:27 PM$"
global name, app, type, path, opt
name = "lslib"
app = "ocarina"
type = "core"
path = ""
opt = []
from bt.message import write
from tools import database
import settings
# Called every time the plugin is enabled
def open():
pass
# Called every time the plugin is stopped
def close():
pass
# Called when the plugin needs to perform some action
def run(args=None):
cur = str(settings.get("curlib"))
result = database.select("name","library","id="+str(cur)).fetchone()[0]
write("Current Library: "+result)
result = database.select("*","library").fetchall()
if len(result) == 0:
return
write("Name\tPath")
write("------------")
for lib in result:
write(lib[1]+"\t"+lib[2])

View File

@ -19,13 +19,16 @@ from manager import manager
def next(): def next():
cur = settings.get("current") cur = str(settings.get("curlib"))
database.open() count = database.select("count(*)","libtrack","library="+cur).fetchone()[0]
count = database.count("track")
database.close() curtrk = settings.get("current")
if cur == count: if curtrk > count:
return 0 curtrk = 0
return cur+1 else:
curtrk += 1
rows = database.select("track","libtrack","library="+cur).fetchall()
return rows[curtrk][0],curtrk
@ -47,12 +50,12 @@ def run(args=None):
if settings.has("curlib") == False: if settings.has("curlib") == False:
return return
curlib = str(settings.get("curlib")) curlib = str(settings.get("curlib"))
id = settings.get("next")() id,curtrk = settings.get("next")()
database.open() database.open()
a = database.select("path","library","id="+curlib).fetchone()[0] a = database.select("path","library","id="+curlib).fetchone()[0]
b = database.select("path","track","id="+str(id)).fetchone()[0] b = database.select("path","track","id="+str(id)).fetchone()[0]
database.close() database.close()
settings.set("current",id) settings.set("current",curtrk)
manager.run("load",([a+b])) manager.run("load",([a+b]))
manager.run("play") manager.run("play")

View File

@ -18,14 +18,20 @@ import settings
def next(): def next():
count = database.count("track") cur = str(settings.get("curlib"))
return random.randint(0,count) count = database.select("count(*)","libtrack","library="+cur).fetchone()[0]
id = random.randint(0,count)
rows = database.select("track","libtrack","library="+cur).fetchall()
id = rows[id][0]
return id,id
# Called every time the plugin is enabled # Called every time the plugin is enabled
def open(): def open():
if settings.has("random") == False: if settings.has("random") == False:
settings.set("random",False) settings.set("random",False)
else:
settings.set("next",next)
# Called every time the plugin is stopped # Called every time the plugin is stopped

38
src/core/switchlib.py Normal file
View File

@ -0,0 +1,38 @@
# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 5, 2010 4:15:12 PM$"
global name, app, type, path, opt
name = "switchlib"
app = "ocarina"
type = "core"
path = ""
opt = []
from bt.message import write
from tools import database
import settings
# Called every time the plugin is enabled
def open():
pass
# Called every time the plugin is stopped
def close():
pass
# Called when the plugin needs to perform some action
def run(args=None):
if args == 0:
return
name = args[0]
write("Switching to: "+name)
result = database.select("id","library","name=\'"+name+"\'").fetchone()[0]
settings.replace("curlib",int(result))

View File

@ -72,16 +72,15 @@ def create():
path TEXT UNIQUE path TEXT UNIQUE
); );
CREATE TABLE libtrack
(
library INTEGER,
track INTEGER
);
""") """)
global vals
vals["files"] = "?"
vals["artist"]= "?,?"
vals["album"] = "?,?"
vals["library"] = "?,?,?"
vals["track"] = "?,?,?,?,?,?,?"
def open(): def open():
@ -105,12 +104,20 @@ def commit():
def init(): def init():
global db global db, vals
db = join(settings.get("user"),"ocarina.db") db = join(settings.get("user"),"ocarina.db")
dbExists = checkPath(db) dbExists = checkPath(db)
open() open()
# Create database if it doesn't exist yet
if dbExists == False: if dbExists == False:
create() create()
# Fill out information for all values
vals["files"] = "?"
vals["artist"]= "?,?"
vals["album"] = "?,?"
vals["library"] = "?,?,?"
vals["track"] = "?,?,?,?,?,?,?"
vals["libtrack"] = "?,?"
close() close()