Skip to content

Commit

Permalink
lyrics: Set User-Agent header (fix #2357)
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Dec 30, 2016
1 parent 87266be commit 8bb24e3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions beetsplug/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class HTMLParseError(Exception):

from beets import plugins
from beets import ui
import beets


DIV_RE = re.compile(r'<(/?)div>?', re.I)
Expand All @@ -71,6 +72,7 @@ class HTMLParseError(Exception):
u'\u2016': u'-',
u'\u2026': u'...',
}
USER_AGENT = 'beets/{}'.format(beets.__version__)


# Utilities.
Expand Down Expand Up @@ -210,7 +212,9 @@ def fetch_url(self, url):
# We're not overly worried about the NSA MITMing our lyrics scraper
with warnings.catch_warnings():
warnings.simplefilter('ignore')
r = requests.get(url, verify=False)
r = requests.get(url, verify=False, headers={
'User-Agent': USER_AGENT,
})
except requests.RequestException as exc:
self._log.debug(u'lyrics request failed: {0}', exc)
return
Expand Down Expand Up @@ -263,7 +267,10 @@ class Genius(Backend):
def __init__(self, config, log):
super(Genius, self).__init__(config, log)
self.api_key = config['genius_api_key'].as_str()
self.headers = {'Authorization': "Bearer %s" % self.api_key}
self.headers = {
'Authorization': "Bearer %s" % self.api_key,
'User-Agent': USER_AGENT,
}

def search_genius(self, artist, title):
query = u"%s %s" % (artist, title)
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Fixes:
* :doc:`/plugins/discogs`: Fix a crash when a release did not contain Format
information, and increased robustness when other fields are missing.
:bug:`2302`
* :doc:`/plugins/lyrics`: The plugin now reports a beets-specific User-Agent
header when requesting lyrics. :bug:`2357`

For plugin developers: new importer prompt choices (see :ref:`append_prompt_choices`), you can now provide new candidates for the user to consider.

Expand Down

0 comments on commit 8bb24e3

Please sign in to comment.