diff --git a/libsaria/__init__.py b/libsaria/__init__.py index 6e55a58e..61c01a55 100644 --- a/libsaria/__init__.py +++ b/libsaria/__init__.py @@ -1,6 +1,6 @@ # Bryan Schumaker (8/7/2010) -__all__ = [ "music", +__all__ = [ "collection", "music", "data", "event", "map", "path"] import event diff --git a/libsaria/collection/__init__.py b/libsaria/collection/__init__.py new file mode 100644 index 00000000..9ead0558 --- /dev/null +++ b/libsaria/collection/__init__.py @@ -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) + diff --git a/libsaria/collection/collection.py b/libsaria/collection/collection.py new file mode 100644 index 00000000..024db409 --- /dev/null +++ b/libsaria/collection/collection.py @@ -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 + + + diff --git a/libsaria/collection/table.py b/libsaria/collection/table.py new file mode 100644 index 00000000..a9dcf08f --- /dev/null +++ b/libsaria/collection/table.py @@ -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 diff --git a/libsaria/path.py b/libsaria/path.py index f4f38cd5..77d68dce 100644 --- a/libsaria/path.py +++ b/libsaria/path.py @@ -7,6 +7,7 @@ expand = os.path.expanduser join = os.path.join mkdir = os.mkdir rm = os.remove +walk = os.walk dir = None def sariadir(): diff --git a/tests/collection.py b/tests/collection.py new file mode 100644 index 00000000..313aa630 --- /dev/null +++ b/tests/collection.py @@ -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)