Began work on virtual sources
Virtual sources should make it easier to do things with the current song without having to know anything about it (such as a song id or file path).
This commit is contained in:
parent
8c2151b862
commit
f063da5b56
|
@ -27,15 +27,6 @@ def end_of_song():
|
||||||
return call("EOS", audio.reset)
|
return call("EOS", audio.reset)
|
||||||
|
|
||||||
|
|
||||||
def load(file):
|
|
||||||
global audio
|
|
||||||
global expand
|
|
||||||
file = expand(file)
|
|
||||||
if not exists(file):
|
|
||||||
return False
|
|
||||||
return call("LOAD", audio.load, file)
|
|
||||||
|
|
||||||
|
|
||||||
def seek(prcnt):
|
def seek(prcnt):
|
||||||
global audio
|
global audio
|
||||||
return call("SEEK", audio.seek, prcnt)
|
return call("SEEK", audio.seek, prcnt)
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
# Bryan Schumaker (11/23/2010)
|
# Bryan Schumaker (11/23/2010)
|
||||||
|
|
||||||
libsaria = None
|
libsaria = None
|
||||||
|
sources = None
|
||||||
|
library = None
|
||||||
|
playlist = None
|
||||||
|
|
||||||
audio = None
|
audio = None
|
||||||
call = None
|
call = None
|
||||||
invite = None
|
invite = None
|
||||||
prefs = None
|
prefs = None
|
||||||
|
expand = None
|
||||||
|
exists = None
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global libsaria
|
global libsaria
|
||||||
|
@ -17,13 +22,38 @@ def init2():
|
||||||
global audio
|
global audio
|
||||||
global invite
|
global invite
|
||||||
global prefs
|
global prefs
|
||||||
|
global sources
|
||||||
|
global library
|
||||||
|
global playlist
|
||||||
|
global expand
|
||||||
|
global exists
|
||||||
|
|
||||||
call = libsaria.event.call
|
call = libsaria.event.call
|
||||||
invite = libsaria.event.invite
|
invite = libsaria.event.invite
|
||||||
prefs = libsaria.prefs
|
prefs = libsaria.prefs
|
||||||
|
expand = libsaria.path.expand
|
||||||
|
exists = libsaria.path.exists
|
||||||
|
sources = libsaria.sources
|
||||||
|
library = sources.library
|
||||||
|
playlist = sources.playlist
|
||||||
|
|
||||||
from libsaria.audio import audio
|
from libsaria.audio import audio
|
||||||
invite("PREEOS", pause)
|
invite("PREEOS", pause)
|
||||||
|
invite("POSTEOS", catch_eos)
|
||||||
|
|
||||||
|
def pick_next():
|
||||||
|
file = playlist.next()
|
||||||
|
load(file)
|
||||||
|
play()
|
||||||
|
|
||||||
|
def catch_eos(*args):
|
||||||
|
library.inc_count()
|
||||||
|
library.inc_score()
|
||||||
|
return call("NEXT", pick_next)
|
||||||
|
|
||||||
|
def next():
|
||||||
|
library.change_score()
|
||||||
|
return call("NEXT", pick_next)
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
return call("PLAY", audio.play)
|
return call("PLAY", audio.play)
|
||||||
|
@ -39,3 +69,9 @@ def set_volume(prcnt):
|
||||||
|
|
||||||
def toggle_rand():
|
def toggle_rand():
|
||||||
prefs.set_pref("libsaria.random", not prefs.get_pref("libsaria.random"))
|
prefs.set_pref("libsaria.random", not prefs.get_pref("libsaria.random"))
|
||||||
|
|
||||||
|
def load(file):
|
||||||
|
file = expand(file)
|
||||||
|
if not exists(file):
|
||||||
|
return False
|
||||||
|
return call("LOAD", audio.load, file)
|
||||||
|
|
|
@ -86,7 +86,7 @@ def set_artwork_tags(artist, album, path):
|
||||||
libsaria.event.start("POSTSETART", file)
|
libsaria.event.start("POSTSETART", file)
|
||||||
|
|
||||||
def get_artwork_id(id):
|
def get_artwork_id(id):
|
||||||
artist, album = libsaria.sources.get_attrs(id, "artist", "album")
|
artist, album = libsaria.sources.library.get_attrs(id, "artist", "album")
|
||||||
return get_artwork_tags(artist, album)
|
return get_artwork_tags(artist, album)
|
||||||
|
|
||||||
def get_artwork(filepath):
|
def get_artwork(filepath):
|
||||||
|
|
|
@ -3,22 +3,42 @@
|
||||||
__all__ = ["collection"]
|
__all__ = ["collection"]
|
||||||
|
|
||||||
import libsaria
|
import libsaria
|
||||||
import tagpy
|
|
||||||
call = libsaria.event.call
|
call = libsaria.event.call
|
||||||
exists = libsaria.path.exists
|
exists = libsaria.path.exists
|
||||||
expand = libsaria.path.expand
|
expand = libsaria.path.expand
|
||||||
FileRef = tagpy.FileRef
|
|
||||||
prefs = None
|
prefs = None
|
||||||
|
|
||||||
import library
|
import library
|
||||||
import playlist
|
import playlist
|
||||||
|
|
||||||
get_attrs = library.get_attrs
|
|
||||||
reset = library.reset
|
reset = library.reset
|
||||||
inc_score = library.inc_score
|
inc_score = library.inc_score
|
||||||
inc_count = library.inc_count
|
inc_count = library.inc_count
|
||||||
|
|
||||||
cur_lib_id = -1
|
controls = libsaria.controls
|
||||||
|
|
||||||
|
sources = dict()
|
||||||
|
cur_source = None
|
||||||
|
class Source:
|
||||||
|
def __init__(self, name):
|
||||||
|
self.name = name
|
||||||
|
self.get_attrs = None
|
||||||
|
#self.reset = None
|
||||||
|
#self.load = None
|
||||||
|
#self.walk = None
|
||||||
|
#self.filter = None
|
||||||
|
#self.is_visible = None
|
||||||
|
#self.num_visible = None
|
||||||
|
sources[name] = self
|
||||||
|
|
||||||
|
def load_file(self, path):
|
||||||
|
ret = controls.load(path)
|
||||||
|
cur_source = self.name
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def get_attrs(*attrs):
|
||||||
|
return sources[cur_source].get_attrs(attrs)
|
||||||
|
|
||||||
|
|
||||||
def new_source(path, bg=True):
|
def new_source(path, bg=True):
|
||||||
global library
|
global library
|
||||||
|
@ -31,27 +51,7 @@ def lib_get_cur_id():
|
||||||
global cur_lib_id
|
global cur_lib_id
|
||||||
return cur_lib_id
|
return cur_lib_id
|
||||||
|
|
||||||
def change_score():
|
|
||||||
prcnt = libsaria.audio.get_progress()
|
|
||||||
if prcnt > 0.75:
|
|
||||||
inc_count(cur_lib_id)
|
|
||||||
inc_score(cur_lib_id)
|
|
||||||
if prcnt < 0.33:
|
|
||||||
inc_score(cur_lib_id, -1)
|
|
||||||
|
|
||||||
def play_selected_id(id):
|
def play_selected_id(id):
|
||||||
change_score()
|
change_score()
|
||||||
play_id(id)
|
play_id(id)
|
||||||
inc_score(id, 1)
|
inc_score(id, 1)
|
||||||
|
|
||||||
def plist_next():
|
|
||||||
change_score()
|
|
||||||
playlist.next()
|
|
||||||
|
|
||||||
def catch_eos(*args):
|
|
||||||
inc_count(cur_lib_id)
|
|
||||||
inc_score(cur_lib_id)
|
|
||||||
playlist.next()
|
|
||||||
libsaria.event.invite("POSTEOS", catch_eos)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
# Bryan Schumaker (11/05/2010)
|
# Bryan Schumaker (11/05/2010)
|
||||||
|
|
||||||
import os
|
|
||||||
import tagpy
|
|
||||||
import libsaria
|
import libsaria
|
||||||
|
import libsaria.sources
|
||||||
import libsaria.path.files
|
import libsaria.path.files
|
||||||
import string
|
|
||||||
from libsaria import threads
|
from libsaria import threads
|
||||||
from track import Track
|
|
||||||
splitext = libsaria.path.splitext
|
splitext = libsaria.path.splitext
|
||||||
|
|
||||||
|
os = None
|
||||||
|
tagpy = None
|
||||||
|
Track = None
|
||||||
|
|
||||||
|
FileRef = None
|
||||||
fs_tree = None
|
fs_tree = None
|
||||||
tag_tree = None
|
tag_tree = None
|
||||||
index = None
|
index = None
|
||||||
|
@ -16,19 +18,25 @@ tracks = None
|
||||||
locations = None
|
locations = None
|
||||||
size = None
|
size = None
|
||||||
visible = None
|
visible = None
|
||||||
|
source = None
|
||||||
|
|
||||||
FileRef = tagpy.FileRef
|
cur_id = -1
|
||||||
|
|
||||||
lib_lock = threads.get_mutex("library")
|
lib_lock = threads.get_mutex("library")
|
||||||
loaded = False
|
loaded = False
|
||||||
filtered = False
|
filtered = False
|
||||||
badfiles = set()
|
badfiles = set()
|
||||||
|
|
||||||
ttable = dict()
|
def init():
|
||||||
for s in string.punctuation:
|
global source
|
||||||
ttable[ord(s)] = u""
|
import string
|
||||||
for s in string.lowercase:
|
ttable = dict()
|
||||||
ttable[ord(s)] = ord(s) - 32
|
for s in string.punctuation:
|
||||||
|
ttable[ord(s)] = u""
|
||||||
|
for s in string.lowercase:
|
||||||
|
ttable[ord(s)] = ord(s) - 32
|
||||||
|
|
||||||
|
source = libsaria.sources.Source("library")
|
||||||
|
source.get_attrs = get_attrs
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
from libsaria.trees import FSTree, DLFSTree, DLValTree
|
from libsaria.trees import FSTree, DLFSTree, DLValTree
|
||||||
|
@ -75,12 +83,13 @@ def is_loaded():
|
||||||
lib_lock.release()
|
lib_lock.release()
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def load_bg2(callback):
|
def init_bg2(callback):
|
||||||
|
init()
|
||||||
load()
|
load()
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
def load_bg(callback):
|
def init_bg(callback):
|
||||||
thr = threads.BG_Thread(load_bg2, callback)
|
thr = threads.BG_Thread(init_bg2, callback)
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
|
@ -129,7 +138,12 @@ def song_id(artist, album, title):
|
||||||
title = alb[title]
|
title = alb[title]
|
||||||
return title.keys()[0]
|
return title.keys()[0]
|
||||||
|
|
||||||
def get_attrs(id, *attrs):
|
def get_attrs(*attrs):
|
||||||
|
if attrs[0].__class__ != str:
|
||||||
|
id = attrs[0]
|
||||||
|
attrs = attrs[1:]
|
||||||
|
else:
|
||||||
|
id = cur_id
|
||||||
res = []
|
res = []
|
||||||
rec = tracks.get(id, None)
|
rec = tracks.get(id, None)
|
||||||
if rec == None:
|
if rec == None:
|
||||||
|
@ -153,6 +167,8 @@ def get_attrs(id, *attrs):
|
||||||
res += [tags[2]]
|
res += [tags[2]]
|
||||||
else:
|
else:
|
||||||
res += [get(attr, None)]
|
res += [get(attr, None)]
|
||||||
|
if len(res) == 1:
|
||||||
|
return res[0]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def set_attr(id, attr, new_value):
|
def set_attr(id, attr, new_value):
|
||||||
|
@ -165,30 +181,38 @@ def set_attr(id, attr, new_value):
|
||||||
else:
|
else:
|
||||||
rec.__dict__[attr] = new_value
|
rec.__dict__[attr] = new_value
|
||||||
|
|
||||||
def inc_score(id, amount=1):
|
def change_score():
|
||||||
|
prcnt = libsaria.audio.get_progress()
|
||||||
|
if prcnt > 0.75:
|
||||||
|
inc_count(cur_id)
|
||||||
|
inc_score(cur_id)
|
||||||
|
if prcnt < 0.33:
|
||||||
|
inc_score(cur_id, -1)
|
||||||
|
|
||||||
|
def inc_score(id = cur_id, amount=1):
|
||||||
rec = tracks.get(id, None)
|
rec = tracks.get(id, None)
|
||||||
if rec:
|
if rec:
|
||||||
rec.score += amount
|
rec.score += amount
|
||||||
save()
|
save()
|
||||||
|
|
||||||
def inc_count(id):
|
def inc_count(id = cur_id):
|
||||||
rec = tracks.get(id, None)
|
rec = tracks.get(id, None)
|
||||||
if rec:
|
if rec:
|
||||||
rec.count += 1
|
rec.count += 1
|
||||||
save()
|
save()
|
||||||
|
|
||||||
def play_id(id):
|
def play_id(id):
|
||||||
loaded = load_id(id)
|
if load_id(id) == True:
|
||||||
if loaded == True:
|
|
||||||
libsaria.controls.play()
|
libsaria.controls.play()
|
||||||
return loaded
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def load_id(id):
|
def load_id(id):
|
||||||
|
global cur_id
|
||||||
if tracks.get(id, None) == None:
|
if tracks.get(id, None) == None:
|
||||||
return False
|
return False
|
||||||
libsaria.sources.cur_lib_id = id
|
cur_id = id
|
||||||
libsaria.audio.load(get_attrs(id, "filepath")[0])
|
return source.load_file(get_attrs(id, "filepath"))
|
||||||
return True
|
|
||||||
|
|
||||||
def filter(text):
|
def filter(text):
|
||||||
global visible
|
global visible
|
||||||
|
@ -269,6 +293,16 @@ def update_path(path):
|
||||||
print e
|
print e
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
global os
|
||||||
|
global tagpy
|
||||||
|
global FileRef
|
||||||
|
global Track
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tagpy
|
||||||
|
from track import Track
|
||||||
|
FileRef = tagpy.FileRef
|
||||||
|
|
||||||
sep = libsaria.path.sep
|
sep = libsaria.path.sep
|
||||||
for path in locations:
|
for path in locations:
|
||||||
update_path(path)
|
update_path(path)
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
# Bryan Schumaker (11/07/2010)
|
# Bryan Schumaker (11/07/2010)
|
||||||
|
|
||||||
import random as rand
|
|
||||||
|
|
||||||
import libsaria
|
import libsaria
|
||||||
import libsaria.path.files
|
import libsaria.path.files
|
||||||
from libsaria import threads
|
from libsaria import threads
|
||||||
from libsaria.sources import library
|
|
||||||
call = libsaria.event.call
|
call = libsaria.event.call
|
||||||
|
|
||||||
|
|
||||||
|
library = None
|
||||||
|
source = None
|
||||||
|
rand = None
|
||||||
|
|
||||||
song_list = []
|
song_list = []
|
||||||
song_set = set(song_list)
|
song_set = set(song_list)
|
||||||
|
|
||||||
|
@ -29,6 +32,16 @@ def rm_id(id):
|
||||||
song_list.remove(id)
|
song_list.remove(id)
|
||||||
song_set.remove(id)
|
song_set.remove(id)
|
||||||
|
|
||||||
|
def init():
|
||||||
|
global library
|
||||||
|
global rand
|
||||||
|
global source
|
||||||
|
|
||||||
|
import library
|
||||||
|
import random as rand
|
||||||
|
source = libsaria.sources.Source("playlist")
|
||||||
|
source.get_attrs = library.get_attrs
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
global song_list
|
global song_list
|
||||||
global song_set
|
global song_set
|
||||||
|
@ -56,16 +69,18 @@ def load():
|
||||||
if cur_index >= 0:
|
if cur_index >= 0:
|
||||||
libsaria.sources.cur_lib_id = song_list[cur_index]
|
libsaria.sources.cur_lib_id = song_list[cur_index]
|
||||||
|
|
||||||
def load_bg2(callback):
|
def init_bg2(callback):
|
||||||
|
init()
|
||||||
load()
|
load()
|
||||||
while library.is_loaded() == False:
|
while library.is_loaded() == False:
|
||||||
pass
|
pass
|
||||||
callback()
|
callback()
|
||||||
if cur_index >= 0:
|
if cur_index >= 0:
|
||||||
library.load_id(song_list[cur_index])
|
load_id(song_list[cur_index])
|
||||||
|
#library.load_id(song_list[cur_index])
|
||||||
|
|
||||||
def load_bg(callback):
|
def init_bg(callback):
|
||||||
thr = threads.BG_Thread(load_bg2, callback)
|
thr = threads.BG_Thread(init_bg2, callback)
|
||||||
thr.start()
|
thr.start()
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
|
@ -147,11 +162,19 @@ def rand_next():
|
||||||
cur_index = index
|
cur_index = index
|
||||||
return id
|
return id
|
||||||
|
|
||||||
def play_id(id):
|
def load_id(id):
|
||||||
global cur_index
|
global cur_index
|
||||||
cur_index = song_list.index(id)
|
cur_index = song_list.index(id)
|
||||||
library.play_id(id)
|
|
||||||
save()
|
save()
|
||||||
|
path = library.get_attrs(id, "filepath")
|
||||||
|
return source.load_file(path)
|
||||||
|
|
||||||
|
def play_id(id):
|
||||||
|
if load_id(id) == True:
|
||||||
|
print "playing..."
|
||||||
|
libsaria.controls.play()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def next():
|
def next():
|
||||||
id = None
|
id = None
|
||||||
|
@ -162,5 +185,4 @@ def next():
|
||||||
else:
|
else:
|
||||||
id = seq_next()
|
id = seq_next()
|
||||||
if id != None:
|
if id != None:
|
||||||
save()
|
return library.get_attrs(id, "filepath")
|
||||||
return call("NEXT", library.play_id, id)
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ class NextButton(Button):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
Button.__init__(self, gtk.STOCK_MEDIA_NEXT)
|
Button.__init__(self, gtk.STOCK_MEDIA_NEXT)
|
||||||
def clicked(self, button):
|
def clicked(self, button):
|
||||||
LS.sources.plist_next()
|
LS.controls.next()
|
||||||
|
|
||||||
|
|
||||||
class ForwardButton(Button):
|
class ForwardButton(Button):
|
||||||
|
|
|
@ -15,7 +15,7 @@ def set_fns():
|
||||||
global get_attrs
|
global get_attrs
|
||||||
global file_id
|
global file_id
|
||||||
get_time = ocarina.libsaria.audio.get_time
|
get_time = ocarina.libsaria.audio.get_time
|
||||||
get_attrs = libsaria.sources.get_attrs
|
get_attrs = libsaria.sources.library.get_attrs
|
||||||
file_id = libsaria.path.file_id
|
file_id = libsaria.path.file_id
|
||||||
invite("POSTSTART", set_fns)
|
invite("POSTSTART", set_fns)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class AttrLabel(gtk.Alignment):
|
||||||
global get_attrs
|
global get_attrs
|
||||||
id = file_id(filepath)
|
id = file_id(filepath)
|
||||||
if id != None:
|
if id != None:
|
||||||
text = str(get_attrs(id, self.attr)[0])
|
text = str(get_attrs(id, self.attr))
|
||||||
if self.other:
|
if self.other:
|
||||||
text = "%s %s" % (self.other, text)
|
text = "%s %s" % (self.other, text)
|
||||||
self.label.set_text(text)
|
self.label.set_text(text)
|
||||||
|
|
|
@ -20,7 +20,7 @@ pages = dict()
|
||||||
|
|
||||||
def change_title(filepath):
|
def change_title(filepath):
|
||||||
id = libsaria.path.file_id(filepath)
|
id = libsaria.path.file_id(filepath)
|
||||||
(ttl, artst) = libsaria.sources.get_attrs(id, "title", "artist")
|
(ttl, artst) = libsaria.sources.library.get_attrs(id, "title", "artist")
|
||||||
title.set_text("%s by %s" % (ttl, artst))
|
title.set_text("%s by %s" % (ttl, artst))
|
||||||
|
|
||||||
def bar_add(widget, expand = False, fill = False):
|
def bar_add(widget, expand = False, fill = False):
|
||||||
|
|
|
@ -16,7 +16,7 @@ lib_page = source.Source()
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
body.add_page("Library", lib_page)
|
body.add_page("Library", lib_page)
|
||||||
library.load_bg(filler)
|
library.init_bg(filler)
|
||||||
libsaria.event.invite("POSTNEWSOURCE", refresh)
|
libsaria.event.invite("POSTNEWSOURCE", refresh)
|
||||||
|
|
||||||
def filler():
|
def filler():
|
||||||
|
|
|
@ -14,7 +14,7 @@ plist_page = source.Source()
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
body.add_page("Playlist", plist_page)
|
body.add_page("Playlist", plist_page)
|
||||||
playlist.load_bg(filler)
|
playlist.init_bg(filler)
|
||||||
|
|
||||||
def filler():
|
def filler():
|
||||||
plist_page.init(filter, is_visible, right_click, playlist.play_id, reset)
|
plist_page.init(filter, is_visible, right_click, playlist.play_id, reset)
|
||||||
|
|
|
@ -94,7 +94,7 @@ class HTTPRequest(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
def audio_file(self):
|
def audio_file(self):
|
||||||
sid, ext = splitext(self.path.strip("/"))
|
sid, ext = splitext(self.path.strip("/"))
|
||||||
fpath = library.get_attrs(long(sid), "filepath")[0]
|
fpath = library.get_attrs(long(sid), "filepath")
|
||||||
self.other_file(fpath, ext)
|
self.other_file(fpath, ext)
|
||||||
|
|
||||||
def other_file(self, path, ext):
|
def other_file(self, path, ext):
|
||||||
|
|
|
@ -19,7 +19,7 @@ def tweak_icon(file):
|
||||||
def tweak_title(filepath):
|
def tweak_title(filepath):
|
||||||
if filepath != None:
|
if filepath != None:
|
||||||
id = file_id(filepath)
|
id = file_id(filepath)
|
||||||
title = get_attrs(id, "title")[0]
|
title = get_attrs(id, "title")
|
||||||
else:
|
else:
|
||||||
title = ocarina.__vers__
|
title = ocarina.__vers__
|
||||||
window.set_title(title)
|
window.set_title(title)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user