Began work on ocarina 3

This commit is contained in:
bjschuma 2010-03-14 21:29:38 -04:00
parent 48c79e78dc
commit f058eda485
29 changed files with 855 additions and 727 deletions

43
src/core/cli.py Normal file
View File

@ -0,0 +1,43 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 13, 2010 9:08:56 PM$"
import readline
import rlcompleter
from ct import cmd
import ocarina
readline.parse_and_bind("tab:complete")
global quit
quit = False
def loop():
global quit
while quit == False:
try:
s = raw_input(ocarina.vars["$prompt"] + " ")
cmd.run(s)
except:
ocarina.events.start("ocarina-stop")
def uninit():
global quit
quit = True
#def init():
# ocarina.events.invite("ocarina-start",loop)
# ocarina.events.invite("ocarina-stop",uninit)
ocarina.events.invite("ocarina-start",loop)
ocarina.events.invite("ocarina-stop",uninit)

View File

@ -1,5 +1,5 @@
__author__="bjschuma"
__date__ ="$Jan 27, 2010 6:20:54 PM$"
__date__ ="$Mar 13, 2010 4:20:16 PM$"
__all__ = ["db"]
__all__ = ["cmd", "dict", "message", "opts", "path", "plugin","slist"]

113
src/core/ct/cmd.py Normal file
View File

@ -0,0 +1,113 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Feb 20, 2010 2:19:10 PM$"
from ct.message import *
from ocarina import alias
from ocarina import plugins
from ocarina import vars
def runCmd(input):
write("Running command: "+input,2)
# Find command
split = input.split(' ',1)
cmd = split[0]
args=None
if len(split) > 1:
args = split[1]
try:
result = ocarina.plugins.run(cmd,args)
except:
result = None
if result == None:
return input
else:
return result
# Check if we are storing in a variable
def varCheck(cmd):
split = cmd.split('=', 1)
if len(split)==2 and len(split[0].split())==1:
var = split[0].strip()
if not var[0]=="$":
var = "$" + var
write("Using variable: "+var, 2)
return ( var, split[1].strip() )
else:
return (None, cmd)
# Replace variables in the command with their real values
def varReplace(cmd):
for key in vars.keys():
v = "`"+key+"`"
if cmd.find(v) > -1:
new = str(vars[key])
write(key + " => " + new, 2)
cmd = cmd.replace(v, new)
return cmd
# Replace aliases with their real values
def aliasReplace(cmd):
split = cmd.split()
out = ""
for index,word in enumerate(split):
if index > 0:
out += " "
if alias.has(word) == True:
write(word + " => " + alias[word], 2)
out += aliasReplace(alias[word])
else:
out += word
return out
def fixType(text):
if text.lower() == "false":
return False
elif text.lower() == "true":
return True
elif text.isdigit()==True:
return int(text)
return text
def run(string):
split = string.split(";")
ans = []
for cmd in split:
(var,cmd) = varCheck(cmd)
cmd = varReplace(cmd)
cmd = aliasReplace(cmd)
if var == None:
ans += [ runCmd(cmd) ]
else:
disable()
vars[var] = fixType( runCmd(cmd) )
enable()
if len(ans) == 1:
return ans[0]
return ans
def call(string):
# disable text printing
disable()
result = run(string)
# enable text printing
enable()
return result

View File

