libsaria: Fix library updating
I need to reindex and rebuild the tree on each update. I also need to notify the front-end that things have changed.
This commit is contained in:
parent
e0ad57c541
commit
0e5bd0d908
|
@ -71,7 +71,6 @@ def make_library(path):
|
||||||
return
|
return
|
||||||
library.add_path(path)
|
library.add_path(path)
|
||||||
library.update_lib()
|
library.update_lib()
|
||||||
libsaria.callbacks.library_updated()
|
|
||||||
|
|
||||||
def play_id(id):
|
def play_id(id):
|
||||||
global cur_id
|
global cur_id
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# Bryan Schumaker (5 / 20 / 2011)
|
# Bryan Schumaker (5 / 20 / 2011)
|
||||||
|
|
||||||
|
import libsaria
|
||||||
import library
|
import library
|
||||||
import update
|
import update
|
||||||
import tree
|
import tree
|
||||||
|
@ -20,6 +21,8 @@ index.reindex()
|
||||||
def update_lib():
|
def update_lib():
|
||||||
update.update()
|
update.update()
|
||||||
tree.make_tree()
|
tree.make_tree()
|
||||||
|
index.reindex()
|
||||||
|
libsaria.callbacks.library_updated()
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
library.reset()
|
library.reset()
|
||||||
|
|
|
@ -23,6 +23,12 @@ for t in (splitt, lowert):
|
||||||
for c in t:
|
for c in t:
|
||||||
ttable[c] = t[c]
|
ttable[c] = t[c]
|
||||||
|
|
||||||
|
def reset():
|
||||||
|
global lib_index
|
||||||
|
global all_ids
|
||||||
|
lib_index = dict()
|
||||||
|
all_ids = set()
|
||||||
|
|
||||||
def format(text):
|
def format(text):
|
||||||
return text.translate(ttable).split()
|
return text.translate(ttable).split()
|
||||||
|
|
||||||
|
@ -42,6 +48,7 @@ def add_tracks(tracks):
|
||||||
|
|
||||||
def reindex():
|
def reindex():
|
||||||
global matching
|
global matching
|
||||||
|
reset()
|
||||||
for src, tracks in library.lib_dict.iteritems():
|
for src, tracks in library.lib_dict.iteritems():
|
||||||
add_tracks(tracks)
|
add_tracks(tracks)
|
||||||
matching = all_ids
|
matching = all_ids
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Tree(dict):
|
||||||
child.insert(path[1:])
|
child.insert(path[1:])
|
||||||
|
|
||||||
|
|
||||||
lib_tree = Tree()
|
lib_tree = None
|
||||||
|
|
||||||
def list_ids():
|
def list_ids():
|
||||||
for id in lib_tree.walk():
|
for id in lib_tree.walk():
|
||||||
|
@ -51,5 +51,7 @@ def add_tracks(tracks):
|
||||||
lib_tree.insert([artist, album, track.track, id])
|
lib_tree.insert([artist, album, track.track, id])
|
||||||
|
|
||||||
def make_tree():
|
def make_tree():
|
||||||
|
global lib_tree
|
||||||
|
lib_tree = Tree()
|
||||||
for src, tracks in library.lib_dict.iteritems():
|
for src, tracks in library.lib_dict.iteritems():
|
||||||
add_tracks(tracks)
|
add_tracks(tracks)
|
||||||
|
|
|
@ -15,7 +15,6 @@ def song_id(path):
|
||||||
return stat(path).st_ino
|
return stat(path).st_ino
|
||||||
|
|
||||||
def scan_path(path):
|
def scan_path(path):
|
||||||
print "Scanning path:", path
|
|
||||||
file_map = dict()
|
file_map = dict()
|
||||||
for root, dir, files in walk(path):
|
for root, dir, files in walk(path):
|
||||||
for file in files:
|
for file in files:
|
||||||
|
@ -48,6 +47,8 @@ def update_path(path, tracks):
|
||||||
def update():
|
def update():
|
||||||
library.lock_library()
|
library.lock_library()
|
||||||
for path, lib in library.lib_dict.iteritems():
|
for path, lib in library.lib_dict.iteritems():
|
||||||
|
print "Updating path:", path
|
||||||
update_path(path, lib)
|
update_path(path, lib)
|
||||||
|
print "Done!"
|
||||||
library.save()
|
library.save()
|
||||||
library.unlock_library()
|
library.unlock_library()
|
||||||
|
|
Loading…
Reference in New Issue