mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 17:51:24 +01:00
Compare commits
No commits in common. "c59ce7d6a6a5be85b240e177dd60573a0fab1318" and "c58ee488a9a005d6c8e79ad925a1e9afc88b90b7" have entirely different histories.
c59ce7d6a6
...
c58ee488a9
|
@ -69,30 +69,32 @@ class BoomplayBaseIE(InfoExtractor):
|
|||
def _urljoin(cls, path):
|
||||
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,
|
||||
|
@ -104,29 +106,30 @@ class BoomplayBaseIE(InfoExtractor):
|
|||
**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)<strong>(?P<entry>.*?)</strong>', metadata_div) or []
|
||||
description = re.sub(
|
||||
r'(?i)Listen and download music for free on Boomplay!', '',
|
||||
clean_html(self._get_element_by_class_and_tag(
|
||||
clean_html(cls._get_element_by_class_and_tag(
|
||||
'description_content', 'span', webpage)) or '') or None
|
||||
|
||||
details_section = self._get_element_by_class_and_tag('songDetailInfo', 'section', webpage) or ''
|
||||
details_section = cls._get_element_by_class_and_tag('songDetailInfo', 'section', webpage) or ''
|
||||
metadata_entries.extend(re.findall(r'(?si)<li>(?P<entry>.*?)</li>', details_section) or [])
|
||||
page_metadata = {
|
||||
'id': item_id,
|
||||
**self._extract_title_from_webpage(webpage),
|
||||
'thumbnail': self._html_search_meta(['og:image', 'twitter:image'],
|
||||
webpage, 'thumbnail', default=None),
|
||||
'like_count': parse_count(self._get_element_by_class_and_tag('btn_favorite', 'button', metadata_div)),
|
||||
'repost_count': parse_count(self._get_element_by_class_and_tag('btn_share', 'button', metadata_div)),
|
||||
'comment_count': parse_count(self._get_element_by_class_and_tag('btn_comment', 'button', metadata_div)),
|
||||
'duration': parse_duration(self._get_element_by_class_and_tag('btn_duration', 'button', metadata_div)),
|
||||
'title': cls._html_search_regex(r'(?i)<h1[^>]*>([^<]+)</h1>', webpage, 'title', default=None),
|
||||
'thumbnail': cls._html_search_meta(['og:image', 'twitter:image'],
|
||||
webpage, 'thumbnail', default=''),
|
||||
'like_count': parse_count(cls._get_element_by_class_and_tag('btn_favorite', 'button', metadata_div)),
|
||||
'repost_count': parse_count(cls._get_element_by_class_and_tag('btn_share', 'button', metadata_div)),
|
||||
'comment_count': parse_count(cls._get_element_by_class_and_tag('btn_comment', 'button', metadata_div)),
|
||||
'duration': parse_duration(cls._get_element_by_class_and_tag('btn_duration', 'button', metadata_div)),
|
||||
'upload_date': unified_strdate(strip_or_none(
|
||||
self._get_element_by_class_and_tag('btn_pubDate', 'button', metadata_div))),
|
||||
cls._get_element_by_class_and_tag('btn_pubDate', 'button', metadata_div))),
|
||||
'description': description,
|
||||
}
|
||||
for metadata_entry in metadata_entries:
|
||||
|
@ -144,40 +147,6 @@ class BoomplayBaseIE(InfoExtractor):
|
|||
page_metadata['release_year'] = int_or_none(v)
|
||||
return page_metadata
|
||||
|
||||
def _extract_title_from_webpage(self, webpage):
|
||||
if h1_title := self._html_search_regex(r'(?i)<h1[^>]*>([^<]+)</h1>', webpage, 'title', default=None):
|
||||
return {'title': h1_title}
|
||||
else:
|
||||
return self._fix_title(
|
||||
self._html_search_meta(['og:title', 'twitter:title'], webpage, 'title', default=None)
|
||||
or self._html_search_regex(r'(?i)<title[^>]*>([^<]+)</title>', webpage, 'title', default=None))
|
||||
|
||||
@staticmethod
|
||||
def _fix_title(title):
|
||||
"""
|
||||
fix various types of titles(og:title, twitter:title, title tag in html head)
|
||||
"""
|
||||
if not title:
|
||||
return {}
|
||||
|
||||
title_patterns = (
|
||||
r'^(?P<title>(?P<artist>.+)) Songs MP3 Download, New Songs \& Albums \| Boomplay$', # artists
|
||||
r'^(?P<artist>.+?) - (?P<title>.+) MP3\ Download \& Lyrics \| Boomplay$', # music
|
||||
r'^Download (?P<artist>.+) album songs: (?P<title>.+?) \| Boomplay Music$', # album
|
||||
r'^Search:(?P<title>.+) \| Boomplay Music$', # search url
|
||||
r'^(?P<title>.+) \| Podcast \| Boomplay$', # podcast, episode
|
||||
r'^(?P<title>.+) \| Boomplay(?: Music)?$', # video, playlist, generic playlists
|
||||
)
|
||||
|
||||
for pattern in title_patterns:
|
||||
if match := re.search(pattern, title):
|
||||
return {
|
||||
'title': match.group('title'),
|
||||
'artists': [match.group('artist')] if 'artist' in match.groupdict() else None,
|
||||
}
|
||||
|
||||
return {'title': title}
|
||||
|
||||
@classmethod
|
||||
def _extract_from_webpage(cls, url, webpage, **kwargs):
|
||||
if kwargs:
|
||||
|
@ -197,7 +166,7 @@ class BoomplayBaseIE(InfoExtractor):
|
|||
<a
|
||||
(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?
|
||||
(?<=\s)href\s*=\s*(?P<_q>['"])
|
||||
(?P<href>/(?:{media_types})/\d+/?[\-\w=?&#:;@]*)
|
||||
(?!javascript:)(?P<href>/(?:{media_types})/\d+/?[\-\w=?&#:;@]*)
|
||||
(?P=_q)
|
||||
(?:\s(?:[^>"']|"[^"]*"|'[^']*')*)?
|
||||
>''', webpage):
|
||||
|
@ -321,6 +290,7 @@ class BoomplayEpisodeIE(BoomplayBaseIE):
|
|||
webpage = self._download_webpage(url, ep_id)
|
||||
return merge_dicts(
|
||||
self._extract_page_metadata(webpage, ep_id), {
|
||||
'title': self._og_search_title(webpage, default='').rsplit('|', 2)[0].strip() or None,
|
||||
'description': self._html_search_meta(
|
||||
['description', 'og:description', 'twitter:description'], webpage),
|
||||
'formats': self._extract_formats(ep_id, 'EPISODE', vcodec='none'),
|
||||
|
@ -364,6 +334,7 @@ class BoomplayPodcastIE(BoomplayBaseIE):
|
|||
}))
|
||||
return self.playlist_result(
|
||||
song_list, playlist_id,
|
||||
playlist_title=self._og_search_title(webpage, fatal=True).rsplit('|', 2)[0].strip(),
|
||||
**self._extract_page_metadata(webpage, playlist_id))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user