@ -1,150 +0,0 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 27, 2010 6:21:27 PM$"
from bt.message import write
from sqlite3 import *
from bt import sql
import settings
def init():
if sql.dbexists() == True:
return
table = sql.CTable("library")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.addcol("path","TEXT","UNIQUE")
table.execute()
table = sql.CTable("artist")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.execute()
table = sql.CTable("album")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("name","TEXT","UNIQUE")
table.execute()
table = sql.CTable("track")
table.addcol("id","INTEGER","PRIMARY KEY AUTOINCREMENT")
table.addcol("artist","INTEGER")
table.addcol("album","INTEGER")
table.addcol("count","INTEGER")
table.addcol("length","INTEGER")
table.addcol("name","TEXT")
table.addcol("path","TEXT","UNIQUE")
table.execute()
table = sql.CTable("libtrack")
table.addcol("library","INTEGER")
table.addcol("track","INTEGER")
table.execute()
def newlib(name,path):
try:
ins = sql.Insert('library',[None,name,path])
ins.execute()
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,name","library","name='"+name+"'")
result = sel.execute().fetchone()
if result == []:
return
libid = result[0]
name = result[1]
sel = sql.Select("track","libtrack","library="+str(libid))
result = sel.execute().fetchall()
for track in result:
where = "track="+str(track[0])+" AND library!="+str(libid)
sel = sql.Select("track,library","libtrack",where )
r = sel.execute().fetchall()
# If track is not in any other library, it can be removed
if r == []:
rmtrk(track[0])
rm = sql.Remove("library","name='"+name+"'")
rm.execute()
rm = sql.Remove("libtrack","library="+str(libid))
rm.execute()
write("Removed library: "+name)
def libid(libname):
sel = sql.Select("id","library","name='"+libname+"'")
result = sel.execute().fetchone()
if result == None:
return None
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 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] + " " + count + " " + row[2] )
write("Current: "+curname)
def getpath(dbid):
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]
return root+track

17
src/core/ct/dict.py Normal file
View File

@ -0,0 +1,17 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Feb 24, 2010 8:59:47 PM$"
class Dict(dict):
def __init__(self):
dict.__init__(self)
def has(self,key):
return (key in self.keys())

View File

@ -1,160 +0,0 @@
#! /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
import manager
import cline
global pipeline
global time
global bin
global bus
pipeline = gst.Pipeline("player")
bin = gst.element_factory_make("playbin",None)
bin.set_state(gst.STATE_NULL)
time = gst.Format(gst.FORMAT_TIME)
# Volume range goes from 0 to 1.0 (before sounding bad)
volume = gst.element_factory_make("volume","vol")
pipeline.add(bin,volume)
bus = pipeline.get_bus()
def load(path):
path = expandPath(path)
if checkPath(path) == False:
return
write("loading file: "+path, True)
global bin
bin.set_property("uri", "file://"+path)
bin.set_state(gst.STATE_PAUSED)
def play():
global pipeline
#if not pipeline == None:
pipeline.set_state(gst.STATE_PLAYING)
#else:
# manager.run("next",settings.get("cursong"))
def pause():
global pipeline
if not pipeline == None:
pipeline.set_state(gst.STATE_PAUSED)
def setvol(value):
global pipeline
curvol = float( settings.get("volume") )
vol = pipeline.get_by_name("vol")
if value == "up":
value = curvol + 0.05
elif value == "down":
value = curvol - 0.05
else:
# Prevent converting strings
try:
value = float(value)
except:
return
if value > 1.0:
value = 1.0
if value < 0.0:
value = 0.0
settings.set("volume",value)
vol.set_property("volume",value )
def getProgress(tuple=False):
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]
if tuple==False:
return float(position) / float(total)
else:
return (position,total)
# Draw the progress bar on the command line
def drawProgress():
p = getProgress()
if p == -1:
return
win = settings.get("maxyx")
max = int(win[1] * p)
if max > win[1]:
max = win[1]
if max == 0:
cline.message.disp(" "*(win[1]-1) ,win[0]-1)
else:
cline.message.disp("="*max, win[0]-1)
# A callback when there are messages on the bus
def onMessage(bus,message):
if message.type == gst.MESSAGE_EOS:
manager.run("next")
# Manually check the bus for messages
def checkBus():
global bus
if bus.peek() == None:
return
onMessage(bus,bus.pop())
def init():
# Register signals
signal.register("play",play)
signal.register("pause",pause)
signal.register("cliloop",drawProgress)
signal.register("cliloop",checkBus,90)
# Check for settings values
if settings.has("args") == True:
input = settings.get("args")
if not input == []:
join = ' '
path = join.join(input)
load(path)
else:
if settings.has("curtrk")==True:
track = settings.get("curtrk")
if track > 0:
manager.run("next",[track,False])
if settings.has("volume") == False:
settings.set("volume",1.0)
setvol(settings.get("volume"))
def close():
global pipeline
global bin
pause()
pipeline.set_state(gst.STATE_NULL)
bin.set_state(gst.STATE_NULL)

25
src/core/ct/message.py Normal file
View File

@ -0,0 +1,25 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 13, 2010 4:32:22 PM$"
import ocarina
global enabled
enabled = True
def write(s,verbose=0):
global enabled
if (enabled==True) and (ocarina.vars["$verbose"] >= verbose):
s = str(s)
print s
def disable():
global enabled
enabled = False
def enable():
global enabled
enabled = True

42
src/core/ct/opts.py Normal file
View File

@ -0,0 +1,42 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 13, 2010 4:37:46 PM$"
import sys
import re
from ct.dict import Dict
# option -> number of times passed
global opts
opts = Dict()
global args
args = []
def parseOpt(opt):
global opts
if opts.has(opt) == False:
opts[opt] = 1
else:
opts[opt] += 1
def parseShort(opt):
for l in opt:
parseOpt(l)
def parse():
global args
for arg in sys.argv[1:]:
if re.match("-(?!-)(.*?)",arg):
parseShort(arg[1:])
elif re.match("--(.*?)",arg):
parseOpt(arg[2:])
else:
args += [arg]

40
src/core/ct/path.py Normal file
View File

@ -0,0 +1,40 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 13, 2010 5:27:12 PM$"
import os
import sys
import re
def expand(path):
return os.path.expanduser(path)
def join(a,b):
return os.path.join(a,b)
def exists(path):
return os.path.exists( path )
def ls(path):
try:
return os.listdir(path)
except:
return None
def addPyPath(path):
mods = []
if exists(path) == True:
sys.path.append(path)
for file in ls(path):
if re.match("(.*?)\.py(?!c)",file):
mods += [file.rsplit(".py",1)[0]]
return mods

49
src/core/ct/plugin.py Normal file
View File

@ -0,0 +1,49 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 14, 2010 2:58:02 PM$"
import inspect
import os
from ct.message import write
class Plugin:
def __init__(self):
self.enabled = True
self.help = dict()
self.usage = dict()
self.minarg = 0
def open(self):
pass
def close(self):
pass
def run(self,args):
return None
def start(self,args=None):
if len(args) < self.minarg:
return
try:
return self.run(args)
# Find out information about the error
except Exception,e:
trace = inspect.trace()
frame = trace[len(trace)-1]
filename = frame[1]
lineno = str(frame[2])
filename = filename.rsplit(os.sep,1)[1]
write(filename+" ("+lineno+"): "+str(e))

22
src/core/ct/slist.py Normal file
View File

@ -0,0 +1,22 @@
__author__="bjschuma"
__date__ ="$Feb 22, 2010 10:52:13 PM$"
# This is a sorted list (as long as items are inserted with add() )
class Slist(list):
def __init__(self):
list.__init__(self)
def add(self, item, priority):
self += [(priority,item)]
self.sort()
def remove(self, item):
for tuple in self:
if tuple[1] == item:
list.remove(self,tuple)
break

View File

