Remove old collection code and files
This commit is contained in:
parent
3cb1959a7f
commit
2b2cd7e805
|
@ -9,11 +9,6 @@ exists = libsaria.path.exists
|
||||||
expand = libsaria.path.expand
|
expand = libsaria.path.expand
|
||||||
FileRef = tagpy.FileRef
|
FileRef = tagpy.FileRef
|
||||||
|
|
||||||
LIBRARY = 0
|
|
||||||
PLAYLIST = 1
|
|
||||||
QUEUE = 2
|
|
||||||
|
|
||||||
import lens
|
|
||||||
import library
|
import library
|
||||||
import playlist
|
import playlist
|
||||||
|
|
||||||
|
@ -47,16 +42,6 @@ def lib_get_cur_id():
|
||||||
def plist_refresh():
|
def plist_refresh():
|
||||||
return call("PLISTREFRESH")
|
return call("PLISTREFRESH")
|
||||||
|
|
||||||
#def choose_next():
|
|
||||||
# global playlist
|
|
||||||
# global cur_lib_id
|
|
||||||
# if libsaria.prefs["random"] == True:
|
|
||||||
# next = playlist.random()
|
|
||||||
# else:
|
|
||||||
# next = playlist.next_id(cur_lib_id)
|
|
||||||
# if next != None:
|
|
||||||
# return call("NEXT", play_id, next)
|
|
||||||
|
|
||||||
def change_score():
|
def change_score():
|
||||||
prcnt = libsaria.audio.get_progress()
|
prcnt = libsaria.audio.get_progress()
|
||||||
if prcnt > 0.75:
|
if prcnt > 0.75:
|
||||||
|
|
|
@ -1,166 +0,0 @@
|
||||||
# Bryan Schumaker (8/8/2010)
|
|
||||||
|
|
||||||
import libsaria
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
timedelta = datetime.timedelta
|
|
||||||
|
|
||||||
tag = None
|
|
||||||
audio = None
|
|
||||||
ins_table = None
|
|
||||||
ins_index = None
|
|
||||||
ins_tree = None
|
|
||||||
|
|
||||||
class TrackRecord:
|
|
||||||
def __init__(self, year, length, lenstr):
|
|
||||||
self.length = length
|
|
||||||
if lenstr[0] == "0" and lenstr[1] == ":":
|
|
||||||
self.lenstr = lenstr[2:]
|
|
||||||
else:
|
|
||||||
self.lenstr = lenstr
|
|
||||||
self.count = 0
|
|
||||||
self.year = year
|
|
||||||
self.score = 0
|
|
||||||
|
|
||||||
self.fs = None
|
|
||||||
self.tags = None
|
|
||||||
|
|
||||||
|
|
||||||
class Collection:
|
|
||||||
def __init__(self, file):
|
|
||||||
self.file = file
|
|
||||||
self.load()
|
|
||||||
self.filtered = False
|
|
||||||
self.visible = None
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
libsaria.data.save(
|
|
||||||
(self.fs_tree, self.tag_tree, self.index, self.records,
|
|
||||||
self.next_record, self.size),
|
|
||||||
self.file, ".dl_tree")
|
|
||||||
|
|
||||||
def load(self):
|
|
||||||
objects = libsaria.data.load(self.file, ".dl_tree")
|
|
||||||
if objects == None or len(objects) != 6:
|
|
||||||
self.reset()
|
|
||||||
return
|
|
||||||
(self.fs_tree, self.tag_tree, self.index, self.records,
|
|
||||||
self.next_record, self.size) = objects
|
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
from tree import DLTree
|
|
||||||
from index import Index
|
|
||||||
self.fs_tree = DLTree()
|
|
||||||
self.tag_tree = DLTree()
|
|
||||||
self.index = Index()
|
|
||||||
self.records = dict()
|
|
||||||
self.next_record = 0
|
|
||||||
self.size = 0
|
|
||||||
|
|
||||||
def disp(self):
|
|
||||||
pass
|
|
||||||
#self.fs_tree.disp()
|
|
||||||
#print
|
|
||||||
#print
|
|
||||||
#self.tag_tree.disp()
|
|
||||||
|
|
||||||
def filter(self, text):
|
|
||||||
if len(text) > 0:
|
|
||||||
self.visible = self.index.filter(text)
|
|
||||||
self.filtered = True
|
|
||||||
else:
|
|
||||||
self.visible = None
|
|
||||||
self.filtered = False
|
|
||||||
|
|
||||||
def is_visible(self, id):
|
|
||||||
if self.filtered == False:
|
|
||||||
return True
|
|
||||||
return id in self.visible
|
|
||||||
|
|
||||||
def num_visible(self):
|
|
||||||
if self.filtered == True:
|
|
||||||
return len(self.visible)
|
|
||||||
else:
|
|
||||||
return self.size
|
|
||||||
|
|
||||||
def walk_tags(self):
|
|
||||||
for tag in self.tag_tree.walk_forwards():
|
|
||||||
rec = self.records[tag[3]]
|
|
||||||
yield tag + [rec.year] + [rec.lenstr]
|
|
||||||
|
|
||||||
def walk_ids(self):
|
|
||||||
for tag in self.tag_tree.walk_forwards():
|
|
||||||
yield tag[3]
|
|
||||||
|
|
||||||
def walk_filtered_ids(self):
|
|
||||||
for id in self.visible:
|
|
||||||
yield id
|
|
||||||
|
|
||||||
def find_id(self, file):
|
|
||||||
stripped = file.strip(libsaria.path.sep)
|
|
||||||
split = stripped.split(libsaria.path.sep)
|
|
||||||
|
|
||||||
res = self.fs_tree.walk_path(split)
|
|
||||||
if res == False:
|
|
||||||
return None
|
|
||||||
return res[0]
|
|
||||||
|
|
||||||
def has_id(self, id):
|
|
||||||
return id in self.index
|
|
||||||
|
|
||||||
def get_attr(self, id, attr):
|
|
||||||
rec = self.records[id]
|
|
||||||
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 insert_tags(self, artist, album, title, id):
|
|
||||||
if self.has_id(id) == True:
|
|
||||||
return
|
|
||||||
tags = self.tag_tree.insert([artist, album, title, id])
|
|
||||||
self.index.insert([artist, album, title], id)
|
|
||||||
self.size += 1
|
|
||||||
|
|
||||||
def insert_allocate(self, components, ref):
|
|
||||||
t = ref.tag()
|
|
||||||
artist = t.artist
|
|
||||||
album = t.album
|
|
||||||
title = t.title
|
|
||||||
audio = ref.audioProperties()
|
|
||||||
if artist == "":
|
|
||||||
artist = u"Unknown Artist"
|
|
||||||
if album == "":
|
|
||||||
album = u"Unknown Album"
|
|
||||||
if title == "":
|
|
||||||
title = u"Unknown Title"
|
|
||||||
|
|
||||||
len = audio.length
|
|
||||||
record = TrackRecord(t.year, len, "%s" % timedelta(seconds=len))
|
|
||||||
|
|
||||||
id = self.next_record
|
|
||||||
self.next_record += 1
|
|
||||||
|
|
||||||
fs = self.fs_tree.insert(components + [id])
|
|
||||||
tags = self.tag_tree.insert([artist, album, title, id])
|
|
||||||
self.index.insert([artist, album, title], id)
|
|
||||||
|
|
||||||
record.fs = fs
|
|
||||||
record.tags = tags
|
|
||||||
self.records[id] = record
|
|
||||||
self.size += 1
|
|
|
@ -1,130 +0,0 @@
|
||||||
# Bryan Schumaker (10/1/2010)
|
|
||||||
|
|
||||||
import libsaria
|
|
||||||
import collection
|
|
||||||
|
|
||||||
import random as rand
|
|
||||||
|
|
||||||
from libsaria import data
|
|
||||||
|
|
||||||
save = data.save
|
|
||||||
load = data.load
|
|
||||||
|
|
||||||
sep = libsaria.path.sep
|
|
||||||
walk = libsaria.path.walk
|
|
||||||
join = libsaria.path.join
|
|
||||||
splitext = libsaria.path.splitext
|
|
||||||
|
|
||||||
badfiles = set()
|
|
||||||
|
|
||||||
def set_badfiles():
|
|
||||||
global badfiles
|
|
||||||
bf = load("badfiles")
|
|
||||||
if bf != None:
|
|
||||||
badfiles = bf
|
|
||||||
|
|
||||||
|
|
||||||
class Library(collection.Collection):
|
|
||||||
def __init__(self):
|
|
||||||
collection.Collection.__init__(self, "library")
|
|
||||||
|
|
||||||
def scan(self, path):
|
|
||||||
print "Library scanning %s" % path
|
|
||||||
set_badfiles()
|
|
||||||
self.update(path)
|
|
||||||
self.save()
|
|
||||||
save(badfiles, "badfiles", "")
|
|
||||||
self.disp()
|
|
||||||
|
|
||||||
def update(self, path):
|
|
||||||
global badfiles
|
|
||||||
FileRef = libsaria.collection.FileRef
|
|
||||||
find_id = self.find_id
|
|
||||||
|
|
||||||
for root,dirs,files in walk(path):
|
|
||||||
stripped_root = root.strip(sep)
|
|
||||||
split_root = stripped_root.split(sep)
|
|
||||||
for file in files:
|
|
||||||
ext = splitext(file)[1]
|
|
||||||
if ext in badfiles:
|
|
||||||
continue
|
|
||||||
path = join(root, file)
|
|
||||||
if find_id(path) != None:
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
ref = FileRef(path)
|
|
||||||
except:
|
|
||||||
badfiles.add(ext)
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
self.insert_allocate(split_root + [file], ref)
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Playlist(collection.Collection):
|
|
||||||
def __init__(self):
|
|
||||||
collection.Collection.__init__(self, "playlist")
|
|
||||||
self.last_tracks = []
|
|
||||||
|
|
||||||
def next_id(self, last_id):
|
|
||||||
return_next = False
|
|
||||||
first = None
|
|
||||||
visible = self.is_visible
|
|
||||||
for id in self.walk_ids():
|
|
||||||
if visible(id):
|
|
||||||
if first == None:
|
|
||||||
first = id
|
|
||||||
if return_next == True:
|
|
||||||
return id
|
|
||||||
if id == last_id:
|
|
||||||
return_next = True
|
|
||||||
if first != None:
|
|
||||||
return first
|
|
||||||
return None
|
|
||||||
|
|
||||||
def random(self):
|
|
||||||
if self.size == 0:
|
|
||||||
return
|
|
||||||
getattr = libsaria.collection.get_attrs
|
|
||||||
last = self.last_tracks
|
|
||||||
for i in xrange(15):
|
|
||||||
id = self.get_rand_candidate()
|
|
||||||
artist = getattr(id, "artist")[0]
|
|
||||||
album = getattr(id, "album")[0]
|
|
||||||
title = getattr(id, "title")[0]
|
|
||||||
if (artist, title) in last:
|
|
||||||
print "Skipping %s by %s because it has played recently." % (title, artist)
|
|
||||||
continue
|
|
||||||
score = getattr(id, "score")[0]
|
|
||||||
if score < 0:
|
|
||||||
play_anyway = rand.randint(0, 100)
|
|
||||||
if play_anyway < ((20 * score) + 100):
|
|
||||||
print "Skipping %s by %s because I don't think you want to hear it." % (title, artist)
|
|
||||||
continue
|
|
||||||
last.append((artist, title))
|
|
||||||
if len(last) > 30:
|
|
||||||
last.pop(0)
|
|
||||||
if i > 0:
|
|
||||||
print "Picking a song took %s iterations" % i
|
|
||||||
return id
|
|
||||||
return id
|
|
||||||
|
|
||||||
def get_rand_candidate(self):
|
|
||||||
num = self.num_visible()
|
|
||||||
next_idx = rand.randint(0, num-1)
|
|
||||||
func = self.walk_filtered_ids
|
|
||||||
if self.filtered == False:
|
|
||||||
func = self.walk_ids
|
|
||||||
for n in func():
|
|
||||||
if next_idx == 0:
|
|
||||||
return n
|
|
||||||
next_idx -= 1
|
|
||||||
# We shouldn't ever get here, but for some reason we are.
|
|
||||||
# We return the last value of n, but I would like to figure
|
|
||||||
# Out why we leave the loop early eventually.
|
|
||||||
return n
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ for s in string.lowercase:
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
from libsaria.trees import FSTree, DLFSTree, DLValTree
|
from libsaria.trees import FSTree, DLFSTree, DLValTree
|
||||||
from tree import DLTree
|
|
||||||
from index import Index
|
from index import Index
|
||||||
|
|
||||||
global index
|
global index
|
||||||
|
@ -46,7 +45,6 @@ def reset():
|
||||||
tracks = dict()
|
tracks = dict()
|
||||||
size = 0
|
size = 0
|
||||||
visible = set()
|
visible = set()
|
||||||
#save()
|
|
||||||
|
|
||||||
def load():
|
def load():
|
||||||
global fs_tree
|
global fs_tree
|
||||||
|
@ -54,15 +52,11 @@ def load():
|
||||||
global index
|
global index
|
||||||
global tracks
|
global tracks
|
||||||
global sources
|
global sources
|
||||||
#global size
|
|
||||||
#global songs
|
|
||||||
objects = libsaria.data.load("library", ".lib")
|
objects = libsaria.data.load("library", ".lib")
|
||||||
if objects == None or len(objects) != 5:
|
if objects == None or len(objects) != 5:
|
||||||
#if objects == None or len(objects) != 6:
|
|
||||||
reset()
|
reset()
|
||||||
return
|
return
|
||||||
(sources, tracks, fs_tree, tag_tree, index) = objects
|
(sources, tracks, fs_tree, tag_tree, index) = objects
|
||||||
#(fs_tree, tag_tree, index, tracks, next_id, size) = objects
|
|
||||||
libsaria.event.start("POSTLIBLOAD")
|
libsaria.event.start("POSTLIBLOAD")
|
||||||
|
|
||||||
def save():
|
def save():
|
||||||
|
|
|
@ -109,7 +109,6 @@ def rand_next():
|
||||||
def next():
|
def next():
|
||||||
if libsaria.prefs["random"] == True:
|
if libsaria.prefs["random"] == True:
|
||||||
id = rand_next()
|
id = rand_next()
|
||||||
print id, library.get_attrs(id, "filepath")
|
|
||||||
else:
|
else:
|
||||||
id = seq_next()
|
id = seq_next()
|
||||||
if id != None:
|
if id != None:
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
# Bryan Schumaker (8 / 12 / 2010)
|
|
||||||
|
|
||||||
classes = set([str, int, unicode])
|
|
||||||
|
|
||||||
class DLTree:
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
self.parent = parent
|
|
||||||
self.child_fwd = dict()
|
|
||||||
self.child_bck = dict()
|
|
||||||
|
|
||||||
def disp(self, level=0):
|
|
||||||
space = " " * level
|
|
||||||
children = self.children
|
|
||||||
|
|
||||||
if children == None:
|
|
||||||
return
|
|
||||||
|
|
||||||
keys = children.keys()
|
|
||||||
keys.sort()
|
|
||||||
|
|
||||||
for key in keys:
|
|
||||||
if key.__class__ in classes:#== str or key.__class__ == int or key.__class__ == unicode:
|
|
||||||
#value = children[key]
|
|
||||||
yield key
|
|
||||||
#value.disp(level+1)
|
|
||||||
|
|
||||||
#if len(self.children) == 0:
|
|
||||||
# print self.get_path()
|
|
||||||
|
|
||||||
def walk_path(self, path):
|
|
||||||
if len(path) == 0:
|
|
||||||
return True
|
|
||||||
p = path[0]
|
|
||||||
if p not in self.child_fwd:
|
|
||||||
return False
|
|
||||||
child = self.child_fwd[p]
|
|
||||||
val = child.walk_path(path[1:])
|
|
||||||
if val == True:
|
|
||||||
return child.child_fwd.keys()
|
|
||||||
return val
|
|
||||||
|
|
||||||
def walk_backwards(self, child=None):
|
|
||||||
cmp = self.child_bck.get(child, None)
|
|
||||||
if self.parent == None:
|
|
||||||
return [cmp]
|
|
||||||
child = self
|
|
||||||
path = self.parent.walk_backwards(child)
|
|
||||||
if cmp != None:
|
|
||||||
path.append(cmp)
|
|
||||||
return path
|
|
||||||
|
|
||||||
def walk_forwards(self):
|
|
||||||
children = self.child_fwd
|
|
||||||
|
|
||||||
keys = children.keys()
|
|
||||||
keys.sort()
|
|
||||||
|
|
||||||
for key in keys:
|
|
||||||
child = children[key]
|
|
||||||
has_children = False
|
|
||||||
for result in child.walk_forwards():
|
|
||||||
has_children = True
|
|
||||||
res = [key]
|
|
||||||
if result != None:
|
|
||||||
res += result
|
|
||||||
yield res
|
|
||||||
# A leaf will have no children, but
|
|
||||||
# still needs to yield a value
|
|
||||||
if has_children == False:
|
|
||||||
yield [key]
|
|
||||||
|
|
||||||
def insert(self, path):
|
|
||||||
cmp = path[0]
|
|
||||||
child = None
|
|
||||||
try:
|
|
||||||
child = self.child_fwd[cmp]
|
|
||||||
except TypeError:
|
|
||||||
child = DLTree(self)
|
|
||||||
self.child_fwd[cmp] = child
|
|
||||||
self.child_bck[child] = cmp
|
|
||||||
except KeyError:
|
|
||||||
child = DLTree(self)
|
|
||||||
self.child_fwd[cmp] = child
|
|
||||||
self.child_bck[child] = cmp
|
|
||||||
if len(path) > 1:
|
|
||||||
return child.insert(path[1:])
|
|
||||||
return self
|
|
Loading…
Reference in New Issue