curds: Add exception handling for invalid tracks

Users might have images or ripping logs mixed in with their tracks, so
let's make sure we don't crash if we try to scan one of these.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-03-20 10:12:02 -04:00
parent 72a947621c
commit 754a8beadd
4 changed files with 11 additions and 1 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
*.ogg
*.coverage
*.ui~
*.txt

View File

@ -74,7 +74,10 @@ class Track(Tag):
self.tracknumber, self.discnumber))
def lookup(path):
return Tag.lookup(Track(path), "new-track")
try:
return Tag.lookup(Track(path), "new-track")
except Exception as e:
return None
def save():

View File

@ -62,6 +62,10 @@ class TestTrackTag(unittest.TestCase):
self.assertEqual(tags.Track(join(test_tracks, "09 - Test {Disc 02}.ogg")).discnumber, 2)
self.assertEqual(tags.Track(join(test_tracks, "10 - Test {Disc 20}.ogg")).discnumber, 20)
def test_track_exceptiddon(self):
self.assertIsNone(tags.Track.lookup(os.path.join(test_tracks, "text.txt")))
self.assertIsNone(tags.Track.lookup(os.path.join(test_tracks, "test.txt")))
def on_new_track(self, track):
self.cb_track = track

View File

@ -50,6 +50,8 @@ generate_track(60, "Test Album/11 - Test Track 11.ogg", { "Title" : "Test Track
"album" : "Test Album 11",
"discnumber" : "1/1",
"tracknumber" : "11/100" })
with open(os.path.join(trier, "Test Album/text.txt"), 'w') as f:
f.write("Test Text")
# Create a giant library for testing
for artistno in range(1, 26):