@ -1,173 +0,0 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 30, 2010 3:57:53 PM$"
from bt import sql
from bt import needle
from bt.file import *
from bt.message import write
import tagpy
import re
global total
global scanned
global added
global root
global goodFiles
global search
global libid
total = 0
added = 0
scanned = 0
root = ""
goodFiles = ["ogg", "mp3"]
# Generate search string (allows adding to goodFiles later)
def genSearch():
global goodFiles
global search
search = ".*\.("
for index,file in enumerate(goodFiles):
if index > 0:
search += "|"
search += file
search += ")"
genSearch()
# Test if the file extension is in goodFiles
def testPath(path):
global search
match = re.search(search,path,re.IGNORECASE)
if match == None:
return False
return True
def incr(path):
global total
total += 1
# Call to insert either an artist or an album
def insartalb(table,value):
if value == "":
value = "Unknown "+table.title()
#value = value.replace("\'","\'\'")
sel = sql.Select("id",table,'name="' + value + '"')
result = sel.execute().fetchall()
if result == []:
ins = sql.Insert(table,[None,value])
ins.execute()
result = sel.execute().fetchall()
return result[0][0]
# Call to insert a new track
def instrk(arid, alid, title, length, path):
global root
global libid
if title == "":
title = "Unknown Title"
path = path[len(root):]
sel = sql.Select("id","track",'path="'+path+'"')
result = sel.execute().fetchall()
if result == []:
ins = sql.Insert("track", [None, arid, alid, 0, length, title, path] )
ins.execute()
result = sel.execute().fetchall()
trid = str(result[0][0])
where = "library='"+libid+"' AND track='"+trid+"'"
sel = sql.Select("*","libtrack",where)
result = sel.execute().fetchall()
if result == []:
ins = sql.Insert("libtrack",[int(libid),int(trid)])
ins.execute()
def addtrk(path):
global added
global scanned
scanned += 1
try:
f = tagpy.FileRef(path)
t = f.tag()
added += 1
except:
return
try:
arid = insartalb("artist", t.artist)
alid = insartalb("album", t.album)
a = f.audioProperties()
instrk(arid, alid, t.title, a.length, path)
except:
write("Error adding: "+path)
#pass
def scan((dir,func)):
files = ls(dir)
for file in files:
path = join(dir,file)
if checkDir(path) == True:
scan((path,func))
else:
if testPath(path) == True:
func(path)
def go(name):
global total
global added
global scanned
global root
global libid
total = 0
added = 0
scanned = 0
sel = sql.Select("id,path","library","name='"+name+"'")
result = sel.execute().fetchall()
if result == []:
return
libid = str(result[0][0])
path = result[0][1]
root = path
# Start a thread to count the total number of files to scan
totthr = needle.Needle(scan,(path,incr))
totthr.start()
# Start a thread to actually add tracks to the db
scthr = needle.Needle(scan,(path,addtrk))
scthr.start()
def prcnt():
global total
global scanned
global added
write( str(scanned) + " / " + str(total) )
write( "Added " + str(added) + " tracks." )

76
src/core/event.py Normal file
View File

@ -0,0 +1,76 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Feb 24, 2010 9:13:41 PM$"
from ct.dict import Dict
from ct.slist import Slist
# Maintain the list of guests
class GuestList(Slist):
def __init__(self,name):
Slist.__init__(self)
self.name = name
self.active = False
class Event(Dict):
def __init__(self):
Dict.__init__(self)
def type(self,guest):
return type(guest).__name__
# Add a "guest" (function or script) to this event
def invite(self, name, guest, priority=None):
if priority==None:
if self.type(guest)=='str' or self.type(guest)=='unicode':
priority = 200
elif self.type(guest)=='function' or self.type(guest)=='instancemethod':
priority = 100
if self.has(name) == False:
self[name] = GuestList(name)
self[name].add(guest, priority)
# Remove a guest from the guest list
def uninvite(self, name, guest):
self[name].remove(guest)
def stop(self,name):
self[name].active = False
# Start the party!
def start(self,name,args=None):
if self.has(name) == False:
return
self[name].active = True
for priority,guest in self[name]:
if self[name].active == True:
if self.type(guest)=='unicode' or self.type(guest)=='str':
import scripting
scripting.runScript(guest)
elif args==None:
guest()
else:
guest(args)
self.stop(name)

170
src/core/gstreamer.py Normal file
View File

