From a1bc3617a45dbbd83cf6330f3d3a90ba1d720673 Mon Sep 17 00:00:00 2001 From: Bas Stottelaar Date: Sun, 14 Sep 2014 14:03:56 +0200 Subject: [PATCH] More logging + proper exception catching. --- headphones/librarysync.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/headphones/librarysync.py b/headphones/librarysync.py index 0fdd98c8..49a147cc 100644 --- a/headphones/librarysync.py +++ b/headphones/librarysync.py @@ -15,10 +15,10 @@ import os import glob - -from beets.mediafile import MediaFile - import headphones + +from beets.mediafile import MediaFile, FileTypeError, UnreadableFileError + from headphones import db, logger, helpers, importer, lastfm # You can scan a single directory and append it to the current library by specifying append=True, ArtistID & ArtistName @@ -84,8 +84,8 @@ def libraryScan(dir=None, append=False, ArtistID=None, ArtistName=None, cron=Fal for directory in d[:]: if directory.startswith("."): d.remove(directory) - for files in f: + for files in f: # MEDIA_FORMATS = music file extensions, e.g. mp3, flac, etc if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS): @@ -104,9 +104,8 @@ def libraryScan(dir=None, append=False, ArtistID=None, ArtistName=None, cron=Fal # Try to read the metadata try: f = MediaFile(song) - - except: - logger.error('Cannot read file: ' + unicode_song_path) + except (FileTypeError, UnreadableFileError): + logger.error("Cannot read file media file '%s'. It may be corrupted or not a media file.", unicode_song_path) continue # Grab the bitrates for the auto detect bit rate option