aboutsummaryrefslogtreecommitdiff
path: root/yt_dlp/extractor/monstercat.py
diff options
context:
space:
mode:
Diffstat (limited to 'yt_dlp/extractor/monstercat.py')
-rw-r--r--yt_dlp/extractor/monstercat.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/yt_dlp/extractor/monstercat.py b/yt_dlp/extractor/monstercat.py
index 930c13e27..f17b91f5a 100644
--- a/yt_dlp/extractor/monstercat.py
+++ b/yt_dlp/extractor/monstercat.py
@@ -4,15 +4,11 @@ from .common import InfoExtractor
from ..utils import (
clean_html,
extract_attributes,
- get_element_by_class,
- get_element_html_by_class,
- get_element_text_and_html_by_tag,
int_or_none,
strip_or_none,
- traverse_obj,
- try_call,
unified_strdate,
)
+from ..utils.traversal import find_element, traverse_obj
class MonstercatIE(InfoExtractor):
@@ -26,19 +22,21 @@ class MonstercatIE(InfoExtractor):
'thumbnail': 'https://www.monstercat.com/release/742779548009/cover',
'release_date': '20230711',
'album': 'The Secret Language of Trees',
- 'album_artist': 'BT',
+ 'album_artists': ['BT'],
},
}]
def _extract_tracks(self, table, album_meta):
for td in re.findall(r'<tr[^<]*>((?:(?!</tr>)[\w\W])+)', table): # regex by chatgpt due to lack of get_elements_by_tag
- title = clean_html(try_call(
- lambda: get_element_by_class('d-inline-flex flex-column', td).partition(' <span')[0]))
- ids = extract_attributes(try_call(lambda: get_element_html_by_class('btn-play cursor-pointer mr-small', td)) or '')
+ title = traverse_obj(td, (
+ {find_element(cls='d-inline-flex flex-column')},
+ {lambda x: x.partition(' <span')}, 0, {clean_html}))
+ ids = traverse_obj(td, (
+ {find_element(cls='btn-play cursor-pointer mr-small', html=True)}, {extract_attributes})) or {}
track_id = ids.get('data-track-id')
release_id = ids.get('data-release-id')
- track_number = int_or_none(try_call(lambda: get_element_by_class('py-xsmall', td)))
+ track_number = traverse_obj(td, ({find_element(cls='py-xsmall')}, {int_or_none}))
if not track_id or not release_id:
self.report_warning(f'Skipping track {track_number}, ID(s) not found')
self.write_debug(f'release_id={release_id!r} track_id={track_id!r}')
@@ -48,7 +46,7 @@ class MonstercatIE(InfoExtractor):
'title': title,
'track': title,
'track_number': track_number,
- 'artist': clean_html(try_call(lambda: get_element_by_class('d-block fs-xxsmall', td))),
+ 'artists': traverse_obj(td, ({find_element(cls='d-block fs-xxsmall')}, {clean_html}, all)),
'url': f'https://www.monstercat.com/api/release/{release_id}/track-stream/{track_id}',
'id': track_id,
'ext': 'mp3',
@@ -57,20 +55,19 @@ class MonstercatIE(InfoExtractor):
def _real_extract(self, url):
url_id = self._match_id(url)
html = self._download_webpage(url, url_id)
- # wrap all `get_elements` in `try_call`, HTMLParser has problems with site's html
- tracklist_table = try_call(lambda: get_element_by_class('table table-small', html)) or ''
-
- title = try_call(lambda: get_element_text_and_html_by_tag('h1', html)[0])
- date = traverse_obj(html, ({lambda html: get_element_by_class('font-italic mb-medium d-tablet-none d-phone-block',
- html).partition('Released ')}, 2, {strip_or_none}, {unified_strdate}))
+ # NB: HTMLParser may choke on this html; use {find_element} or try_call(lambda: get_element...)
+ tracklist_table = traverse_obj(html, {find_element(cls='table table-small')}) or ''
+ title = traverse_obj(html, ({find_element(tag='h1')}, {clean_html}))
album_meta = {
'title': title,
'album': title,
'thumbnail': f'https://www.monstercat.com/release/{url_id}/cover',
- 'album_artist': try_call(
- lambda: get_element_by_class('h-normal text-uppercase mb-desktop-medium mb-smallish', html)),
- 'release_date': date,
+ 'album_artists': traverse_obj(html, (
+ {find_element(cls='h-normal text-uppercase mb-desktop-medium mb-smallish')}, {clean_html}, all)),
+ 'release_date': traverse_obj(html, (
+ {find_element(cls='font-italic mb-medium d-tablet-none d-phone-block')},
+ {lambda x: x.partition('Released ')}, 2, {strip_or_none}, {unified_strdate})),
}
return self.playlist_result(