thebigmunch / audio-metadata

A library for reading and, in the future, writing audio metadata. https://audio-metadata.readthedocs.io/
https://forum.thebigmunch.me
MIT License
53 stars 11 forks source link

Handle ValueError: year 0 is out of range #40

Open jsetton opened 3 years ago

jsetton commented 3 years ago

audio-metadata version

Name: audio-metadata Version: 0.11.1 Summary: A library for reading and, in the future, writing metadata from audio files. Home-page: https://github.com/thebigmunch/audio-metadata Author: thebigmunch Author-email: mail@thebigmunch.me License: MIT Location: /usr/lib/python3.8/site-packages Requires: bidict, pendulum, tbm-utils, wrapt, attrs, more-itertools, pprintpp, bitstruct Required-by: google-music, google-music-utils, google-music-scripts, google-music-proto

Python version

Python 3.8.2

Exception traceback

Traceback (most recent call last):
  File "/usr/bin/gms", line 8, in <module>
    sys.exit(run())
  File "/usr/lib/python3.8/site-packages/google_music_scripts/cli.py", line 618, in run
    args.func(args)
  File "/usr/lib/python3.8/site-packages/google_music_scripts/commands.py", line 390, in do_upload
    local_songs = get_local_songs(
  File "/usr/lib/python3.8/site-packages/google_music_scripts/core.py", line 186, in get_local_songs
    local_songs = [
  File "/usr/lib/python3.8/site-packages/google_music_scripts/core.py", line 195, in <listcomp>
    if audio_metadata.determine_format(filepath) in [
  File "/usr/lib/python3.8/site-packages/audio_metadata/api.py", line 72, in determine_format
    ID3v2.parse(data)
  File "/usr/lib/python3.8/site-packages/tbm_utils/decorators.py", line 44, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/audio_metadata/formats/id3v2.py", line 416, in parse
    self.tags = ID3v2Frames.parse(
  File "/usr/lib/python3.8/site-packages/tbm_utils/decorators.py", line 44, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/audio_metadata/formats/id3v2.py", line 246, in parse
    frame = ID3v2Frame.parse(data, id3_version, unsync)
  File "/usr/lib/python3.8/site-packages/tbm_utils/decorators.py", line 44, in wrapper
    return wrapped(*args, **kwargs)
  File "/usr/lib/python3.8/site-packages/audio_metadata/formats/id3v2frames.py", line 551, in parse
    return frame_type(
  File "<attrs generated init audio_metadata.formats.id3v2frames.ID3v2TimestampFrame>", line 6, in __init__
  File "/usr/lib/python3.8/site-packages/audio_metadata/formats/id3v2frames.py", line 1423, in _validate_value
    parse_iso8601(v)
  File "/usr/lib/python3.8/site-packages/pendulum/parsing/iso8601.py", line 187, in parse_iso8601
    return datetime.date(year, month, day)
ValueError: year 0 is out of range

Proposed fix

Similar to https://github.com/thebigmunch/google-music-proto/issues/6, ValueError should be gracefully handled.

--- audio_metadata/formats/id3v2frames.py.orig
+++ audio_metadata/formats/id3v2frames.py
@@ -1421,7 +1421,7 @@
                for v in value:
                        try:
                                parse_iso8601(v)
-                       except ParserError:
+                       except (ParserError, ValueError):
                                raise TagError("Timestamp frame values must conform to the ID3v2-compliant subset of ISO 8601.")

        @datareader
thebigmunch commented 3 years ago

Changed the label to enhancement, since it's not technically a bug to error out on invalid input. But audio-metadata should definitely handle this case gracefully as well as ParserError.