[Assorted-commits] SF.net SVN: assorted:[1141] music-labeler/trunk
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-01-25 03:12:13
|
Revision: 1141 http://assorted.svn.sourceforge.net/assorted/?rev=1141&view=rev Author: yangzhang Date: 2009-01-25 03:12:07 +0000 (Sun, 25 Jan 2009) Log Message: ----------- - added output back to playlists - refactored to separate the core gui from the quodlibet ETL - added tools.bash Modified Paths: -------------- music-labeler/trunk/README music-labeler/trunk/src/ml.py Added Paths: ----------- music-labeler/trunk/tools.bash Modified: music-labeler/trunk/README =================================================================== --- music-labeler/trunk/README 2009-01-24 23:57:46 UTC (rev 1140) +++ music-labeler/trunk/README 2009-01-25 03:12:07 UTC (rev 1141) @@ -12,8 +12,13 @@ - [pygtk] 2.13 - [Mutagen] 1.14 +Requirements for [Quodlibet] frontend: + +- [Quodlibet] 1.0 + [pygtk]: http://www.pygtk.org/ [Mutagen]: http://code.google.com/p/quodlibet/wiki/Development/Mutagen +[Quodlibet]: http://code.google.com/p/quodlibet/ Related ------- @@ -21,3 +26,9 @@ Another application that demonstrates GTK autocompletion is [drun] [drun]: http://sourceforge.net/projects/drun/ + +Todo +---- + +- Integrate into quodlibet. +- Move to quodlibet 2.0. Modified: music-labeler/trunk/src/ml.py =================================================================== --- music-labeler/trunk/src/ml.py 2009-01-24 23:57:46 UTC (rev 1140) +++ music-labeler/trunk/src/ml.py 2009-01-25 03:12:07 UTC (rev 1141) @@ -7,7 +7,22 @@ import gtk.keysyms as k, gtk.gdk as gdk from mutagen import File from os.path import expanduser +from path import path +from collections import defaultdict +# Quod Libet messiness. +sys.path.append('/usr/share/quodlibet/') +import util +util.gettext_install() +from browsers.playlists import Playlist +quote, unquote = Playlist.quote, Playlist.unquote + +# General stuff. + +do_debug = False +def debug(*args): + if do_debug: print ' '.join(map(str,args)) + cap = 50 def trunc(s): s = str(s) @@ -15,8 +30,7 @@ class struct(object): pass -def debug(*args): - if do_debug: print ' '.join(map(str,args)) +# GTK+ helpers. def connecting(widget, signal): def wrapper(handler): @@ -30,7 +44,9 @@ return handler return wrapper -def mainwin(): +# Main GUI layer. + +def labeler(pls, labels, track_paths): sep = ';' w = Window() @@ -51,14 +67,18 @@ es = [] rows = itertools.count() - def make_e(track): + def make_e(track_path): + meta = File(track_path) + def refresh(): 'Called when the list is changed.' labels.sort(key = str.lower) on_change() e = Entry() + e.set_text('; '.join(sorted(lbl for lbl, paths in pls.iteritems() + if track_path in paths) + [''])) self = struct() def get_pieces(do_strip = False, truncate = False): @@ -123,7 +143,7 @@ l.append([m]) # Something is always selected in the list. t.get_selection().select_path(0) - t.scroll_to_cell(0) + if len(l) > 0: t.scroll_to_cell(0) @connecting(e, 'key-press-event') def on_key_press(src, ev): @@ -227,25 +247,65 @@ tw.move(ex,ey+eh) row = rows.next() - caption = '%s - %s' % (trunc(track.get('TPE1','Unknown Artist')), - trunc(track.get('TIT2','Untitled'))) + caption = '%s - %s' % (trunc(meta.get('TPE1','Unknown Artist')), + trunc(meta.get('TIT2','Untitled'))) tab.attach(Label(str = caption), 0, 1, row, row+1) tab.attach(e, 1, 2, row, row+1) es.append(e) + return e + # Build row per track in New playlist. + path2e = {} + for track_path in track_paths: + path2e[track_path] = make_e(track_path) + # Final steps. - with file(expanduser('~/.quodlibet/playlists/New')) as f: - for line in f: - make_e(File(line.rstrip())) w.set_position(WIN_POS_CENTER) debug('size req:', tab.size_request()) w.set_default_size(800,600) w.show_all() + es[0].set_position(-1) main() + # Update playlists in memory. + newpls = defaultdict(set) + for track_path, e in path2e.iteritems(): + # Remove from all playlists. + for pl in pls.itervalues(): + pl.discard(track_path) + # Add to just the specified playlists. + for lbl in filter(lambda x: x, map(str.strip, e.get_text().split(';'))): + if lbl not in pls: pls[lbl] = set() + pls[lbl].add(track_path) + +# Code specific to quodlibet. + +def mainwin(): + "These are the actual tracks to use." + from os import listdir + pldir = path('~/.quodlibet/playlists/').expanduser() + + # Build dict mapping playlist to set of track paths. + pls = {} + specpl = 'New' + for pl in pldir.files(): + if pl.basename() != specpl: + with file(pl) as f: + pls[unquote(pl.basename())] = set(track.rstrip() for track in f) + labels = pls.keys() + + # The list of tracks to label. + with file(pldir / specpl) as f: + track_paths = map(str.rstrip, f) + + # Run the labeler. + labeler(pls, labels, track_paths) + + # Output the new playlists. + for lbl, pl in pls.iteritems(): + with file(pldir / quote(lbl), 'w') as f: + for track_path in sorted(pl, key = str.lower): + print >> f, track_path + if __name__ == '__main__': - from os import listdir - from urllib import quote, unquote - labels = map(unquote, listdir(expanduser('~/.quodlibet/playlists/'))) - do_debug = False mainwin() Added: music-labeler/trunk/tools.bash =================================================================== --- music-labeler/trunk/tools.bash (rev 0) +++ music-labeler/trunk/tools.bash 2009-01-25 03:12:07 UTC (rev 1141) @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -o errexit -o nounset + +for i in $1/* ; do + python -c " +s = '\n'.join(sorted(filter(lambda x: x!='', set(file('$i').read().split('\n'))), key=str.lower)) +print >> file('$i', 'w'), s" +done Property changes on: music-labeler/trunk/tools.bash ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |