- (fn, title, artist,
- album, date) = [x.replace("'", r"'\''")
- for x in (fn, title, artist, album, date)]
-
- outfile = ('%s (%s) %02d %s.mp3' % (artist, album,
- track, title)).replace('/', '_')
-
- run_or_die(3, "flac %s -cd %s %s '%s' | lame --add-id3v2 %s --tt '%s' --ta '%s' --tl '%s' --ty '%s' --tn %d - '%s'"
- % (flac_options, skip_arg or '', until_arg or '', fn,
- lame_options, title, artist, album, date, track, outfile))
-
- if pic != None:
- taglib.add_apic_frame_to_mp3(outfile, pic[0], pic[1], pic[2])
+ (fn, title, artist, album_artist,
+ album, date) = [(x or '').replace("'", r"'\''")
+ for x in [fn, title, artist, album_artist, album, date]]
+
+ album_artist_options = ''
+ if album_artist:
+ album_artist_options = "--tv 'TPE2=%s'" % album_artist
+
+ outfile_album = album
+ discnum_options = ''
+ if discnum != None:
+ outfile_album = '%s (disc %s)' % (album, discnum)
+ discnum_options = "--tv 'TPOS=%d'" % int(discnum)
+
+ quoted_outfile = ('%s (%s) %02d %s.mp3' % (artist, outfile_album,
+ track, title)).replace('/', '_')
+
+ pic_options = None
+ if pics:
+ (fd, picfn) = tempfile.mkstemp()
+ f = os.fdopen(fd, 'wb')
+ f.write(pics[0][7])
+ f.close()
+ pic_options = "--ti '%s'" % picfn
+ try:
+ run_or_die(3, "flac %s -cd %s '%s' | lame --id3v2-only --id3v2-latin1 --pad-id3v2-size 0 %s --tt '%s' --ta '%s' --tl '%s' --ty '%s' --tn %d %s %s %s - '%s'"
+ % (flac_options, ' '.join(skip_until), fn,
+ lame_options, title, artist, album, date, track,
+ pic_options, album_artist_options,
+ discnum_options, quoted_outfile))
+ finally:
+ if pic_options:
+ try:
+ os.unlink(picfn)
+ except:
+ pass