2
## Extract pickled data from the QuodLibet songs database
3
## to an easy to parse XML file.
5
## By Mathieu Cadet <mathieu cadet gmail>
11
sys.path += ["/usr/local/share/quodlibet",
12
"/usr/share/quodlibet"]
19
user = os.environ.get("USER")
20
home = os.environ.get("HOME")
21
if not user or not home:
22
quit("USER and/or HOME environnement variable not defined")
25
f = open("%s/.quodlibet/songs" % home)
31
print "Unable to load QuodLibet database."
35
xml = codecs.open("/tmp/quodlibet-songs-%s" % user, "wt","utf-8")
37
xml.write("<songs>\n")
40
if len(s.get("title", '')) > 0 and \
41
len(s.get("artist", '')) > 0 or len(s.get("album", '')) > 0:
43
xml.write("<title><![CDATA[%s]]></title>\n" % s.get("title"))
44
xml.write("<artist><![CDATA[%s]]></artist>\n" % s.get("artist", "Unknown artist").replace("\n", ","))
45
xml.write("<album><![CDATA[%s]]></album>\n" % s.get("album", ""))
46
xml.write("<filename><![CDATA[%s]]></filename>\n" % s.get("~filename","").decode("utf-8", 'replace'))
47
xml.write("</song>\n")
49
xml.write("</songs>\n")
53
print "Unable to write the XML song database."