From d6393856912ef66b48306dc7d6f61f1514e6fbc7 Mon Sep 17 00:00:00 2001 From: codezjx Date: Tue, 8 Aug 2017 01:10:06 +0800 Subject: [PATCH] Handle the "HeaderNotFoundError" exception when add metadata to song file. --- ncm/file_util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ncm/file_util.py b/ncm/file_util.py index 544bb0a..d32283a 100644 --- a/ncm/file_util.py +++ b/ncm/file_util.py @@ -1,12 +1,17 @@ # -*- coding: utf-8 -*- -from mutagen.mp3 import MP3 +from mutagen.mp3 import MP3, HeaderNotFoundError from mutagen.id3 import ID3, APIC, TPE1, TIT2, TALB, error def add_metadata_to_song(file_path, cover_path, song): # If no ID3 tags in mp3 file - audio = MP3(file_path, ID3=ID3) + try: + audio = MP3(file_path, ID3=ID3) + except HeaderNotFoundError: + print('Can\'t sync to MPEG frame, not an validate MP3 file!') + return + if audio.tags is None: print('No ID3 tag, trying to add one!') try: