|
63 | 63 | # errors when piping something to cue_file |
64 | 64 | # - streamline tag conversion code a little |
65 | 65 | # - only write known tags, not all `liq_*` |
| 66 | +# 2024-07-02 Moonbase59 - v4.0.5 Fix minor bugs with file duration |
66 | 67 | # |
67 | 68 | # Originally based on an idea and some code by John Warburton (@Warblefly): |
68 | 69 | # https://github.com/Warblefly/TrackBoundaries |
69 | 70 | # Some collaborative work with RM-FM (@RM-FM): Sustained ending analysis. |
70 | 71 |
|
71 | 72 | __author__ = 'Matthias C. Hormann' |
72 | | -__version__ = '4.0.4' |
| 73 | +__version__ = '4.0.5' |
73 | 74 |
|
74 | 75 | import os |
75 | 76 | import sys |
@@ -356,10 +357,10 @@ def read_tags( |
356 | 357 | tags_found = {**tags_in_stream, **tags_in_format, **tags_in_json} |
357 | 358 | # eprint(json.dumps(tags_found, indent=2, sort_keys=True)) |
358 | 359 |
|
359 | | - # add duration of stream #0 |
| 360 | + # add duration of stream #0 if it exists and can be converted to float |
360 | 361 | try: |
361 | | - tags_found["duration"] = result['streams'][0]['duration'] |
362 | | - except KeyError: |
| 362 | + tags_found["duration"] = float(result['streams'][0]['duration']) |
| 363 | + except (KeyError, ValueError): |
363 | 364 | try: |
364 | 365 | # we might have a video duration (.mka) like "00:07:01.117000000", |
365 | 366 | # ignore |
@@ -903,6 +904,10 @@ def write_tags(filename, tags={}, replaygain=False): |
903 | 904 | tags_new.pop(k, None) |
904 | 905 | del tags_new["R128_TRACK_GAIN"] |
905 | 906 |
|
| 907 | + # Never write "duration" to tags |
| 908 | + if "duration" in tags_new: |
| 909 | + del tags_new["duration"] |
| 910 | + |
906 | 911 | # eprint(replaygain, temp, json.dumps(tags_new, indent=2)) |
907 | 912 |
|
908 | 913 | if MUTAGEN_AVAILABLE and filename.suffix.casefold() in mp4_ext: |
@@ -1223,6 +1228,9 @@ if args.force or not skip_analysis: |
1223 | 1228 | # allow to override even the analysis results |
1224 | 1229 | if args.json: |
1225 | 1230 | result = override_from_JSON(result, tags_json) |
| 1231 | + # override duration, seems ffprobe can be more exact |
| 1232 | + if "duration" in tags_found: |
| 1233 | + result["duration"] = tags_found["duration"] |
1226 | 1234 | else: |
1227 | 1235 | result = add_missing(tags_found, args.target, args.blankskip, args.noclip) |
1228 | 1236 |
|
|
0 commit comments