From 2d78ea8fc90943db1942758ee3d1744dcabfea94 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Sun, 10 Jan 2010 19:29:39 -0500 Subject: [PATCH] Can list all librarys, gstreamer.py draws a progress bar on the bottom of the CLI --- src/core/lslib.py | 1 + src/core/next.py | 12 ++++++++++- src/core/ocarina.py | 2 +- src/core/tools/database.py | 11 ---------- src/core/tools/gstreamer.py | 41 ++++++++++++++++++++++++++++++++++++- src/extra/__init__.py | 2 ++ src/{core => extra}/rand.py | 11 +++++----- src/ocarina | 5 +++-- 8 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 src/extra/__init__.py rename src/{core => extra}/rand.py (88%) diff --git a/src/core/lslib.py b/src/core/lslib.py index bd14071d..cfb9e947 100644 --- a/src/core/lslib.py +++ b/src/core/lslib.py @@ -42,3 +42,4 @@ def run(args=None): for lib in result: write(lib[1]+"\t"+lib[2]) + return result diff --git a/src/core/next.py b/src/core/next.py index d8460c7d..7e465b71 100644 --- a/src/core/next.py +++ b/src/core/next.py @@ -36,7 +36,7 @@ def next(): def open(): if settings.has("current") == False: settings.set("current",0) - settings.set("next",next) + settings.init("next",next) # Called every time the plugin is stopped @@ -55,7 +55,17 @@ def run(args=None): database.open() a = database.select("path","library","id="+curlib).fetchone()[0] b = database.select("path","track","id="+str(id)).fetchone()[0] + + info = database.select("track.name, artist.name, album.name", + "track, album, artist", + "track.id="+str(id)+" and track.artist=artist.id and track.album=album.id").fetchone() + database.close() settings.set("current",curtrk) manager.run("load",([a+b])) + + write(info[0]) + write("By: "+info[1]) + write("From: "+info[2]) + manager.run("play") diff --git a/src/core/ocarina.py b/src/core/ocarina.py index 32b178c2..e0bbcf91 100644 --- a/src/core/ocarina.py +++ b/src/core/ocarina.py @@ -25,7 +25,7 @@ from tools import gstreamer settings.set("user", join(settings.get("user"),".ocarina2")) mkdir(settings.get("user")) -manager.restoresession() +#manager.restoresession() bt.proc.setname("Ocarina2") diff --git a/src/core/tools/database.py b/src/core/tools/database.py index 7a9d3982..1f31ad79 100644 --- a/src/core/tools/database.py +++ b/src/core/tools/database.py @@ -4,22 +4,11 @@ __author__="bjschuma" __date__ ="$Dec 27, 2009 9:58:50 PM$" -global name, app, type, path, opt -name = "database" -app = "ocarina" -type = "core" -path = "" -opt = [] - - import settings from bt.file import * import sqlite3 -#global conn, c -#conn = None -#c = None global db global conn global vals diff --git a/src/core/tools/gstreamer.py b/src/core/tools/gstreamer.py index c23af27f..f0b08f2e 100644 --- a/src/core/tools/gstreamer.py +++ b/src/core/tools/gstreamer.py @@ -8,9 +8,14 @@ from bt.file import * import gst import settings +from manager import manager +from cline import message global pipeline pipeline = None +global time +time = gst.Format(gst.FORMAT_TIME) + def load(filename): @@ -18,7 +23,7 @@ def load(filename): if checkPath(filename) == False: return - write("loading file: "+filename) + write("loading file: "+filename,True) bin = gst.element_factory_make("playbin", None) bin.set_property("uri", "file://"+filename) bin.set_state(gst.STATE_PAUSED) @@ -39,6 +44,37 @@ def pause(): pipeline.set_state(gst.STATE_PAUSED) +def progress(): + global pipeline + global time + + # Don't bother to go on if the pipeline isn't playing + if not pipeline.get_state()[1] == gst.STATE_PLAYING: + return -1 + + position = pipeline.query_position(time)[0] + total = pipeline.query_duration(time)[0] + return float(position) / float(total) + + + +# If the song is done, play the next song +def done(): + p = progress() + + if p == -1: + return + + max = int(settings.get("maxyx")[1] * p) + bar = "=" + message.disp(bar*max, settings.get("maxyx")[0]-1) + + + if p == 1.0: + #if position == total: + manager.run("next") + + # Called every time the plugin is enabled @@ -47,6 +83,9 @@ def init(): pipeline = gst.Pipeline() pipeline.set_state(gst.STATE_NULL) songs = settings.get("args") + + settings.set("everyloop",done) + if len(songs) > 0: load(songs[0]) settings.replace("args", []) diff --git a/src/extra/__init__.py b/src/extra/__init__.py new file mode 100644 index 00000000..bb4d3239 --- /dev/null +++ b/src/extra/__init__.py @@ -0,0 +1,2 @@ +__author__="bjschuma" +__date__ ="$Jan 9, 2010 8:07:29 PM$" \ No newline at end of file diff --git a/src/core/rand.py b/src/extra/rand.py similarity index 88% rename from src/core/rand.py rename to src/extra/rand.py index a3393eb7..3852c6fa 100644 --- a/src/core/rand.py +++ b/src/extra/rand.py @@ -7,7 +7,7 @@ __date__ ="$Jan 2, 2010 1:14:04 PM$" global name, app, type, path, opt name = "rand" app = "ocarina" -type = "core" +type = "extra" path = "" opt = [] @@ -17,7 +17,7 @@ import random import settings -def next(): +def randnext(): cur = str(settings.get("curlib")) count = database.select("count(*)","libtrack","library="+cur).fetchone()[0] id = random.randint(0,count) @@ -28,10 +28,9 @@ def next(): # Called every time the plugin is enabled def open(): - if settings.has("random") == False: - settings.set("random",False) - else: - settings.set("next",next) + settings.init("random",False) + if settings.get("random") == True: + settings.set("next",randnext) # Called every time the plugin is stopped diff --git a/src/ocarina b/src/ocarina index a80c2ce3..f06e4932 100755 --- a/src/ocarina +++ b/src/ocarina @@ -1,4 +1,5 @@ #!/bin/bash -PLUG=`pwd`/`dirname $0`"/core" -cd && `which scion` "-p $PLUG" $* \ No newline at end of file +CORE=`pwd`/`dirname $0`"/core" +EXTRA=`pwd`/`dirname $0`"/extra" +cd && `which scion` "-p $CORE -p $EXTRA" $* \ No newline at end of file