[Assorted-commits] SF.net SVN: assorted:[1142] music-labeler/trunk/src/ml.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-01-25 06:26:22
|
Revision: 1142 http://assorted.svn.sourceforge.net/assorted/?rev=1142&view=rev Author: yangzhang Date: 2009-01-25 06:26:15 +0000 (Sun, 25 Jan 2009) Log Message: ----------- - proper parsing of metadata - fixed modifier mask handling - don't write if no change Modified Paths: -------------- music-labeler/trunk/src/ml.py Modified: music-labeler/trunk/src/ml.py =================================================================== --- music-labeler/trunk/src/ml.py 2009-01-25 03:12:07 UTC (rev 1141) +++ music-labeler/trunk/src/ml.py 2009-01-25 06:26:15 UTC (rev 1142) @@ -3,9 +3,9 @@ from __future__ import with_statement from gtk import * from cgi import escape +from cStringIO import StringIO import itertools 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 @@ -13,6 +13,7 @@ # Quod Libet messiness. sys.path.append('/usr/share/quodlibet/') import util +import formats util.gettext_install() from browsers.playlists import Playlist quote, unquote = Playlist.quote, Playlist.unquote @@ -69,7 +70,7 @@ def make_e(track_path): - meta = File(track_path) + meta = formats.MusicFile(track_path) def refresh(): 'Called when the list is changed.' @@ -174,14 +175,14 @@ refresh() if ev.keyval in [k.Down, k.Up] or \ - (ev.keyval in [k.n, k.p] and ev.state == gdk.CONTROL_MASK): + (ev.keyval in [k.n, k.p] and ev.state & gdk.CONTROL_MASK): # Up/down selects prev/next row in the list, if possible, and scroll to # center that row. sel = t.get_selection() mdl, itr = sel.get_selected() assert mdl is l dir = 1 if ev.keyval == k.Down or \ - (ev.keyval == k.n and ev.state == gdk.CONTROL_MASK) else -1 + (ev.keyval == k.n and ev.state & gdk.CONTROL_MASK) else -1 if itr is not None: (pos,) = l.get_path(itr) pos += dir @@ -202,7 +203,7 @@ txt = get_mid() if txt == '': # Move on to next track. - dir,inc = ('prev',-1) if ev.state == gdk.SHIFT_MASK else ('next',1) + dir,inc = ('prev',-1) if ev.state & gdk.SHIFT_MASK else ('next',1) debug('moving to %s track' % dir) nexte = es[(es.index(e) + inc) % len(es)] nexte.grab_focus() @@ -244,11 +245,12 @@ debug('win.orig:', win.get_origin()) debug('win.pos:', win.get_position()) tw.set_size_request(ew,-1) - tw.move(ex,ey+eh) + # Position the popup to the right. + tw.move(ex+ew,ey) row = rows.next() - caption = '%s - %s' % (trunc(meta.get('TPE1','Unknown Artist')), - trunc(meta.get('TIT2','Untitled'))) + caption = '%s - %s' % (trunc(meta.get('artist', '[Unknown Artist]')), + trunc(meta.get('title', '[Untitled]'))) tab.attach(Label(str = caption), 0, 1, row, row+1) tab.attach(e, 1, 2, row, row+1) es.append(e) @@ -301,11 +303,21 @@ # Run the labeler. labeler(pls, labels, track_paths) - # Output the new playlists. + # Output the new playlists, but only if there's any difference. 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 + f = StringIO() + for track_path in sorted(pl, key = str.lower): + print >> f, track_path + new = f.getvalue() + if not (pldir / quote(lbl)).exists(): + old = '' + else: + with file(pldir / quote(lbl)) as f: + old = f.read() + if old != new != '': + print 'updating', lbl + with file(pldir / quote(lbl), 'w') as f: + f.write(new) if __name__ == '__main__': mainwin() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |