+ quoted_outfile = ('%s (%s) %02d %s.mp3' % (artist, outfile_album,
+ track, title)).replace('/', '_')
+ # HACK! :(
+ if check_missing:
+ return quoted_outfile.replace(r"'\''", "'")
+
+ pic_options = ''
+ (fd, picfn) = tempfile.mkstemp()
+ os.close(fd)
+ p = Popen(['metaflac', '--export-picture-to', picfn, unquoted_fn],
+ stderr=PIPE)
+ status = p.wait()
+ stderr = ''.join(p.stderr)
+ # Hacky check for flac with no album art
+ if 'no PICTURE block' in stderr:
+ # That's fine, just no picture.
+ pass
+ else:
+ if status != 0:
+ sys.stderr.write('metaflac exited %d: %s\n' % (status, stderr))
+ return
+ pic_options = "--ti '%s'" % picfn
+ try:
+ # TODO: Look at TDOR, TDRL, TDRC for date.
+ 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:
+ try:
+ os.unlink(picfn)
+ except:
+ pass