mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 17:16:07 +01:00
Use _safe_cast to avoid dying on illegal dates.
This commit is contained in:
parent
03fa8d809b
commit
e290f8dfad
12 changed files with 10 additions and 1 deletions
|
|
@ -1016,11 +1016,15 @@ class DateField(MediaField):
|
||||||
datestring = MediaField.__get__(self, mediafile, None)
|
datestring = MediaField.__get__(self, mediafile, None)
|
||||||
datestring = re.sub(r'[Tt ].*$', '', unicode(datestring))
|
datestring = re.sub(r'[Tt ].*$', '', unicode(datestring))
|
||||||
items = unicode(datestring).split('-')
|
items = unicode(datestring).split('-')
|
||||||
|
# A date with more than 3 components is not a date we understand. In
|
||||||
|
# that case, act like we saw no date components.
|
||||||
|
if len(items) > 3:
|
||||||
|
items = []
|
||||||
items = items + [None] * (3 - len(items))
|
items = items + [None] * (3 - len(items))
|
||||||
if not items[0] and hasattr(self, '_year_field'):
|
if not items[0] and hasattr(self, '_year_field'):
|
||||||
# Fallback to addition year field
|
# Fallback to addition year field
|
||||||
items[0] = self._year_field.__get__(mediafile)
|
items[0] = self._year_field.__get__(mediafile)
|
||||||
return [int(item or 0) for item in items]
|
return [_safe_cast(int, item) for item in items]
|
||||||
|
|
||||||
def _set_date_tuple(self, mediafile, year, month=None, day=None):
|
def _set_date_tuple(self, mediafile, year, month=None, day=None):
|
||||||
date = [year or 0]
|
date = [year or 0]
|
||||||
|
|
|
||||||
BIN
test/rsrc/unparseable.alac.m4a
Normal file
BIN
test/rsrc/unparseable.alac.m4a
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.ape
Normal file
BIN
test/rsrc/unparseable.ape
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.flac
Normal file
BIN
test/rsrc/unparseable.flac
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.m4a
Normal file
BIN
test/rsrc/unparseable.m4a
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.mp3
Normal file
BIN
test/rsrc/unparseable.mp3
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.mpc
Normal file
BIN
test/rsrc/unparseable.mpc
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.ogg
Normal file
BIN
test/rsrc/unparseable.ogg
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.opus
Normal file
BIN
test/rsrc/unparseable.opus
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.wma
Normal file
BIN
test/rsrc/unparseable.wma
Normal file
Binary file not shown.
BIN
test/rsrc/unparseable.wv
Normal file
BIN
test/rsrc/unparseable.wv
Normal file
Binary file not shown.
|
|
@ -467,6 +467,11 @@ class ReadWriteTestBase(ArtTestMixin, GenreListTestMixin):
|
||||||
self.assertEqual(mediafile.disc, 10)
|
self.assertEqual(mediafile.disc, 10)
|
||||||
self.assertEqual(mediafile.disctotal, 0)
|
self.assertEqual(mediafile.disctotal, 0)
|
||||||
|
|
||||||
|
def test_unparseable_date(self):
|
||||||
|
mediafile = self._mediafile_fixture('unparseable')
|
||||||
|
|
||||||
|
self.assertEqual(mediafile.year, 0)
|
||||||
|
self.assertEqual(mediafile.date, datetime.date.min)
|
||||||
|
|
||||||
def assertTags(self, mediafile, tags):
|
def assertTags(self, mediafile, tags):
|
||||||
__unittest = True
|
__unittest = True
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue