Use new collection structure to populate the library list.

This commit is contained in:
Bryan Schumaker 2010-10-08 13:09:42 -04:00
parent adcb73dac9
commit 2c27185679
10 changed files with 62 additions and 32 deletions

View File

@ -14,7 +14,7 @@ PLAYLIST = 1
QUEUE = 2
import lens
library2 = lens.Library()
library = lens.Library()
cur_lib_id = -1
@ -23,30 +23,18 @@ def new_source(path, bg=True):
path = expand(path)
if not exists(path):
return 0
library.reset()
return call("NEWSOURCE", library.scan, path)
def new_source2(path, bg=True):
global library2
path = expand(path)
if not exists(path):
return 0
library2.reset()
return call("NEWSOURCE2", library2.scan, path)
def walk_library():
global library
for track in library:
yield track
def scan_library():
global library2
for track in library2.walk_tags():
for track in library.walk_tags():
yield track
def lib_get_attr(id, attr):
global library2
global library
if id >= 0:
return library2.get_attr(id, attr)
return library.get_attr(id, attr)
return None
def lib_play_id(id):
@ -56,6 +44,10 @@ def lib_play_id(id):
libsaria.music.load(filepath)
libsaria.music.play()
def lib_find_id(file):
global library
library.find_id(file)
def lib_get_cur_id():
global cur_lib_id
return cur_lib_id

View File

@ -19,7 +19,7 @@ class TrackRecord:
self.tags = None
class Collection2:
class Collection:
def __init__(self, file):
self.file = file
self.load()
@ -58,6 +58,11 @@ class Collection2:
rec = self.records[tag[3]]
yield tag + [rec.year] + [rec.length]
def find_id(self, file):
stripped = file.strip(libsaria.path.sep)
split = stripped.split(libsaria.path.sep)
print self.fs_tree.walk_path(split)
def get_attr(self, id, attr):
rec = self.records[id]
if attr == "filepath":
@ -66,6 +71,14 @@ class Collection2:
if attr == "playcount":
return rec.count
tags = rec.tags.walk_backwards()
if attr == "artist":
return tags[0]
if attr == "album":
return tags[1]
if attr == "title":
return tags[2]
def insert_allocate(self, components, ref):
t = ref.tag()
artist = t.artist

View File

@ -10,9 +10,9 @@ walk = libsaria.path.walk
join = libsaria.path.join
splitext = libsaria.path.splitext
class Library(collection.Collection2):
class Library(collection.Collection):
def __init__(self):
collection.Collection2.__init__(self, "DLTree_test")
collection.Collection.__init__(self, "DLTree_test")
self.badfiles = set()
pass

View File

@ -27,10 +27,19 @@ class DLTree:
#if len(self.children) == 0:
# print self.get_path()
def walk_path(self, path):
p = path[0]
if p not in self.child_fwd:
return False
child = self.child_fwd[p]
val = child.walk_path[path[1:]]
if val != False:
return p + [val]
def walk_backwards(self, child=None):
if self.parent == None:
return [self.child_bck[child]]
cmp = self.child_bck.get(child, None)
if self.parent == None:
return [cmp]
child = self
path = self.parent.walk_backwards(child)
if cmp != None:
@ -63,7 +72,6 @@ class DLTree:
try:
child = self.child_fwd[cmp]
except TypeError:
#self.children = dict()
child = DLTree(self)
self.child_fwd[cmp] = child
self.child_bck[child] = cmp

View File

@ -1,5 +1,6 @@
# Bryan Schumaker (8/7/2010)
import libsaria
from libsaria import path
import cPickle as pickle
#import pickle
@ -37,12 +38,18 @@ def loadfile(file):
def universal_open(file):
global plugin
split = file.rsplit('.', 1)
ext = split[len(split)-1]
if path.is_dir(file):
print "Is a dir! Scan it!"
libsaria.collection.new_source(file)
split = path.splitext(file)
ext = split[1]
# Install and start a plugin
if ext == "py":
if ext == ".py":
if plugin == None:
from libsaria import plugin
plugin.install(file)
try:
libsaria.collection.lib_find_id(file)
libsaria.music.load(file)
except Exception,e:
print e
pass

View File

@ -54,7 +54,6 @@ class OpenButton(Button):
def clicked(self, button):
from ocarina import fsselect
fsselect.run_chooser2(LS.data.universal_open)
print "OpenButton clicked"
class UpButton(Button):

View File

@ -25,6 +25,9 @@ class Collection(gtk.ScrolledWindow):
self.add(self.list)
self.show()
def clear(self):
self.list.clear()
def populate(self, func):
self.list.freeze()
insert = self.list.list.insert
@ -58,15 +61,19 @@ class Library(Collection):
def __init__(self):
Collection.__init__(self, self.mouse_motion, self.select_row)
libsaria.event.invite("POSTSTART", self.populate, bg=True)
libsaria.event.invite("POSTNEWSOURCE", self.refresh, bg=True)
def populate(self):
import datetime
before = datetime.datetime.now()
#Collection.populate(self, collection.walk_library)
Collection.populate(self, collection.scan_library)
Collection.populate(self, collection.walk_library)
after = datetime.datetime.now()
print "Populating took: %s" % (after-before)
def refresh(self, arg):
self.clear()
self.populate()
def mouse_motion(self, row):
return collection.lib_get_attr(row[0], "playcount")

View File

@ -58,6 +58,7 @@ def select_path(widget, callback):
uri = chooser_widget.get_uri()
if uri[:7] == "file://":
uri = uri[7:]
uri = uri.replace("%20", " ")
callback(uri)
def run_chooser2(callback):

View File

@ -47,3 +47,6 @@ class List(gtk.TreeView):
def set_visible(self, a, b):
return True
def clear(self):
self.list.clear()

View File

@ -5,5 +5,5 @@ from libsaria import collection
#collection.new_source2("~/Music/")
collection.new_source2("/media/Music")
print collection.library2.size
collection.new_source("/media/Music")
print collection.library.size