Collection work
I've begun work on a generic collection class for the library, playlist, and queue. Tagpy functions have been merged into the libsaria.collections.__init__.py file to make things easier.
This commit is contained in:
parent
25a0d0be9f
commit
52b1236b29
|
@ -1,6 +1,6 @@
|
||||||
# Bryan Schumaker (8/7/2010)
|
# Bryan Schumaker (8/7/2010)
|
||||||
|
|
||||||
__all__ = [ "music",
|
__all__ = [ "collection", "music",
|
||||||
"data", "event", "map", "path"]
|
"data", "event", "map", "path"]
|
||||||
|
|
||||||
import event
|
import event
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
# Bryan Schumaker (8/8/2010)
|
||||||
|
|
||||||
|
__all__ = ["collection"]
|
||||||
|
|
||||||
|
import libsaria
|
||||||
|
import tagpy
|
||||||
|
call = libsaria.event.call
|
||||||
|
exists = libsaria.path.exists
|
||||||
|
expand = libsaria.path.expand
|
||||||
|
FileRef = tagpy.FileRef
|
||||||
|
|
||||||
|
LIBRARY = 0
|
||||||
|
PLAYLIST = 1
|
||||||
|
QUEUE = 2
|
||||||
|
|
||||||
|
import collection
|
||||||
|
source = collection.Collection()
|
||||||
|
|
||||||
|
def new_source(path, bg=True):
|
||||||
|
global source
|
||||||
|
path = expand(path)
|
||||||
|
if not exists(path):
|
||||||
|
return 0
|
||||||
|
return call("NEWSOURCE", source.scan, arg=path, bg=bg)
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Bryan Schumaker (8/8/2010)
|
||||||
|
|
||||||
|
import libsaria
|
||||||
|
import table
|
||||||
|
|
||||||
|
class Collection:
|
||||||
|
def __init__(self):
|
||||||
|
self.table = table.Table()
|
||||||
|
|
||||||
|
|
||||||
|
def scan(self, path):
|
||||||
|
print "Scanning path:", path
|
||||||
|
self.clear()
|
||||||
|
self.update(path)
|
||||||
|
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
print "Erasing collection ... "
|
||||||
|
|
||||||
|
|
||||||
|
def insert(self, file):
|
||||||
|
tags = file.tag()
|
||||||
|
id = self.table.insert(tags)
|
||||||
|
print id, tags
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update(self, path):
|
||||||
|
FileRef = libsaria.collection.FileRef
|
||||||
|
join = libsaria.path.join
|
||||||
|
|
||||||
|
for root,dirs,files in libsaria.path.walk(path):
|
||||||
|
for file in files:
|
||||||
|
file = join(root,file)
|
||||||
|
try:
|
||||||
|
tagfile = FileRef(file)
|
||||||
|
self.insert(tagfile)
|
||||||
|
except Exception,e:
|
||||||
|
print e
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Bryan Schumaker (8/8/2010)
|
||||||
|
|
||||||
|
class Table(dict):
|
||||||
|
def __init__(self):
|
||||||
|
dict.__init__(self)
|
||||||
|
self.next_id = 0
|
||||||
|
|
||||||
|
|
||||||
|
def insert(self, tag):
|
||||||
|
id = self.next_id
|
||||||
|
self[id] = (tag.artist, tag.album, tag.title)
|
||||||
|
self.next_id += 1
|
||||||
|
print id, self.next_id
|
||||||
|
return id
|
|
@ -7,6 +7,7 @@ expand = os.path.expanduser
|
||||||
join = os.path.join
|
join = os.path.join
|
||||||
mkdir = os.mkdir
|
mkdir = os.mkdir
|
||||||
rm = os.remove
|
rm = os.remove
|
||||||
|
walk = os.walk
|
||||||
|
|
||||||
dir = None
|
dir = None
|
||||||
def sariadir():
|
def sariadir():
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Bryan Schumaker (8/8/2010)
|
||||||
|
|
||||||
|
from libsaria import collection
|
||||||
|
|
||||||
|
#src = "~/Music"
|
||||||
|
#src = "~/Music/Foo Fighters"
|
||||||
|
src = "~/Music/Foo Fighters/Foo Fighters"
|
||||||
|
|
||||||
|
collection.new_source(src, bg=False)
|
Loading…
Reference in New Issue