Add tracks to libray
I now attempt to add every file in the filesystem to the library as a Track(). Errors are logged and bad extentions are saved (so we know not to scan them in the future).
This commit is contained in:
parent
0e2898a0f6
commit
afd145efd7
|
@ -1,6 +1,10 @@
|
||||||
# Bryan Schumaker (11/05/2010)
|
# Bryan Schumaker (11/05/2010)
|
||||||
|
|
||||||
|
import tagpy
|
||||||
import libsaria
|
import libsaria
|
||||||
|
import string
|
||||||
|
from track import Track
|
||||||
|
splitext = libsaria.path.splitext
|
||||||
|
|
||||||
fs_tree = None
|
fs_tree = None
|
||||||
tag_tree = None
|
tag_tree = None
|
||||||
|
@ -11,7 +15,16 @@ sources = None
|
||||||
size = None
|
size = None
|
||||||
visible = None
|
visible = None
|
||||||
|
|
||||||
|
FileRef = tagpy.FileRef
|
||||||
|
|
||||||
filtered = False
|
filtered = False
|
||||||
|
badfiles = set()
|
||||||
|
|
||||||
|
ttable = dict()
|
||||||
|
for s in string.punctuation:
|
||||||
|
ttable[ord(s)] = ""
|
||||||
|
for s in string.lowercase:
|
||||||
|
ttable[ord(s)] = ord(s) - 32
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
from libsaria.trees import FSTree
|
from libsaria.trees import FSTree
|
||||||
|
@ -35,29 +48,31 @@ def reset():
|
||||||
next_id = 0
|
next_id = 0
|
||||||
size = 0
|
size = 0
|
||||||
visible = set()
|
visible = set()
|
||||||
save()
|
#save()
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
#global fs_tree
|
#global fs_tree
|
||||||
#global tag_tree
|
#global tag_tree
|
||||||
#global index
|
#global index
|
||||||
#global tracks
|
global tracks
|
||||||
global next_id
|
global next_id
|
||||||
global sources
|
global sources
|
||||||
#global size
|
#global size
|
||||||
#global songs
|
#global songs
|
||||||
|
reset()
|
||||||
objects = libsaria.data.load("library", ".lib")
|
objects = libsaria.data.load("library", ".lib")
|
||||||
if objects == None or len(objects) != 2:
|
if objects == None or len(objects) != 3:
|
||||||
#if objects == None or len(objects) != 6:
|
#if objects == None or len(objects) != 6:
|
||||||
reset()
|
reset()
|
||||||
return
|
return
|
||||||
(sources, next_id) = objects
|
(sources, tracks, next_id) = objects
|
||||||
|
print next_id
|
||||||
#(fs_tree, tag_tree, index, tracks, next_id, size) = objects
|
#(fs_tree, tag_tree, index, tracks, next_id, size) = objects
|
||||||
libsaria.event.start("POSTLIBLOAD")
|
libsaria.event.start("POSTLIBLOAD")
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
global sources
|
global sources
|
||||||
libsaria.data.save( (sources, next_id), "library", ".lib")
|
libsaria.data.save( (sources, tracks, next_id), "library", ".lib")
|
||||||
|
|
||||||
def walk():
|
def walk():
|
||||||
return []
|
return []
|
||||||
|
@ -151,9 +166,36 @@ def scan(path):
|
||||||
update()
|
update()
|
||||||
save()
|
save()
|
||||||
|
|
||||||
|
def insert_track(path, ref):
|
||||||
|
global next_id
|
||||||
|
global tracks
|
||||||
|
global ttable
|
||||||
|
global fs_tree
|
||||||
|
tags = ref.tag()
|
||||||
|
audio = ref.audioProperties()
|
||||||
|
track = Track(tags, audio)
|
||||||
|
artist = tags.artist or u"Unknown Artist"
|
||||||
|
album = tags.album or u"Unknown Album"
|
||||||
|
title = tags.title or u"Unknown Title"
|
||||||
|
tracks[next_id] = track
|
||||||
|
next_id += 1
|
||||||
|
|
||||||
def update_path(path):
|
def update_path(path):
|
||||||
|
global badfiles
|
||||||
tree = libsaria.path.make_tree(path)
|
tree = libsaria.path.make_tree(path)
|
||||||
print path, len(tree)
|
for path in tree.walk_paths():
|
||||||
|
ext = splitext(path)[1]
|
||||||
|
if ext in badfiles:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
ref = FileRef(path)
|
||||||
|
except:
|
||||||
|
badfiles.add(ext)
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
insert_track(path, ref)
|
||||||
|
except Exception, e:
|
||||||
|
print e
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
global sources
|
global sources
|
||||||
|
|
Loading…
Reference in New Issue