Advertise preferred language to Spotify (#544)

Some artist or track provide different translation for different language
usage. This requires send http request with Accept-Language in header.
Create this option for people who wants to see proper translation.
This commit is contained in:
Yingshiuan Pan authored and GitHub committed 2020-07-23 17:06:28 +01:00
1 parent c425102659
commit bb4c98033f
2 files changed
+9

No files matched your search

+8
View File
@@ -109,6 +109,7 @@ class Spotify(object):
retries=max_retries,
status_retries=max_retries,
backoff_factor=0.3,
language=None,
):
"""
Creates a Spotify API client.
@@ -141,6 +142,9 @@ class Spotify(object):
:param backoff_factor:
A backoff factor to apply between attempts after the second try
See urllib3 https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html
:param language:
The language parameter advertises what language the user prefers to see.
See ISO-639 language code: https://www.loc.gov/standards/iso639-2/php/code_list.php
"""
self.prefix = "https://api.spotify.com/v1/"
self._auth = auth
@@ -153,6 +157,7 @@ class Spotify(object):
self.backoff_factor = backoff_factor
self.retries = retries
self.status_retries = status_retries
self.language = language
if isinstance(requests_session, requests.Session):
self._session = requests_session
@@ -224,6 +229,9 @@ class Spotify(object):
if payload:
args["data"] = json.dumps(payload)
if self.language is not None:
headers["Accept-Language"] = self.language
logger.debug('Sending %s to %s with Headers: %s and Body: %r ',
method, url, headers, args.get('data'))