From d69a1be537610d15ff7d1fc6f1a38f83d0264da6 Mon Sep 17 00:00:00 2001
From: grqx_wsl <173253225+grqx@users.noreply.github.com>
Date: Mon, 4 Nov 2024 23:17:26 +1300
Subject: [PATCH] _urljoin(): let url_or_none sanitize the url; more
classmethods
---
yt_dlp/extractor/boomplay.py | 43 ++++++++++++++++++------------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/yt_dlp/extractor/boomplay.py b/yt_dlp/extractor/boomplay.py
index f19a77aa4..0bc7a2864 100644
--- a/yt_dlp/extractor/boomplay.py
+++ b/yt_dlp/extractor/boomplay.py
@@ -67,34 +67,34 @@ def _get_element_by_class_and_tag(cls, class_, tag, html):
@classmethod
def _urljoin(cls, path):
- if not hasattr(path, 'startswith') or path.startswith('javascript:'):
- return None
return url_or_none(urljoin(base=cls._BASE, path=path))
- def _get_playurl(self, item_id, item_type):
- resp = self._download_json(
+ @classmethod
+ def _get_playurl(cls, item_id, item_type):
+ resp = cls._download_json(
'https://www.boomplay.com/getResourceAddr', item_id,
note='Downloading play URL', errnote='Failed to download play URL',
data=urlencode_postdata({
'param': base64.b64encode(aes_cbc_encrypt_bytes(json.dumps({
'itemID': item_id,
'itemType': item_type,
- }).encode(), self._KEY, self._IV)).decode(),
+ }).encode(), cls._KEY, cls._IV)).decode(),
}), headers={
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
})
if not (source := resp.get('source')) and (code := resp.get('code')):
if 'unavailable in your country' in (desc := resp.get('desc')) or '':
# since NG must have failed ...
- self.raise_geo_restricted(countries=['GH', 'KE', 'TZ', 'CM', 'CI'])
+ cls.raise_geo_restricted(countries=['GH', 'KE', 'TZ', 'CM', 'CI'])
else:
raise ExtractorError(desc or f'Failed to get play url, code: {code}')
return unpad_pkcs7(aes_cbc_decrypt_bytes(
base64.b64decode(source),
- self._KEY, self._IV)).decode()
+ cls._KEY, cls._IV)).decode()
- def _extract_formats(self, item_id, item_type='MUSIC', **kwargs):
- if url := url_or_none(self._get_playurl(item_id, item_type)):
+ @classmethod
+ def _extract_formats(cls, item_id, item_type='MUSIC', **kwargs):
+ if url := url_or_none(cls._get_playurl(item_id, item_type)):
return [{
'format_id': '0',
'url': url,
@@ -106,29 +106,30 @@ def _extract_formats(self, item_id, item_type='MUSIC', **kwargs):
**kwargs,
}]
else:
- self.raise_no_formats('No formats found')
+ cls.raise_no_formats('No formats found')
- def _extract_page_metadata(self, webpage, item_id):
- metadata_div = self._get_element_by_class_and_tag('summary', 'div', webpage) or ''
+ @classmethod
+ def _extract_page_metadata(cls, webpage, item_id):
+ metadata_div = cls._get_element_by_class_and_tag('summary', 'div', webpage) or ''
metadata_entries = re.findall(r'(?si)(?P