X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/31cfad82f74bdd8d803c214e4755bd9c82d8e4db..29d7234bd6c1853dc02c4e3c6c47c099bb1241a7:/fa-flacd?ds=inline diff --git a/fa-flacd b/fa-flacd index e291b75..8166b94 100755 --- a/fa-flacd +++ b/fa-flacd @@ -1,4 +1,4 @@ -#! /usr/bin/env python2.4 +#! /usr/bin/python """ =head1 NAME @@ -85,13 +85,20 @@ from errno import EEXIST, ENOENT from glob import glob from optparse import OptionParser -import org.diplodocus.jobs -from org.diplodocus.structures import ListDictDict -from org.diplodocus.util import die, flatten, nothing -from org.diplodocus.util import catch_EnvironmentError as c - from flac_archive.tags import Tags +def c(f, *args): + try: + return f(*args) + except EnvironmentError, error: + error.msg = '%s.%s(%s): ' % (f.__module__, f.__name__, + ', '.join(map(str, args))) + raise + +def die(e, *args): + sys.stderr.write(''.join(args)) + sys.exit(e) + def spew(*args): if verbose: for i in args: @@ -109,7 +116,8 @@ def run_flac(infile, cue, outfile, tags): argv.extend(['-T', i]) argv.append(infile) # flac 1.1.3 PICTURE support - argv.extend(['--picture', '3|image/jpeg|||cover.front']) + if os.path.exists('cover.front'): + argv.extend(['--picture', '3|image/jpeg|||cover.front']) spew('Running flac\n') status = os.spawnvp(os.P_WAIT, argv[0], argv) @@ -125,7 +133,11 @@ def flac(dir, tracknum, tags): flac files represent individual tracks or whole discs.""" separator = ' ' - artist = (tags.gets('ARTIST', separator=', ') or '').replace('/', '_') + if len(tags.get('ALBUMARTIST')) > 0: + artist_tag = tags.gets('ALBUMARTIST', separator=', ') + else: + artist_tag = tags.gets('ARTIST', separator=', ') + artist = (artist_tag or '').replace('/', '_') album = (tags.gets('ALBUM', separator=separator) or '').replace('/', '_') discnum = tags.gets('DISCNUMBER') @@ -189,7 +201,10 @@ def flac(dir, tracknum, tags): ld = os.listdir(dir) if ld == ['using-tags'] or sorted(ld) == ['cover.front', 'using-tags']: try: - os.unlink(dir + '/cover.front') + try: + os.unlink(dir + '/cover.front') + except OSError: + pass os.unlink(dir + '/using-tags') os.rmdir(dir) except EnvironmentError: @@ -275,11 +290,8 @@ def flacloop(maxjobs): return 1 return lamb - def notify_start(pid, jobs): - # make this print '2 jobs; start 378 for Artist/01 Title.flac' - spew('%d jobs; start %d for %s\n' % (len(jobs), pid, dir[0])) - - def notify_finish(pid, status, jobs): + while True: + status = getjob(lambda *a,**k: None)() spew('%d jobs; %d finished (' % (len(jobs), pid)) if os.WIFEXITED(status): spew('exited with status ', str(os.WEXITSTATUS(status))) @@ -289,12 +301,6 @@ def flacloop(maxjobs): spew('stopped with signal ', str(os.WSTOPSIG(status))) spew(')\n') - # Never returns (see getjob comment). - org.diplodocus.jobs.run(maxjobs=maxjobs, debug=debug, - get_job=getjob, - notify_start=notify_start, - notify_finish=notify_finish) - def main(argv): # Control the exit code for any uncaught exceptions. try: