From 8b2263b0685327f43fc6761eed7267652ddb5797 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Mon, 8 Feb 2010 00:09:57 -0500 Subject: [PATCH] Began work on advancing to the next track --- src/core/ct/db.py | 31 +++++++++++++++++++++++++------ src/core/music.py | 6 +++++- src/core/next.py | 41 +++++++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 11 deletions(-) diff --git a/src/core/ct/db.py b/src/core/ct/db.py index 698d6214..053ae060 100644 --- a/src/core/ct/db.py +++ b/src/core/ct/db.py @@ -12,6 +12,7 @@ from sqlite3 import * from bt import sql import settings + def init(): if sql.dbexists() == True: return @@ -115,19 +116,37 @@ def libid(libname): return result[0] +def countlib(libid): + lib = str( libid ) + sel = sql.Select("count(*)","libtrack","library="+lib) + count = sel.execute().fetchone()[0] + return count + + def listlib(): sel = sql.Select("*","library") result = sel.execute().fetchall() id = settings.get("curlib") curname = "" - write("Id Name Path") - write("------------------") + write("Id Name Count Path") + write("---------------------------") for row in result: if row[0] == id: curname = row[1] + count = str( countlib(row[0]) ) write( str(row[0]) + " " + - row[1] + " " + row[2] ) + row[1] + " " + count + " " + row[2] ) + write("Current: "+curname) - #if not curname == "": - #write("") - write("Current: "+curname) \ No newline at end of file + +def getpath(dbid, curtrk): + curlib = str( settings.get("curlib") ) + + selr = sql.Select("path","library","id="+curlib) + root = selr.execute().fetchone()[0] + + selt = sql.Select("path","track","id="+str(dbid)) + track = selt.execute().fetchone()[0] +# write(root) +# write(track) + write(root+track) \ No newline at end of file diff --git a/src/core/music.py b/src/core/music.py index 7dc7be5d..d9cc7187 100644 --- a/src/core/music.py +++ b/src/core/music.py @@ -8,6 +8,8 @@ from bt import plugin from bt.message import write from bt import signal +from ct import gstreamer + class Plugin(plugin.Plugin): def __init__(self): @@ -19,7 +21,9 @@ class Plugin(plugin.Plugin): def loadTrack(self,args): if len(args) == 0: write("Usage: music load track") - return + join = ' ' + path = join.join(args) + gstreamer.load(path) diff --git a/src/core/next.py b/src/core/next.py index 98d9d524..1e8b82e9 100644 --- a/src/core/next.py +++ b/src/core/next.py @@ -5,22 +5,55 @@ __date__ ="$Feb 7, 2010 7:40:01 PM$" from bt import plugin +from bt import signal +from bt.message import write +from bt import sql +from ct import db +import settings + +from manager import run class Plugin(plugin.Plugin): def __init__(self): plugin.Plugin.__init__(self) - self.help = "next" + self.help = "Advance to the next track" + self.usage = "next [, songID]" def open(self): - pass + if settings.has("curtrk") == False: + settings.set("curtrk",-1) + signal.register("next",self.next) def close(self): pass - def run(self, args=None): - pass + def next(self): + signal.stop("next") + + curlib = str(settings.get("curlib")) + count = db.countlib(curlib) + nxttrk = settings.get("curtrk") + if nxttrk > count: + nxttrk = 0 + else: + nxttrk += 1 + + sel = sql.Select("track","libtrack","library="+str(curlib)) + rows = sel.execute().fetchall() + run("next",[rows[nxttrk][0], nxttrk]) + + + + def run(self, args=None): + if args==None or len(args)==0: + signal.emit("next") + return + elif len(args) == 1: + write("Usage:" + self.usage) + # db ID, list index + path = db.getpath(args[0],args[1])