@ -0,0 +1,170 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Feb 5, 2010 7:53:19 PM$"
import gst
import ocarina
from ct.opts import args
from ct.message import write
from ct import path
global player
global time
player = gst.element_factory_make("playbin2","player")
time = gst.Format(gst.FORMAT_TIME)
bus = player.get_bus()
volume = gst.element_factory_make("volume","vol")
player.add(volume)
# Volume range goes from 0 to 1.0 (before sounding bad)
volume.set_property("volume",1.0)
def load(song):
song = path.expand(song)
if path.exists(song) == False:
write("Path does not exist: "+song)
return
write("Loading file: "+song,1)
global player
player.set_state(gst.STATE_NULL)
player.set_property("uri","file://"+song)
if ocarina.vars["$playonload"] == True:
player.set_state(gst.STATE_PLAYING)
else:
player.set_state(gst.STATE_PAUSED)
def uninit():
global player
player.set_state(gst.STATE_NULL)
def init():
#ocarina.events.invite("ocarina-stop",uninit)
if len(args) == 0:
return
space = ' '
song = space.join(args)
load(song)
def play():
global player
write("Gstreamer state: playing",1)
player.set_state(gst.STATE_PLAYING)
def pause():
global player
write("Gstreamer state: paused",1)
player.set_state(gst.STATE_PAUSED)
ocarina.events.invite("ocarina-start",init)
ocarina.events.invite("ocarina-stop",uninit)
#
#def setvol(value):
# global pipeline
# curvol = float( settings.get("volume") )
#
# vol = pipeline.get_by_name("vol")
# if value == "up":
# value = curvol + 0.05
# elif value == "down":
# value = curvol - 0.05
# else:
# # Prevent converting strings
# try:
# value = float(value)
# except:
# return
#
# if value > 1.0:
# value = 1.0
# if value < 0.0:
# value = 0.0
# settings.set("volume",value)
# vol.set_property("volume",value )
#
#
#def getProgress(tuple=False):
# 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]
# if tuple==False:
# return float(position) / float(total)
# else:
# return (position,total)
#
#
## Draw the progress bar on the command line
#def drawProgress():
# p = getProgress()
# if p == -1:
# return
# win = settings.get("maxyx")
# max = int(win[1] * p)
# if max > win[1]:
# max = win[1]
# if max == 0:
# cline.message.disp(" "*(win[1]-1) ,win[0]-1)
# else:
# cline.message.disp("="*max, win[0]-1)
#
#
## A callback when there are messages on the bus
#def onMessage(bus,message):
# if message.type == gst.MESSAGE_EOS:
# manager.run("next")
#
#
## Manually check the bus for messages
#def checkBus():
# global bus
# if bus.peek() == None:
# return
# onMessage(bus,bus.pop())
#
#
#
#def init():
# # Register signals
# signal.register("play",play)
# signal.register("pause",pause)
# signal.register("cliloop",drawProgress)
# signal.register("cliloop",checkBus,90)
#
# # Check for settings values
# if settings.has("args") == True:
# input = settings.get("args")
# if not input == []:
# join = ' '
# path = join.join(input)
# load(path)
# else:
# if settings.has("curtrk")==True:
# track = settings.get("curtrk")
# if track > 0:
# manager.run("next",[track,False])
# if settings.has("volume") == False:
# settings.set("volume",1.0)
# setvol(settings.get("volume"))
#
#
#def close():
# global pipeline
# global bin
# pause()
# pipeline.set_state(gst.STATE_NULL)
# bin.set_state(gst.STATE_NULL)

View File

@ -1,69 +0,0 @@
# Basic plugin class
__author__="bjschuma"
__date__ ="$Jan 27, 2010 6:16:01 PM$"
from bt import plugin
from bt.file import expandPath
from bt.message import write
from ct import db
from ct import update
import settings
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Used to access various parts of the library"
self.usage = "library [create, list, prcnt, remove, switch, update]"
def open(self):
if settings.has("curlib") == False:
settings.set("curlib",-1)
def create(self,args):
usage = "Usage: library create name path"
if len(args) < 2:
write(usage)
return
name = args[0]
join = ' '
path = expandPath(join.join(args[1:]))
db.newlib(name,path)
if settings.get("curlib")==-1:
settings.set("curlib",db.libid(name))
def remove(self,args):
usage = "Usage: library remove name"
if len(args) < 1:
write(usage)
return
name = args[0]
db.rmlib(name)
def run(self, args=None):
if (args==None) or (len(args)==0):
write(self.usage)
return
if args[0] == "create":
self.create(args[1:])
elif args[0] == "list":
db.listlib()
elif args[0] == "remove":
self.remove(args[1:])
elif args[0] == "update":
update.go(args[1])
elif args[0] == "prcnt":
update.prcnt()
elif args[0] == "switch":
newLib = db.libid(args[1])
if not newLib == None:
settings.set("curlib",newLib)

