diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py
index f23f41f11..6056ba83c 100644
--- a/beetsplug/lyrics.py
+++ b/beetsplug/lyrics.py
@@ -23,6 +23,11 @@ from beets import ui
from beets.ui import commands
+# Global logger.
+
+log = logging.getLogger('beets')
+
+
# Lyrics scrapers.
COMMENT_RE = re.compile(r'', re.S)
@@ -30,6 +35,16 @@ DIV_RE = re.compile(r'<(/?)div>?')
TAG_RE = re.compile(r'<[^>]*>')
BREAK_RE = re.compile(r'
')
+def fetch_url(url):
+ """Retrieve the content at a given URL, or return None if the source
+ is unreachable.
+ """
+ try:
+ return urllib.urlopen(url).read()
+ except IOError as exc:
+ log.debug('failed to fetch: {} ({})'.format(url, str(exc)))
+ return None
+
def unescape(text):
"""Resolves xx; HTML entities (and some others)."""
out = text.replace(' ', ' ')
@@ -97,7 +112,9 @@ def _lw_encode(s):
def fetch_lyricswiki(artist, title):
"""Fetch lyrics from LyricsWiki."""
url = LYRICSWIKI_URL_PATTERN % (_lw_encode(artist), _lw_encode(title))
- html = urllib.urlopen(url).read()
+ html = fetch_url(url)
+ if not html:
+ return
lyrics = extract_text(html, "