thedonvaughn / cover_grabber

Recursively traverse directory containing media files (MP3, ogg, FLAC) and download album cover art
https://sourceforge.net/projects/covergrabber/
GNU General Public License v3.0
17 stars 8 forks source link

:ERROR - SOMETHING VERY BAD HAPPENED on every run #7

Open Bujiraso opened 5 years ago

Bujiraso commented 5 years ago

The real bug here is that I don't have much to go on for debugging or troubleshooting.

Bonus feature requesting a "--verbose" switch here, too, which could be a good thing to have as well as a better error message.

$ covergrabber Nightwish/
2019-06-01 07:48:39,738: cover_grabber :INFO - Scanning Nightwish/
2019-06-01 07:48:39,767: cover_grabber :INFO - LastFM: Searching for "Nightwish - Once"
2019-06-01 07:48:40,211: cover_grabber :ERROR - SOMETHING VERY BAD HAPPENED during processing of "Nightwish - Once"
$ covergrabber Silverchair/
2019-06-01 07:48:59,096: cover_grabber :INFO - Scanning Silverchair/
2019-06-01 07:48:59,098: cover_grabber :INFO - LastFM: Searching for "Silverchair - Frogstomp"
2019-06-01 07:48:59,549: cover_grabber :ERROR - SOMETHING VERY BAD HAPPENED during processing of "Silverchair - Frogstomp"
gligneul commented 5 years ago

This patch solves the issue:

diff --git a/cover_grabber/downloader/lastfm_downloader.py b/cover_grabber/downloader/lastfm_downloader.py
index fec1433..dbae57f 100644
--- a/cover_grabber/downloader/lastfm_downloader.py
+++ b/cover_grabber/downloader/lastfm_downloader.py
@@ -14,10 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

 import urllib
-try:
-    import xml.etree.cElementTree as ETree
-except:
-    import xml.etree.ElementTree as ETree
+from lxml import etree as ETree

 from cover_grabber.logging.config import logger

@@ -42,7 +39,8 @@ class LastFMDownloader(object):

         logger.info(u'LastFM: Searching for "{artist_name} - {album_name}"'.format(artist_name=self.artist_name, album_name=self.album_name))
         response = urllib.urlopen(self.url).read() # Send HTTP request to LastFM
-        xml_data = ETree.fromstring(response) # Read in XML data
+        parser = ETree.XMLParser(recover=True)
+        xml_data = ETree.fromstring(response, parser) # Read in XML data

         for element in xml_data.getiterator("album"):
             if (element.find('artist').text.lower() == self.artist_name.lower().encode("utf-8")):

You also need to install lxml with pip.