56
src/core/manager.py Normal file
View File

@ -0,0 +1,56 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 14, 2010 3:06:37 PM$"
import re
import sys
import ocarina
from ct.message import write
from ct import path
from ct.dict import Dict
class PlManager(Dict):
def __init__(self):
Dict.__init__(self)
write("Creating Plugin Manager",1)
#self.plugins = dict()
def load(self, name):
write("Importing plugin: "+name, 2)
__import__(name)
plugin = sys.modules[name].Plugin()
plugin.enabled = True
self[name] = plugin
def run(self,name,args=None):
if self[name].enabled == True:
if args == None:
args = []
else:
args = args.split()
return self[name].start(args)
return None
def init():
ocarina.plugins = PlManager()
for p in ocarina.vars["$path"].split(":"):
for mod in path.addPyPath(p):
ocarina.plugins.load(mod)
ocarina.events.invite("ocarina-start",init,5)

View File

@ -1,78 +0,0 @@
# 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 sql
from bt import signal
from ct import gstreamer
import settings
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Used to control various aspects of playback"
self.usage = "music [load, whatis, now, pause, play, vol]"
def loadTrack(self,args):
if len(args) == 0:
write("Usage: music load track")
join = ' '
path = join.join(args)
write("Loading: "+path,True)
gstreamer.close()
gstreamer.load(path)
def whatIs(self,id):
curlib = str( settings.get("curlib") )
selstr = "track.name,artist.name,album.name"
frmstr = "track,artist,album,libtrack"
whrstr = "track.artist=artist.id AND track.album=album.id"
whrstr += " AND libtrack.track=track.id AND libtrack.library="+curlib
sel = sql.Select(selstr, frmstr, whrstr)
result = sel.execute().fetchall()
result = result[id]
write(result[0])
write("By: "+result[1])
write("From: "+result[2])
def nowPlaying(self):
self.whatIs(settings.get("curtrk"))
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] == "whatis":
id = int(args[1])
self.whatIs(id)
elif args[0] == "now":
self.nowPlaying()
elif args[0] == "play":
signal.emit("play")
elif args[0] == "pause":
signal.emit("pause")
elif args[0] == "vol":
gstreamer.setvol(args[1])

View File

@ -1,76 +0,0 @@
# Basic plugin class
__author__="bjschuma"
__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
import manager
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Advance to the next track"
self.usage = "next [, songID]"
def open(self):
if settings.has("curtrk") == False:
settings.set("curtrk",-1)
signal.register("next",self.next)
def close(self):
pass
def next(self):
signal.stop("next")
curlib = str(settings.get("curlib"))
count = db.countlib(curlib)
nxttrk = settings.get("curtrk")
if nxttrk >= (count-1):
nxttrk = 0
else:
nxttrk += 1
manager.run("next",[nxttrk])
def run(self, args=None):
# args: new current track number
if args==None or len(args)==0:
signal.emit("next")
return
nxttrk = int(args[0])
play = True
if len(args)>1 and bool(args[1])==False:
play = False
curlib = str( settings.get("curlib") )
sel = sql.Select("track","libtrack","library="+curlib)
rows = sel.execute().fetchall()
if nxttrk >= len(rows)-1:
nxttrk = len(rows)-1
next = rows[nxttrk][0]
path = db.getpath(next)
settings.set("curtrk",nxttrk)
manager.run("music",["load",path])
if play==True:
manager.run("music",["play"])
manager.run("music",["now"])

