Merge branch 'master' into Ocarina-4.2
This commit is contained in:
commit
fdcbec5389
|
@ -4,10 +4,10 @@ __all__ = [ "collection", "music",
|
|||
"data", "event", "map", "path", "plugin"]
|
||||
|
||||
__major__ = 1
|
||||
__minor__ = 1
|
||||
__minor__ = 2
|
||||
__dev__ = True
|
||||
__vers__ = "Libsaria %s.%s" % (__major__, __minor__)
|
||||
if __dev__ == False:
|
||||
if __dev__ == True:
|
||||
__vers__ += "-dev"
|
||||
|
||||
import event
|
||||
|
|
|
@ -14,9 +14,16 @@ PLAYLIST = 1
|
|||
QUEUE = 2
|
||||
|
||||
import lens
|
||||
library = lens.Library()
|
||||
import library
|
||||
playlist = lens.Playlist()
|
||||
|
||||
file_to_id = library.file_to_id
|
||||
play_id = library.play_id
|
||||
get_attr = library.get_attr
|
||||
reset = library.reset
|
||||
inc_score = library.inc_score
|
||||
inc_count = library.inc_count
|
||||
|
||||
def init():
|
||||
libsaria.init_pref("random", False)
|
||||
libsaria.event.invite("POSTINIT", init)
|
||||
|
@ -33,44 +40,6 @@ def new_source(path, bg=True):
|
|||
return 0
|
||||
return call("NEWSOURCE", library.scan, path)
|
||||
|
||||
def walk_library():
|
||||
global library
|
||||
for track in library.walk_tags():
|
||||
yield track
|
||||
|
||||
def lib_reset():
|
||||
global library
|
||||
library.reset()
|
||||
library.save()
|
||||
|
||||
def lib_get_attr(id, attr):
|
||||
global library
|
||||
if id >= 0:
|
||||
return library.get_attr(id, attr)
|
||||
|
||||
def lib_inc_count(id):
|
||||
global library
|
||||
if id >= 0:
|
||||
library.inc_count(id)
|
||||
library.save()
|
||||
|
||||
def lib_inc_score(id, amount=1):
|
||||
global library
|
||||
if id >= 0:
|
||||
library.inc_score(id, amount)
|
||||
library.save()
|
||||
|
||||
def lib_play_id(id):
|
||||
global cur_lib_id
|
||||
cur_lib_id = id
|
||||
filepath = lib_get_attr(id, "filepath")
|
||||
libsaria.music.load(filepath)
|
||||
libsaria.music.play()
|
||||
|
||||
def lib_find_id(file):
|
||||
global library
|
||||
return library.find_id(file)
|
||||
|
||||
def lib_get_cur_id():
|
||||
global cur_lib_id
|
||||
return cur_lib_id
|
||||
|
@ -101,9 +70,9 @@ def plist_add_libid(lib_id):
|
|||
# Hey, Future Bryan. I really want to use a lib_get_attrs() function
|
||||
# to return a list of attributes. Can you do that for me, please?
|
||||
# Thank you, Past Bryan
|
||||
artist = lib_get_attr(lib_id, "artist")
|
||||
album = lib_get_attr(lib_id, "album")
|
||||
title = lib_get_attr(lib_id, "title")
|
||||
artist = library.get_attr(lib_id, "artist")
|
||||
album = library.get_attr(lib_id, "album")
|
||||
title = library.get_attr(lib_id, "title")
|
||||
playlist.insert_tags(artist, album, title, lib_id)
|
||||
|
||||
def plist_is_visible(id):
|
||||
|
@ -130,23 +99,23 @@ def choose_next():
|
|||
else:
|
||||
next = playlist.next_id(cur_lib_id)
|
||||
if next != None:
|
||||
return call("NEXT", lib_play_id, next)
|
||||
return call("NEXT", play_id, next)
|
||||
|
||||
def change_score():
|
||||
prcnt = libsaria.music.get_progress()
|
||||
if prcnt > 0.75:
|
||||
lib_inc_count(cur_lib_id)
|
||||
lib_inc_score(cur_lib_id)
|
||||
inc_count(cur_lib_id)
|
||||
inc_score(cur_lib_id)
|
||||
if prcnt < 0.33:
|
||||
lib_inc_score(cur_lib_id, -1)
|
||||
inc_score(cur_lib_id, -1)
|
||||
|
||||
def plist_next():
|
||||
change_score()
|
||||
choose_next()
|
||||
|
||||
def catch_eos(*args):
|
||||
lib_inc_count(cur_lib_id)
|
||||
lib_inc_score(cur_lib_id)
|
||||
inc_count(cur_lib_id)
|
||||
inc_score(cur_lib_id)
|
||||
choose_next()
|
||||
libsaria.event.invite("POSTEOS", catch_eos)
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ class Playlist(collection.Collection):
|
|||
def random(self):
|
||||
if self.size == 0:
|
||||
return
|
||||
getattr = libsaria.collection.lib_get_attr
|
||||
getattr = libsaria.collection.get_attr
|
||||
last = self.last_tracks
|
||||
for i in xrange(15):
|
||||
id = self.get_rand_candidate()
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
# Bryan Schumaker (11/05/2010)
|
||||
|
||||
import libsaria
|
||||
|
||||
fs_tree = None
|
||||
tag_tree = None
|
||||
index = None
|
||||
tracks = None
|
||||
next_id = None
|
||||
sources = None
|
||||
size = None
|
||||
|
||||
def reset():
|
||||
from tree import DLTree
|
||||
from index import Index
|
||||
fs_tree = DLTree()
|
||||
tag_tree = DLTree()
|
||||
index = Index()
|
||||
tracks = dict()
|
||||
next_id = 0
|
||||
size = 0
|
||||
sources = []
|
||||
save()
|
||||
|
||||
def load():
|
||||
global fs_tree
|
||||
global tag_tree
|
||||
global index
|
||||
global tracks
|
||||
global next_id
|
||||
global sources
|
||||
global size
|
||||
objects = libsaria.data.load("library", ".dl_tree")
|
||||
if objects == None or len(objects) != 6:
|
||||
reset()
|
||||
return
|
||||
(fs_tree, tag_tree, index, tracks, next_id, size) = objects
|
||||
load()
|
||||
|
||||
def save():
|
||||
libsaria.data.save(
|
||||
(fs_tree, tag_tree, index, tracks, next_id, size),
|
||||
"library", ".dl_tree")
|
||||
|
||||
def walk_tags():
|
||||
for tag in tag_tree.walk_forwards():
|
||||
rec = tracks[tag[3]]
|
||||
yield tag + [rec.year] + [rec.lenstr]
|
||||
|
||||
def file_to_id(file):
|
||||
global fs_tree
|
||||
stripped = file.strip(libsaria.path.sep)
|
||||
split = stripped.split(libsaria.path.sep)
|
||||
|
||||
res = fs_tree.walk_path(split)
|
||||
if res == False:
|
||||
return None
|
||||
return res[0]
|
||||
|
||||
def get_attr(id, attr):
|
||||
rec = tracks.get(id, None)
|
||||
if rec == None:
|
||||
return None
|
||||
if attr == "filepath":
|
||||
cmp = rec.fs.walk_backwards()
|
||||
return libsaria.path.sep.join([""] + cmp)
|
||||
if attr == "playcount":
|
||||
return rec.count
|
||||
if attr == "year":
|
||||
return rec.year
|
||||
if attr == "lenstr":
|
||||
return rec.lenstr
|
||||
if attr == "score":
|
||||
return rec.score
|
||||
|
||||
tags = rec.tags.walk_backwards()
|
||||
if attr == "artist":
|
||||
return tags[0]
|
||||
if attr == "album":
|
||||
return tags[1]
|
||||
if attr == "title":
|
||||
return tags[2]
|
||||
|
||||
def inc_score(id, amount=1):
|
||||
rec = tracks.get(id, None)
|
||||
if rec:
|
||||
rec.score += amount
|
||||
save()
|
||||
|
||||
def inc_count(id):
|
||||
rec = tracks.get(id, None)
|
||||
if rec:
|
||||
rec.count += 1
|
||||
save()
|
||||
|
||||
def play_id(id):
|
||||
libsaria.collection.cur_lib_id = id
|
||||
filepath = get_attr(id, "filepath")
|
||||
libsaria.music.load(filepath)
|
||||
libsaria.music.play()
|
||||
|
||||
def is_visible(id):
|
||||
return True
|
|
@ -54,9 +54,9 @@ def universal_open(file):
|
|||
plugin.install(file)
|
||||
return
|
||||
try:
|
||||
id = libsaria.collection.lib_find_id(file)
|
||||
id = libsaria.collection.file_to_id(file)
|
||||
if id:
|
||||
libsaria.collection.lib_play_id(id)
|
||||
libsaria.collection.play_id(id)
|
||||
else:
|
||||
libsaria.music.load(file)
|
||||
except Exception,e:
|
||||
|
|
|
@ -4,8 +4,9 @@ import libsaria
|
|||
import web
|
||||
import xm
|
||||
|
||||
cache = libsaria.cache
|
||||
pref_attr = xm.find_preferred_attribute
|
||||
file_to_id = libsaria.collection.file_to_id
|
||||
cache = libsaria.cache
|
||||
pref_attr = xm.find_preferred_attribute
|
||||
|
||||
pref_sizes = ["extralarge", "large", "medium", "small"]
|
||||
|
||||
|
@ -61,11 +62,11 @@ def lfm_cache_album(file, artist, album):
|
|||
return False
|
||||
|
||||
def get_artwork(filepath):
|
||||
id = libsaria.collection.lib_find_id(filepath)
|
||||
id = file_to_id(filepath)
|
||||
if id == None:
|
||||
return
|
||||
artist = libsaria.collection.lib_get_attr(id, "artist")
|
||||
album = libsaria.collection.lib_get_attr(id, "album")
|
||||
artist = libsaria.collection.get_attr(id, "artist")
|
||||
album = libsaria.collection.get_attr(id, "album")
|
||||
cached = cache[artist]
|
||||
file = cached.get("%s.jpg" % album, lfm_cache_album, artist, album)
|
||||
libsaria.event.start("POSTGETART", file)
|
||||
|
|
|
@ -8,10 +8,10 @@ import libsaria
|
|||
gdk = gtk.gdk
|
||||
|
||||
__major__ = 4
|
||||
__minor__ = 1
|
||||
__minor__ = 2
|
||||
__dev__ = True
|
||||
__vers__ = "Ocarina %s.%s" % (__major__, __minor__)
|
||||
if __dev__ == False:
|
||||
if __dev__ == True:
|
||||
__vers__ += "-dev"
|
||||
|
||||
gdk.threads_init()
|
||||
|
|
|
@ -6,6 +6,7 @@ import menu
|
|||
|
||||
libsaria = ocarina.libsaria
|
||||
from libsaria import collection
|
||||
library = collection.library
|
||||
|
||||
event = ocarina.libsaria.event
|
||||
gtk = ocarina.gtk
|
||||
|
@ -81,7 +82,7 @@ class Library(Collection):
|
|||
def populate(self):
|
||||
#import datetime
|
||||
#before = datetime.datetime.now()
|
||||
Collection.populate(self, collection.walk_library)
|
||||
Collection.populate(self, library.walk_tags)
|
||||
#after = datetime.datetime.now()
|
||||
#print "Populating took: %s" % (after - before)
|
||||
|
||||
|
@ -90,17 +91,17 @@ class Library(Collection):
|
|||
self.populate()
|
||||
|
||||
def reset(self):
|
||||
collection.lib_reset()
|
||||
collection.reset()
|
||||
self.clear()
|
||||
|
||||
def mouse_motion(self, row):
|
||||
return (collection.lib_get_attr(row[0], "playcount"),
|
||||
collection.lib_get_attr(row[0], "score"))
|
||||
return (collection.get_attr(row[0], "playcount"),
|
||||
collection.get_attr(row[0], "score"))
|
||||
|
||||
def select_row(self, row):
|
||||
collection.change_score()
|
||||
collection.lib_play_id(row[0])
|
||||
collection.lib_inc_score(row[0], 1)
|
||||
collection.play_id(row[0])
|
||||
collection.inc_score(row[0], 1)
|
||||
|
||||
def filter(self, text):
|
||||
collection.lib_filter(text)
|
||||
|
@ -138,13 +139,13 @@ class Playlist(Collection):
|
|||
#print "Populating took: %s" % (after - before)
|
||||
|
||||
def mouse_motion(self, row):
|
||||
return (collection.lib_get_attr(row[0], "playcount"),
|
||||
collection.lib_get_attr(row[0], "score"))
|
||||
return (collection.get_attr(row[0], "playcount"),
|
||||
collection.get_attr(row[0], "score"))
|
||||
|
||||
def select_row(self, row):
|
||||
collection.change_score()
|
||||
collection.lib_play_id(row[0])
|
||||
collection.lib_inc_score(row[0], 1)
|
||||
collection.play_id(row[0])
|
||||
collection.inc_score(row[0], 1)
|
||||
|
||||
def filter(self, text):
|
||||
collection.plist_filter(text)
|
||||
|
|
|
@ -11,7 +11,8 @@ label = None
|
|||
image = None
|
||||
|
||||
lib_get_cur_id = libsaria.collection.lib_get_cur_id
|
||||
lib_get_attr = libsaria.collection.lib_get_attr
|
||||
get_attr = libsaria.collection.get_attr
|
||||
file_to_id = libsaria.collection.file_to_id
|
||||
|
||||
filter = None
|
||||
info = None
|
||||
|
@ -72,9 +73,9 @@ class InfoBar(Bar):
|
|||
libsaria.event.invite("POSTLOAD", self.change_title)
|
||||
|
||||
def change_title(self, filepath):
|
||||
id = libsaria.collection.lib_find_id(filepath)
|
||||
title = lib_get_attr(id, "title")
|
||||
artist = libsaria.collection.lib_get_attr(id, "artist")
|
||||
id = file_to_id(filepath)
|
||||
title = get_attr(id, "title")
|
||||
artist = get_attr(id, "artist")
|
||||
self.title.set_text("%s by %s" % (title,artist))
|
||||
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@ invite = ocarina.libsaria.event.invite
|
|||
libsaria = ocarina.libsaria
|
||||
|
||||
#update = None
|
||||
get_time = None
|
||||
lib_get_attr = None
|
||||
lib_find_id = None
|
||||
get_time = None
|
||||
get_attr = None
|
||||
file_to_id = None
|
||||
|
||||
def set_fns():
|
||||
#global update
|
||||
global get_time
|
||||
global lib_get_attr
|
||||
global lib_find_id
|
||||
global get_attr
|
||||
global file_to_id
|
||||
#update = ocarina.libsaria.music.get_progress
|
||||
get_time = ocarina.libsaria.music.get_time
|
||||
lib_get_attr = libsaria.collection.lib_get_attr
|
||||
lib_find_id = libsaria.collection.lib_find_id
|
||||
get_time = ocarina.libsaria.music.get_time
|
||||
get_attr = libsaria.collection.get_attr
|
||||
file_to_id = libsaria.collection.file_to_id
|
||||
invite("POSTSTART", set_fns)
|
||||
|
||||
|
||||
|
@ -45,11 +45,10 @@ class AttrLabel(gtk.Alignment):
|
|||
invite("POSTLOAD", self.update)
|
||||
|
||||
def update(self, filepath):
|
||||
global lib_find_id
|
||||
global lib_get_attr
|
||||
id = lib_find_id(filepath)
|
||||
global get_attr
|
||||
id = file_to_id(filepath)
|
||||
if id != None:
|
||||
text = str(lib_get_attr(id, self.attr))
|
||||
text = str(get_attr(id, self.attr))
|
||||
if self.other:
|
||||
text = "%s %s" % (self.other, text)
|
||||
self.label.set_text(text)
|
||||
|
|
|
@ -6,30 +6,48 @@ gtk = ocarina.gtk
|
|||
Menu = gtk.Menu
|
||||
MenuItem = gtk.MenuItem
|
||||
|
||||
lib_items = []
|
||||
plist_items = []
|
||||
common_items = []
|
||||
lib_items = []
|
||||
plist_items = []
|
||||
|
||||
def add_menu_item(items, text, func):
|
||||
items.append( (text, func) )
|
||||
items.sort()
|
||||
|
||||
def add_common_menu_item(text, func):
|
||||
add_menu_item(common_items, text, func)
|
||||
|
||||
def add_lib_menu_item(text, func):
|
||||
add_menu_item(lib_items, text, func)
|
||||
|
||||
def add_plist_menu_item(text, func):
|
||||
add_menu_item(plist_items, text, func)
|
||||
|
||||
def make_menu_item(text, func):
|
||||
item = MenuItem(text)
|
||||
item.connect("activate", func)
|
||||
item.show()
|
||||
return item
|
||||
|
||||
def make_menu(items, button, time):
|
||||
if len(items) == 0:
|
||||
return
|
||||
show = False
|
||||
if len(items) > 0:
|
||||
show = True
|
||||
menu = Menu()
|
||||
|
||||
if len(common_items) > 0:
|
||||
show = True
|
||||
for (text, func) in common_items:
|
||||
menu.append(make_menu_item(text, func))
|
||||
if len(items) > 0:
|
||||
div = MenuItem()
|
||||
div.show()
|
||||
menu.append(div)
|
||||
|
||||
for (text, func) in items:
|
||||
item = MenuItem(text)
|
||||
item.connect("activate", func)
|
||||
item.show()
|
||||
menu.append(item)
|
||||
menu.popup(None, None, None, button, time)
|
||||
menu.append(make_menu_item(text, func))
|
||||
if show == True:
|
||||
menu.popup(None, None, None, button, time)
|
||||
|
||||
def make_lib_menu(button, time):
|
||||
make_menu(lib_items, button, time)
|
||||
|
|
|
@ -17,8 +17,7 @@ def start():
|
|||
text = "Pause after current song"
|
||||
libsaria.init_var("PAUSEAFTER", False)
|
||||
|
||||
menu.add_lib_menu_item(text, set_pause)
|
||||
menu.add_plist_menu_item(text, set_pause)
|
||||
menu.add_common_menu_item(text, set_pause)
|
||||
libsaria.event.invite("POSTNEXT", check_pause)
|
||||
|
||||
def stop():
|
||||
|
@ -27,6 +26,6 @@ def stop():
|
|||
def check_version():
|
||||
if ocarina.__major__ != 4:
|
||||
return False
|
||||
if ocarina.__minor__ != 1:
|
||||
if ocarina.__minor__ != 2:
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -48,6 +48,6 @@ def stop():
|
|||
def check_version():
|
||||
if ocarina.__major__ != 4:
|
||||
return False
|
||||
if ocarina.__minor__ != 1:
|
||||
return False
|
||||
return True
|
||||
if ocarina.__minor__ >= 1:
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
# Bryan Schumaker (10/30/2010)
|
||||
|
||||
import ocarina
|
||||
gdk = ocarina.gdk
|
||||
libsaria = ocarina.libsaria
|
||||
lib_find_id = libsaria.collection.lib_find_id
|
||||
lib_get_attr = libsaria.collection.lib_get_attr
|
||||
invite = libsaria.event.invite
|
||||
gdk = ocarina.gdk
|
||||
libsaria = ocarina.libsaria
|
||||
file_to_id = libsaria.collection.file_to_id
|
||||
get_attr = libsaria.collection.get_attr
|
||||
invite = libsaria.event.invite
|
||||
|
||||
|
||||
def tweak_icon(file):
|
||||
|
@ -17,8 +17,8 @@ def tweak_icon(file):
|
|||
|
||||
def tweak_title(filepath):
|
||||
if filepath != None:
|
||||
id = lib_find_id(filepath)
|
||||
title = lib_get_attr(id, "title")
|
||||
id = file_to_id(filepath)
|
||||
title = get_attr(id, "title")
|
||||
else:
|
||||
title = ocarina.__vers__
|
||||
ocarina.set_window_title(title)
|
||||
|
@ -33,6 +33,6 @@ def stop():
|
|||
def check_version():
|
||||
if ocarina.__major__ != 4:
|
||||
return False
|
||||
if ocarina.__minor__ != 1:
|
||||
return False
|
||||
return True
|
||||
if ocarina.__minor__ >= 1:
|
||||
return True
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue