mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-03-09 12:50:23 -05:00
playsuisse.py: handle locale parameters from URLs
- Currently, the locale header is statically set to “de”, regardless of which locale is set in the URL parameters. - Therefore, all retrieved metadata (description, names, etc.) were in German. - This PR implements a mechanism that extracts the locale value from the specified URL. - As a fallback, URLs without locale parameters are automatically set to de, which corresponds to the original behavior. Advantages: All metadata is retrieved in the specified language.
This commit is contained in:
parent
0bb3978862
commit
6160d2b6b5
1 changed files with 17 additions and 17 deletions
|
@ -215,26 +215,15 @@ def _perform_login(self, username, password):
|
|||
if not self._ID_TOKEN:
|
||||
raise ExtractorError('Login failed')
|
||||
|
||||
def _get_media_data(self, media_id):
|
||||
# NOTE In the web app, the "locale" header is used to switch between languages,
|
||||
# However this doesn't seem to take effect when passing the header here.
|
||||
response = self._download_json(
|
||||
'https://www.playsuisse.ch/api/graphql',
|
||||
media_id, data=json.dumps({
|
||||
'operationName': 'AssetWatch',
|
||||
'query': self._GRAPHQL_QUERY,
|
||||
'variables': {'assetId': media_id},
|
||||
}).encode(),
|
||||
headers={'Content-Type': 'application/json', 'locale': 'de'})
|
||||
|
||||
return response['data']['assetV2']
|
||||
|
||||
def _real_extract(self, url):
|
||||
if not self._ID_TOKEN:
|
||||
self.raise_login_required(method='password')
|
||||
|
||||
media_id = self._match_id(url)
|
||||
media_data = self._get_media_data(media_id)
|
||||
query = parse_qs(url)
|
||||
locale_param = (query.get('locale') or ['de'])[0].lower()
|
||||
locale = locale_param if locale_param in {'fr', 'en', 'it', 'de', 'rm'} else 'de'
|
||||
media_data = self._get_media_data(media_id, locale)
|
||||
info = self._extract_single(media_data)
|
||||
if media_data.get('episodes'):
|
||||
info.update({
|
||||
|
@ -243,6 +232,17 @@ def _real_extract(self, url):
|
|||
})
|
||||
return info
|
||||
|
||||
def _get_media_data(self, media_id, locale):
|
||||
response = self._download_json(
|
||||
'https://www.playsuisse.ch/api/graphql',
|
||||
media_id, data=json.dumps({
|
||||
'operationName': 'AssetWatch',
|
||||
'query': self._GRAPHQL_QUERY,
|
||||
'variables': {'assetId': media_id},
|
||||
}).encode(),
|
||||
headers={'Content-Type': 'application/json', 'locale': locale})
|
||||
return response['data']['assetV2']
|
||||
|
||||
def _extract_single(self, media_data):
|
||||
thumbnails = traverse_obj(media_data, lambda k, _: k.startswith('thumbnail'))
|
||||
|
||||
|
|
Loading…
Reference in a new issue