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.
70 lines
1.3 KiB
Python
70 lines
1.3 KiB
Python
# Bryan Schumaker (8/7/2010)
|
|
|
|
import libsaria
|
|
from libsaria import path
|
|
import cPickle as pickle
|
|
#import pickle
|
|
plugin = None
|
|
|
|
dev = ""
|
|
if libsaria.__dev__ == True:
|
|
dev = "-dev"
|
|
|
|
PROTO = pickle.HIGHEST_PROTOCOL
|
|
|
|
def save(item, file, ext=".pickle"):
|
|
file = "%s%s%s" % (path.join(path.saria_dir(),file), dev, ext)
|
|
savefile(item, file)
|
|
|
|
|
|
def savefile(item, file):
|
|
f = open(file, 'w')
|
|
p = pickle.Pickler(f, PROTO)
|
|
p.dump(item)
|
|
f.close()
|
|
|
|
|
|
def load(file, ext=".pickle"):
|
|
file = "%s%s%s" % (path.join(path.saria_dir(),file), dev, ext)
|
|
return loadfile(file)
|
|
|
|
|
|
def loadfile(file):
|
|
if path.exists(file) == False:
|
|
return
|
|
f = open(file)
|
|
p = pickle.Unpickler(f)
|
|
item = p.load()
|
|
f.close()
|
|
return item
|
|
|
|
|
|
def universal_open(file):
|
|
global plugin
|
|
file = file.replace("%20", " ")
|
|
file = file.replace("%22", "\"")
|
|
if path.is_dir(file):
|
|
libsaria.sources.new_source(file)
|
|
return
|
|
split = path.splitext(file)
|
|
ext = split[1]
|
|
# Install and start a plugin
|
|
if ext == ".py":
|
|
if plugin == None:
|
|
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:
|
|
libsaria.sources.play_id(id)
|
|
else:
|
|
libsaria.audio.load(file)
|
|
except Exception,e:
|
|
print e
|
|
pass
|