Import old library
I can now import files from an Ocarina 4.1 library exported as xml. Ocarina 4.2 keeps track of a list of sources, but 4.1 does not. For importing to work properly, the library needs to be rescanned before running the import. The import will set the playcount and score attributes for each file.
This commit is contained in:
parent
13edf01abe
commit
fed3c7f356
|
@ -8,6 +8,8 @@ import libsaria.xm as xml
|
|||
add_child = xml.add_child
|
||||
add_text = xml.add_text
|
||||
get_attrs = library.get_attrs
|
||||
set_attr = library.set_attr
|
||||
file2id = library.file_to_id
|
||||
lib_file = "library"
|
||||
if libsaria.__dev__ == True:
|
||||
lib_file = lib_file + "-dev"
|
||||
|
@ -19,6 +21,11 @@ def encode_attr(doc, node, attr, value):
|
|||
add_text(doc, child, value)
|
||||
|
||||
|
||||
def decode_attr(attr):
|
||||
child = xml.child(attr)
|
||||
return (attr.nodeName, child.data.strip())
|
||||
|
||||
|
||||
def encode_track(doc, node, id):
|
||||
child = add_child(doc, node, "track")
|
||||
(artist, album, title, filepath, score, count, genre, track, year, rate,
|
||||
|
@ -44,6 +51,16 @@ def encode_track(doc, node, id):
|
|||
encode_attr(doc, child, "lenstr", lenstr)
|
||||
|
||||
|
||||
def decode_track(node):
|
||||
track = dict()
|
||||
for child in xml.children(node):
|
||||
key, value = decode_attr(child)
|
||||
track[key] = value
|
||||
id = file2id(track["filepath"])
|
||||
set_attr(id, "count", int(track["count"]))
|
||||
set_attr(id, "score", int(track["score"]))
|
||||
|
||||
|
||||
def backup():
|
||||
doc = xml.new()
|
||||
child = add_child(doc, doc, "library")
|
||||
|
@ -56,4 +73,13 @@ def backup():
|
|||
print "Wrote library to: %s" % lib_file
|
||||
|
||||
|
||||
def restore(file):
|
||||
fin = open(file)
|
||||
doc = xml.parse(fin)
|
||||
child = xml.child(doc)
|
||||
for track in xml.children(child):
|
||||
decode_track(track)
|
||||
library.save()
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -54,6 +54,10 @@ def universal_open(file):
|
|||
from libsaria import plugin
|
||||
plugin.install(file)
|
||||
return
|
||||
if ext == ".xml":
|
||||
import backup
|
||||
backup.restore(file)
|
||||
return
|
||||
try:
|
||||
id = libsaria.sources.file_to_id(file)
|
||||
if id:
|
||||
|
|
Loading…
Reference in New Issue