@@ -157,7 +157,7 @@ def get_r128_loudness(audio_filepaths, *, calc_peak=True, enable_ffmpeg_threadin
157
157
158
158
159
159
def scan (audio_filepaths , * , album_gain = False , skip_tagged = False , thread_count = None , ffmpeg_path = None , executor = None ,
160
- progress = None ):
160
+ progress = None , boxed_error_count = None ):
161
161
""" Analyze files, and return a dictionary of filepath to loudness metadata or filepath to future if executor is not None. """
162
162
r128_data = {}
163
163
@@ -235,6 +235,8 @@ def scan(audio_filepaths, *, album_gain=False, skip_tagged=False, thread_count=N
235
235
logger ().warning ("Failed to analyze file '%s': %s %s" % (audio_filepath ,
236
236
e .__class__ .__qualname__ ,
237
237
e ))
238
+ if boxed_error_count is not None :
239
+ boxed_error_count [0 ] += 1
238
240
else :
239
241
if result is not None : # track/album gain was not skipped
240
242
r128_data [audio_filepath ] = result
@@ -348,9 +350,8 @@ def tag(filepath, loudness, peak, *,
348
350
mf ["----:COM.APPLE.ITUNES:REPLAYGAIN_ALBUM_PEAK" ] = mutagen .mp4 .MP4FreeForm (("%.6f" % (album_peak )).encode ())
349
351
350
352
else :
351
- logger ().warning ("Unhandled '%s' tag format for file '%s'" % (mf .__class__ .__name__ ,
352
- filepath ))
353
- return
353
+ raise RuntimeError ("Unhandled '%s' tag format for file '%s'" % (mf .__class__ .__name__ ,
354
+ filepath ))
354
355
355
356
mf .save ()
356
357
@@ -437,6 +438,8 @@ def show_scan_report(audio_filepaths, album_dir, r128_data):
437
438
def process (audio_filepaths , * , album_gain = False , opus_output_gain = False , mtime_second_offset = None , skip_tagged = False ,
438
439
thread_count = None , ffmpeg_path = None , dry_run = False , report = False ):
439
440
""" Analyze and tag input audio files. """
441
+ error_count = 0
442
+
440
443
with contextlib .ExitStack () as cm :
441
444
if sys .stderr .isatty () and logging .getLogger ().isEnabledFor (logging .INFO ):
442
445
progress = cm .enter_context (tqdm .tqdm (total = len (audio_filepaths ) + int (album_gain ),
@@ -453,7 +456,8 @@ def process(audio_filepaths, *, album_gain=False, opus_output_gain=False, mtime_
453
456
skip_tagged = skip_tagged ,
454
457
thread_count = thread_count ,
455
458
ffmpeg_path = ffmpeg_path ,
456
- progress = progress )
459
+ progress = progress ,
460
+ boxed_error_count = [error_count ])
457
461
458
462
if report :
459
463
show_scan_report (audio_filepaths ,
@@ -486,11 +490,16 @@ def process(audio_filepaths, *, album_gain=False, opus_output_gain=False, mtime_
486
490
logger ().error ("Failed to tag file '%s': %s %s" % (audio_filepath ,
487
491
e .__class__ .__qualname__ ,
488
492
e ))
493
+ error_count += 1
494
+
495
+ return error_count
489
496
490
497
491
498
def process_recursive (directories , * , album_gain = False , opus_output_gain = False , mtime_second_offset = None ,
492
499
skip_tagged = False , thread_count = None , ffmpeg_path = None , dry_run = False , report = False ):
493
500
""" Analyze and tag all audio files recursively found in input directories. """
501
+ error_count = 0
502
+
494
503
if thread_count is None :
495
504
try :
496
505
thread_count = len (os .sched_getaffinity (0 ))
@@ -568,6 +577,7 @@ def process_recursive(directories, *, album_gain=False, opus_output_gain=False,
568
577
logger ().warning ("Failed to analyze file '%s': %s %s" % (key ,
569
578
e .__class__ .__qualname__ ,
570
579
e ))
580
+ error_count += 1
571
581
else :
572
582
if result is not None :
573
583
r128_data [key ] = result
@@ -601,6 +611,7 @@ def process_recursive(directories, *, album_gain=False, opus_output_gain=False,
601
611
logger ().error ("Failed to tag file '%s': %s %s" % (audio_filepath ,
602
612
e .__class__ .__qualname__ ,
603
613
e ))
614
+ error_count += 1
604
615
605
616
to_del_futures .add (done_future )
606
617
for f in other_dir_futures :
@@ -609,6 +620,8 @@ def process_recursive(directories, *, album_gain=False, opus_output_gain=False,
609
620
for to_del_future in to_del_futures :
610
621
del futures [to_del_future ]
611
622
623
+ return error_count
624
+
612
625
613
626
def cl_main ():
614
627
# parse args
@@ -704,25 +717,28 @@ def cl_main():
704
717
705
718
# main
706
719
if args .recursive :
707
- process_recursive (args .path ,
708
- album_gain = args .album_gain ,
709
- opus_output_gain = args .opus_output_gain ,
710
- mtime_second_offset = args .mtime_second_offset ,
711
- skip_tagged = args .skip_tagged ,
712
- thread_count = args .thread_count ,
713
- ffmpeg_path = args .ffmpeg_path ,
714
- dry_run = args .dry_run ,
715
- report = logging .getLogger ().isEnabledFor (logging .INFO ) or args .dry_run )
720
+ err_count = process_recursive (args .path ,
721
+ album_gain = args .album_gain ,
722
+ opus_output_gain = args .opus_output_gain ,
723
+ mtime_second_offset = args .mtime_second_offset ,
724
+ skip_tagged = args .skip_tagged ,
725
+ thread_count = args .thread_count ,
726
+ ffmpeg_path = args .ffmpeg_path ,
727
+ dry_run = args .dry_run ,
728
+ report = logging .getLogger ().isEnabledFor (logging .INFO ) or args .dry_run )
716
729
else :
717
- process (args .path ,
718
- album_gain = args .album_gain ,
719
- opus_output_gain = args .opus_output_gain ,
720
- mtime_second_offset = args .mtime_second_offset ,
721
- skip_tagged = args .skip_tagged ,
722
- thread_count = args .thread_count ,
723
- ffmpeg_path = args .ffmpeg_path ,
724
- dry_run = args .dry_run ,
725
- report = logging .getLogger ().isEnabledFor (logging .INFO ) or args .dry_run )
730
+ err_count = process (args .path ,
731
+ album_gain = args .album_gain ,
732
+ opus_output_gain = args .opus_output_gain ,
733
+ mtime_second_offset = args .mtime_second_offset ,
734
+ skip_tagged = args .skip_tagged ,
735
+ thread_count = args .thread_count ,
736
+ ffmpeg_path = args .ffmpeg_path ,
737
+ dry_run = args .dry_run ,
738
+ report = logging .getLogger ().isEnabledFor (logging .INFO ) or args .dry_run )
739
+
740
+ if err_count > 0 :
741
+ exit (1 )
726
742
727
743
728
744
if getattr (sys , "frozen" , False ):
0 commit comments