(noob alert) why doesn't this work?
Bengt Richter
bokr at oz.net
Tue Mar 22 19:17:08 EST 2005
On Tue, 22 Mar 2005 09:21:49 -0800, Scott David Daniels <Scott.Daniels at Acm.Org> wrote:
>Bouke Woudstra wrote:
>> It turned out that some flac files have tags like Artist=artistname and others
>> have artist=artistname. Therefore it couldn't find the artist! So now I just
>> look for 'rtist=' which works great.
>
>You might want try using something like this:
>
> wanted = set('artist album date title tracknumber genre'.split())
> ...
>
> def read_and_call(self, flac, source):
> parts = {}
> for line in source:
> try:
> head, remainder = line.split('=', 1)
> except ValueError:
> pass # No equal sign in the line
> else:
> head = head.strip().lower()
> if head in wanted:
> parts[head] = remainder.strip()
> self.wav2mp3(flac, **parts)
Doesn't wav2mp3 have to have default arg values for that, if parts doesn't have all the args?
Alternatively (and untested!) hopefully providing all wav2mp3 args in order:
def flactags(self):
flacfiles = glob.glob('*flac')
flacfiles.sort()
for flac in flacfiles:
cmd = 'metaflac --export-tags=- "%s"' % flac
# collect available tags, then make arg list with '??' for missing values
tagdict = dict((pair[0].strip().lower(), pair[1].strip()) for pair in
(line.split('=', 1) for line in os.popen(cmd).readlines()) if len(pair)==2)
args = [tagdict.get(tag, '??') for tag in 'artist, album, year, number, genre'.split()]
self.wav2mp3(flac, *args)
Regards,
Bengt Richter
More information about the Python-list
mailing list