diff --git a/src/core/ct/db.py b/src/core/ct/db.py index 84a19942..d27385ae 100644 --- a/src/core/ct/db.py +++ b/src/core/ct/db.py @@ -52,16 +52,42 @@ def newlib(name,path): try: ins = sql.Insert('library',[None,name,path]) ins.execute() + + #sel = sql.Insert('library') except: pass +def rmtrk(trid): + # Get the artist and album of the track + sel = sql.Select("artist,album","track","id="+str(trid)) + (arid,alid) = sel.execute().fetchone() + + rm = sql.Remove("track","id="+str(trid)) + rm.execute() + + # Remove artist if no other tracks are using this artist + sel = sql.Select("count(*)","track","artist="+str(arid)) + count = sel.execute().fetchone()[0] + if count == 0: + rm = sql.Remove("artist","id="+str(arid)) + rm.execute() + + # Remove album if no other tracks are using this album + sel = sql.Select("count(*)","track","album="+str(alid)) + count = sel.execute().fetchone()[0] + if count == 0: + rm = sql.Remove("album","id="+str(alid)) + rm.execute() + + def rmlib(name): - sel = sql.Select("id","library","name='"+name+"'") - result = sel.execute().fetchall() + sel = sql.Select("id,name","library","name='"+name+"'") + result = sel.execute().fetchone() if result == []: return - libid = result[0][0] + libid = result[0] + name = result[1] sel = sql.Select("track","libtrack","library="+str(libid)) result = sel.execute().fetchall() @@ -72,13 +98,14 @@ def rmlib(name): r = sel.execute().fetchall() # If track is not in any other library, it can be removed if r == []: - write(r) + rmtrk(track[0]) + rm = sql.Remove("library","name='"+name+"'") + rm.execute() - - #rm = sql.Remove("library","name='"+name+"'") - #rm.execute() - #write("Removed library: "+str(libid)) + rm = sql.Remove("libtrack","library="+str(libid)) + rm.execute() + write("Removed library: "+name) def listlib(): diff --git a/src/core/ct/gstreamer.py b/src/core/ct/gstreamer.py new file mode 100644 index 00000000..3fc1f39f --- /dev/null +++ b/src/core/ct/gstreamer.py @@ -0,0 +1,66 @@ +#! /usr/bin/python + +# To change this template, choose Tools | Templates +# and open the template in the editor. + +__author__="bjschuma" +__date__ ="$Feb 5, 2010 7:53:19 PM$" + + +import gst +import settings + +from bt.file import * +from bt import signal +from bt.message import write + +global pipeline +global time +pipeline = None +time = gst.Format(gst.FORMAT_TIME) + + +def load(path): + path = expandPath(path) + if checkPath(path) == False: + return + + write("loading file: "+path, True) + bin = gst.element_factory_make("playbin",None) + bin.set_property("uri", "file://"+path) + bin.set_state(gst.STATE_PAUSED) + + global pipeline + pipeline = gst.Pipeline("player") + pipeline.add(bin) + + +def play(): + global pipeline + if not pipeline == None: + pipeline.set_state(gst.STATE_PLAYING) + + +def pause(): + global pipeline + if not pipeline == None: + pipeline.set_state(gst.STATE_PAUSED) + + +def init(): + # Register signals + signal.register("play",play) + signal.register("pause",pause) + + if settings.has("args") == True: + input = settings.get("args") + if not input == []: + join = ' ' + path = join.join(input) + load(path) + + +def close(): + global pipeline + if not pipeline == None: + pipeline.set_state(gst.STATE_NULL) \ No newline at end of file diff --git a/src/core/library.py b/src/core/library.py index 635cf890..f8ae4c6b 100644 --- a/src/core/library.py +++ b/src/core/library.py @@ -9,6 +9,7 @@ from bt.file import expandPath from bt.message import write from ct import db from ct import update +import settings class Plugin(plugin.Plugin): @@ -18,6 +19,10 @@ class Plugin(plugin.Plugin): self.usage = "library [create, list, prcnt, remove, update]" + def open(self): + settings.set("curlib",-1) + + def create(self,args): usage = "Usage: library create name path" if len(args) < 2: @@ -28,6 +33,8 @@ class Plugin(plugin.Plugin): join = ' ' path = expandPath(join.join(args[1:])) db.newlib(name,path) + if settings.get("curlib")==-1: + settings.set("curlib") def remove(self,args): diff --git a/src/core/music.py b/src/core/music.py new file mode 100644 index 00000000..aa42f65e --- /dev/null +++ b/src/core/music.py @@ -0,0 +1,40 @@ +# Basic plugin class + +__author__="bjschuma" +__date__ ="$Feb 5, 2010 7:47:18 PM$" + + +from bt import plugin +from bt.message import write +from bt import signal + + +class Plugin(plugin.Plugin): + def __init__(self): + plugin.Plugin.__init__(self) + self.help = "Used to control various aspects of playback" + self.usage = "music [load]" + + + def loadTrack(self,args): + if len(args) == 0: + write("Usage: music load track") + return + + + + def run(self, args=None): + if args==None or len(args) < 1: + write(self.help) + return + + if args[0] == "load": + self.loadTrack(args[1:]) + + elif args[0] == "play": + signal.emit("play") + + elif args[0] == "pause": + signal.emit("pause") + + diff --git a/src/core/ocarina.py b/src/core/ocarina.py index 2891a868..92ae73e8 100644 --- a/src/core/ocarina.py +++ b/src/core/ocarina.py @@ -4,11 +4,13 @@ __author__="bjschuma" __date__ ="$Jan 25, 2010 12:18:21 AM$" +from bt.message import write from bt import plugin import settings settings.set("appname","ocarina2") from ct import db +from ct import gstreamer class Plugin(plugin.Plugin): @@ -19,3 +21,8 @@ class Plugin(plugin.Plugin): def open(self): db.init() + gstreamer.init() + + + def close(self): + gstreamer.close()