23
src/core/ocarina-core.py Normal file
View File

@ -0,0 +1,23 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 13, 2010 4:19:31 PM$"
import ocarina
from ct.message import write
import scripting
import manager
import cli
import gstreamer
def main():
ocarina.init()
# Potentially the first thing printed
write("Welcome to Ocarina (core)", 1)
ocarina.events.start("ocarina-start")
if __name__ == "__main__":main()

View File

@ -1,28 +1,40 @@
# Basic plugin class
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Jan 25, 2010 12:18:21 AM$"
__date__ ="$Mar 13, 2010 4:19:39 PM$"
from bt.message import write
from bt import plugin
import settings
settings.set("appname","ocarina2")
from ct import db
from ct import gstreamer
from ct.dict import Dict
from ct import opts
from ct import path
import event
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "A simple music player written in python"
global settings
global vars
global events
global plugins
global alias
settings = Dict()
vars = Dict()
alias = Dict()
events = event.Event()
plugins = None
def open(self):
db.init()
gstreamer.init()
# Set default values
def init():
opts.parse()
vars["$user"] = path.expand("~")
vars["$ocarina"] = path.join(vars["$user"],".ocarina3")
vars["$verbose"] = 0
vars["$path"] = "coreplug"
vars["$prompt"] = ">>>"
vars["$playonload"] = True
def close(self):
gstreamer.close()
# Set verbose value
if opts.opts.has("v") == True:
vars["$verbose"] += opts.opts["v"]
if opts.opts.has("verbose") == True:
vars["$verbose"] += opts.opts["verbose"]

26
src/core/scripting.py Normal file
View File

@ -0,0 +1,26 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 14, 2010 7:33:16 PM$"
from ct import cmd
import ocarina
def runScript(file):
fin = open(file)
for line in fin:
# Do some formatting for each line
line = line.split("#",1)[0]
line = line.strip()
if len(line) > 0:
cmd.run(line)
def init():
runScript("corescr/init.oc")
ocarina.events.invite("ocarina-start",init,10)

18
src/coreplug/echo.py Normal file
View File

@ -0,0 +1,18 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 14, 2010 4:29:57 PM$"
from ct import plugin
from ct.message import write
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
def run(self,args):
space = ' '
write(space.join(args))

20
src/coreplug/exit.py Normal file
View File

@ -0,0 +1,20 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Mar 14, 2010 3:02:10 PM$"
import ocarina
from ct import plugin
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
def run(self,args):
ocarina.events.start("ocarina-stop")
#print args

26
src/coreplug/list.py Normal file
View File

@ -0,0 +1,26 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 14, 2010 7:17:57 PM$"
import ocarina
from ct import plugin
from ct.message import write
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.minarg = 1
def run(self,args):
for arg in args:
arg = arg.lower()
if arg == "events":
write(ocarina.events.keys())
elif arg == "plugins":
write(ocarina.plugins.keys())
elif arg == "vars":
write(ocarina.vars.keys())

18
src/coreplug/load.py Normal file
View File

@ -0,0 +1,18 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 14, 2010 5:25:41 PM$"
from ct import plugin
import gstreamer
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
def run(self,args):
space = " "
gstreamer.load(space.join(args))

16
src/coreplug/pause.py Normal file
View File

@ -0,0 +1,16 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 14, 2010 5:16:51 PM$"
from ct import plugin
import gstreamer
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
def run(self,args):
gstreamer.pause()

17
src/coreplug/play.py Normal file
View File

@ -0,0 +1,17 @@
#! /usr/bin/python
__author__="bjschuma"
__date__ ="$Mar 14, 2010 5:12:02 PM$"
from ct import plugin
import gstreamer
class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
def run(self,args):
gstreamer.play()

2
src/corescr/init.oc Normal file
View File

@ -0,0 +1,2 @@
$playonload = False
#load ~/Music/theme-pokemon.mp3

3
src/ocarina-core Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
python core/ocarina-core.py $*