libsaria: Add new songs to the library

I scan a directory and collect fileids for each file.  If the fileid
doesn't exist in the library yet, I'll find the tags and add to the
dictionary.
This commit is contained in:
Bryan Schumaker 2011-05-21 07:44:11 -04:00
parent a1722eafb3
commit a4988a0b28
3 changed files with 24 additions and 1 deletions

View File

@ -37,6 +37,10 @@ on_new_source = null_cb
def new_source():
on_new_source()
on_library_updated = null_cb
def library_updated():
on_library_updated()
on_queue_changed = null_cb
def queue_changed():
on_queue_changed()

View File

@ -59,6 +59,7 @@ def make_library(path):
return
library.add_path(path)
library.update()
libsaria.callbacks.library_updated()
def play_id(id):
global cur_id

View File

@ -3,11 +3,14 @@
import os
import library
import track
stat = os.stat
walk = os.walk
join = os.path.join
Track = track.Track
def song_id(path):
return stat(path).st_ino
@ -20,9 +23,24 @@ def scan_path(path):
file_map[song_id(file)] = file
return file_map
def update_path(path, origdict):
def add_new_ids(old_ids, new_ids, tracks, file_map):
to_add = new_ids - old_ids
for id in to_add:
try:
fpath = file_map[id]
tracks[id] = Track(fpath)
except Exception, e:
pass
def update_path(path, tracks):
file_map = scan_path(path)
old_ids = set(tracks.keys())
new_ids = set(file_map.keys())
add_new_ids(old_ids, new_ids, tracks, file_map)
def update():
library.lock_library()
for path, lib in library.lib_dict.iteritems():
update_path(path, lib)
library.unlock_library()