98 lines
1.8 KiB
Python
98 lines
1.8 KiB
Python
# Bryan Schumaker (11/05/2010)
|
|
|
|
import libsaria
|
|
|
|
fs_tree = None
|
|
tag_tree = None
|
|
index = None
|
|
tracks = None
|
|
next_id = None
|
|
sources = None
|
|
size = None
|
|
|
|
def reset():
|
|
from tree import DLTree
|
|
from index import Index
|
|
fs_tree = DLTree()
|
|
tag_tree = DLTree()
|
|
index = Index()
|
|
tracks = dict()
|
|
next_id = 0
|
|
size = 0
|
|
sources = []
|
|
save()
|
|
|
|
def load():
|
|
global fs_tree
|
|
global tag_tree
|
|
global index
|
|
global tracks
|
|
global next_id
|
|
global sources
|
|
global size
|
|
objects = libsaria.data.load("library", ".dl_tree")
|
|
if objects == None or len(objects) != 6:
|
|
reset()
|
|
return
|
|
(fs_tree, tag_tree, index, tracks, next_id, size) = objects
|
|
load()
|
|
|
|
def save():
|
|
libsaria.data.save(
|
|
(fs_tree, tag_tree, index, tracks, next_id, size),
|
|
"library", ".dl_tree")
|
|
|
|
def walk_tags():
|
|
for tag in tag_tree.walk_forwards():
|
|
rec = tracks[tag[3]]
|
|
yield tag + [rec.year] + [rec.lenstr]
|
|
|
|
def file_to_id(file):
|
|
global fs_tree
|
|
stripped = file.strip(libsaria.path.sep)
|
|
split = stripped.split(libsaria.path.sep)
|
|
|
|
res = fs_tree.walk_path(split)
|
|
if res == False:
|
|
return None
|
|
return res[0]
|
|
|
|
def get_attr(id, attr):
|
|
rec = tracks.get(id, None)
|
|
if rec == None:
|
|
return None
|
|
if attr == "filepath":
|
|
cmp = rec.fs.walk_backwards()
|
|
return libsaria.path.sep.join([""] + cmp)
|
|
if attr == "playcount":
|
|
return rec.count
|
|
if attr == "year":
|
|
return rec.year
|
|
if attr == "lenstr":
|
|
return rec.lenstr
|
|
if attr == "score":
|
|
return rec.score
|
|
|
|
tags = rec.tags.walk_backwards()
|
|
if attr == "artist":
|
|
return tags[0]
|
|
if attr == "album":
|
|
return tags[1]
|
|
if attr == "title":
|
|
return tags[2]
|
|
|
|
def inc_score(id, amount=1):
|
|
rec = tracks.get(id, None)
|
|
if rec:
|
|
rec.score += amount
|
|
save()
|
|
|
|
def inc_count(id):
|
|
rec = tracks.get(id, None)
|
|
if rec:
|
|
rec.count += 1
|
|
save()
|
|
|
|
def is_visible(id):
|
|
return True
|