53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
# Bryan Schumaker (11/12/2010)
|
|
|
|
import libsaria
|
|
from libsaria import path
|
|
import xm as xml
|
|
|
|
add_child = xml.add_child
|
|
add_text = xml.add_text
|
|
get_attr = libsaria.collection.lib_get_attr
|
|
lib_file = path.join(path.saria_dir(), "library.xml")
|
|
|
|
def encode_attr(doc, node, attr, value):
|
|
child = add_child(doc, node, attr)
|
|
add_text(doc, child, value)
|
|
|
|
|
|
def encode_track(doc, node, id):
|
|
child = add_child(doc, node, "track")
|
|
|
|
artist = get_attr(id, "artist")
|
|
album = get_attr(id, "album")
|
|
title = get_attr(id, "title")
|
|
count = get_attr(id, "playcount")
|
|
year = get_attr(id, "year")
|
|
lenstr = get_attr(id, "lenstr")
|
|
score = get_attr(id, "score")
|
|
filepath = get_attr(id, "filepath")
|
|
|
|
encode_attr(doc, child, "id", id)
|
|
encode_attr(doc, child, "artist", artist)
|
|
encode_attr(doc, child, "album", album)
|
|
encode_attr(doc, child, "title", title)
|
|
encode_attr(doc, child, "filepath", filepath)
|
|
encode_attr(doc, child, "score", score)
|
|
encode_attr(doc, child, "count", count)
|
|
encode_attr(doc, child, "year", year)
|
|
encode_attr(doc, child, "lenstr", lenstr)
|
|
|
|
|
|
def backup():
|
|
doc = xml.new()
|
|
child = add_child(doc, doc, "library")
|
|
for id in libsaria.collection.lib_walk_ids():
|
|
encode_track(doc, child, id)
|
|
|
|
fout = open(lib_file, 'w')
|
|
fout.write(doc.toprettyxml())
|
|
fout.close()
|
|
print "Wrote library to: %s" % lib_file
|
|
|
|
|
|
|