Playlists
I can add songs to a playlist and populate the playlist afterwards (and on startup).
This commit is contained in:
parent
02fe6dc8ba
commit
dc1b6dd4a6
|
@ -14,7 +14,8 @@ PLAYLIST = 1
|
|||
QUEUE = 2
|
||||
|
||||
import lens
|
||||
library = lens.Library()
|
||||
library = lens.Library()
|
||||
playlist = lens.Playlist()
|
||||
|
||||
cur_lib_id = -1
|
||||
|
||||
|
@ -59,6 +60,30 @@ def lib_is_visible(text):
|
|||
global library
|
||||
return library.is_visible(text)
|
||||
|
||||
def add_to_playlist(lib_id):
|
||||
print lib_id
|
||||
def walk_plist():
|
||||
global playlist
|
||||
global library
|
||||
get_attr = library.get_attr
|
||||
for id in playlist.walk_ids():
|
||||
yield [get_attr(id, "artist"), get_attr(id, "album"),
|
||||
get_attr(id, "title"), id, get_attr(id, "year"),
|
||||
get_attr(id, "lenstr")]
|
||||
|
||||
def plist_save():
|
||||
global playlist
|
||||
playlist.save()
|
||||
|
||||
def plist_add_libid(lib_id):
|
||||
global playlist
|
||||
artist = lib_get_attr(lib_id, "artist")
|
||||
album = lib_get_attr(lib_id, "album")
|
||||
title = lib_get_attr(lib_id, "title")
|
||||
playlist.insert_tags(artist, album, title, lib_id)
|
||||
|
||||
def plist_is_visible(text):
|
||||
global playlist
|
||||
return playlist.is_visible(text)
|
||||
|
||||
def plist_refresh():
|
||||
return call("PLISTREFRESH")
|
||||
|
||||
|
|
|
@ -82,6 +82,10 @@ class Collection:
|
|||
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 find_id(self, file):
|
||||
stripped = file.strip(libsaria.path.sep)
|
||||
split = stripped.split(libsaria.path.sep)
|
||||
|
@ -98,6 +102,10 @@ class Collection:
|
|||
return libsaria.path.sep.join([""] + cmp)
|
||||
if attr == "playcount":
|
||||
return rec.count
|
||||
if attr == "year":
|
||||
return rec.year
|
||||
if attr == "lenstr":
|
||||
return rec.lenstr
|
||||
|
||||
tags = rec.tags.walk_backwards()
|
||||
if attr == "artist":
|
||||
|
@ -107,6 +115,10 @@ class Collection:
|
|||
if attr == "title":
|
||||
return tags[2]
|
||||
|
||||
def insert_tags(self, artist, album, title, id):
|
||||
tags = self.tag_tree.insert([artist, album, title, id])
|
||||
self.index.insert([artist, album, title], id)
|
||||
|
||||
def insert_allocate(self, components, ref):
|
||||
t = ref.tag()
|
||||
artist = t.artist
|
||||
|
@ -128,7 +140,7 @@ class Collection:
|
|||
|
||||
fs = self.fs_tree.insert(components + [id])
|
||||
tags = self.tag_tree.insert([artist, album, title, id])
|
||||
self.index.insert([album, artist, title], id)
|
||||
self.index.insert([artist, album, title], id)
|
||||
|
||||
record.fs = fs
|
||||
record.tags = tags
|
||||
|
|
|
@ -21,6 +21,7 @@ def set_badfiles():
|
|||
if bf != None:
|
||||
badfiles = bf
|
||||
|
||||
|
||||
class Library(collection.Collection):
|
||||
def __init__(self):
|
||||
collection.Collection.__init__(self, "library.dl_tree")
|
||||
|
@ -56,3 +57,8 @@ class Library(collection.Collection):
|
|||
except UnicodeEncodeError:
|
||||
pass
|
||||
|
||||
|
||||
class Playlist(collection.Collection):
|
||||
def __init__(self):
|
||||
collection.Collection.__init__(self, "playlist.dl_tree")
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ win = ocarina.get_window(prefs["window_size"])
|
|||
ocarina.set_window_title("Ocarina 4.1")
|
||||
|
||||
ocarina.add_tab("Library", collection.Library())
|
||||
ocarina.add_tab("Playlist", collection.Playlist())
|
||||
|
||||
after = now()
|
||||
print "Startup took:", after-before
|
||||
|
|
|
@ -58,7 +58,9 @@ class Collection(gtk.ScrolledWindow):
|
|||
list.set_value(list_iter, len(list_row)-1, "Played: %s"%string)
|
||||
|
||||
def add_selected_to_playlist(self):
|
||||
self.list.for_each_selected(collection.add_to_playlist)
|
||||
self.list.for_each_selected(collection.plist_add_libid)
|
||||
collection.plist_save()
|
||||
collection.plist_refresh()
|
||||
|
||||
|
||||
class Library(Collection):
|
||||
|
@ -67,7 +69,7 @@ class Library(Collection):
|
|||
actions.mouse_motion = self.mouse_motion
|
||||
actions.selected_row = self.select_row
|
||||
actions.refilter = self.refilter
|
||||
actions.show_rc_menu = self.show_rc_menu
|
||||
actions.show_rc_menu = menu.make_lib_menu
|
||||
|
||||
Collection.__init__(self, actions)
|
||||
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
||||
|
@ -76,11 +78,11 @@ class Library(Collection):
|
|||
menu.add_lib_menu_item("Add to playlist", self.add_selected_to_playlist)
|
||||
|
||||
def populate(self):
|
||||
import datetime
|
||||
before = datetime.datetime.now()
|
||||
#import datetime
|
||||
#before = datetime.datetime.now()
|
||||
Collection.populate(self, collection.walk_library)
|
||||
after = datetime.datetime.now()
|
||||
print "Populating took: %s" % (after-before)
|
||||
#after = datetime.datetime.now()
|
||||
#print "Populating took: %s" % (after - before)
|
||||
|
||||
def refresh(self, arg):
|
||||
self.clear()
|
||||
|
@ -92,12 +94,46 @@ class Library(Collection):
|
|||
def select_row(self, row):
|
||||
collection.lib_play_id(row[0])
|
||||
|
||||
def show_rc_menu(self, button, time):
|
||||
menu.make_lib_menu(button, time)
|
||||
|
||||
def filter(self, text):
|
||||
collection.lib_filter(text)
|
||||
self.list.refilter()
|
||||
|
||||
def refilter(self, list, iter):
|
||||
return collection.lib_is_visible(list[iter][0])
|
||||
|
||||
|
||||
class Playlist(Collection):
|
||||
def __init__(self):
|
||||
actions = Actions()
|
||||
actions.mouse_motion = self.mouse_motion
|
||||
actions.selected_row = self.select_row
|
||||
actions.refilter = self.refilter
|
||||
actions.show_rc_menu = menu.make_plist_menu
|
||||
|
||||
Collection.__init__(self, actions)
|
||||
libsaria.event.invite("POSTSTART", self.populate, bg=True)
|
||||
libsaria.event.invite("POSTPLISTREFRESH", self.refresh)
|
||||
|
||||
def refresh(self, arg=None):
|
||||
self.clear()
|
||||
self.populate()
|
||||
|
||||
def populate(self):
|
||||
#import datetime
|
||||
#before = datetime.datetime.now()
|
||||
Collection.populate(self, collection.walk_plist)
|
||||
#after = datetime.datetime.now()
|
||||
#print "Populating took: %s" % (after - before)
|
||||
|
||||
def mouse_motion(self, row):
|
||||
return collection.lib_get_attr(row[0], "playcount")
|
||||
|
||||
def select_row(self, row):
|
||||
collection.lib_play_id(row[0])
|
||||
|
||||
def filter(self, text):
|
||||
collection.plist_filter(text)
|
||||
self.list.refilter()
|
||||
|
||||
def refilter(self, list, iter):
|
||||
return collection.plist_is_visible(list[iter][0])
|
||||
|
|
|
@ -21,3 +21,7 @@ def make_lib_menu(button, time):
|
|||
item.show()
|
||||
menu.append(item)
|
||||
menu.popup(None, None, None, button, time)
|
||||
|
||||
|
||||
def make_plist_menu(button, time):
|
||||
print "make_plist_menu() not implemented yet..."
|
||||
|
|
Loading…
Reference in New Issue