mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-20 13:57:25 +01:00
[PromoDJ] Some refactoring
This commit is contained in:
parent
13f116fce6
commit
a634e7c5d1
@ -74,8 +74,7 @@ def _set_url_page(self, url, page):
|
|||||||
def _fetch_page(self, url, allowed_media_cats, playlist_id, page):
|
def _fetch_page(self, url, allowed_media_cats, playlist_id, page):
|
||||||
page_url = self._set_url_page(url, page + 1)
|
page_url = self._set_url_page(url, page + 1)
|
||||||
html = self._download_webpage(page_url, f'{playlist_id}-page-{page + 1}')
|
html = self._download_webpage(page_url, f'{playlist_id}-page-{page + 1}')
|
||||||
current_page = int(clean_html(get_element_by_class('NavigatorCurrentPage', html)) or '1')
|
if self._get_current_page(html) != page + 1:
|
||||||
if current_page != page + 1:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for a in get_elements_html_by_class('player_standard_tool__play', html):
|
for a in get_elements_html_by_class('player_standard_tool__play', html):
|
||||||
@ -115,6 +114,9 @@ def _get_playlist_page_size(self, url):
|
|||||||
is_default_playlist = '/groups/' not in url
|
is_default_playlist = '/groups/' not in url
|
||||||
return 30 if is_default_playlist else 20
|
return 30 if is_default_playlist else 20
|
||||||
|
|
||||||
|
def _get_current_page(self, html):
|
||||||
|
return int(clean_html(get_element_by_class('NavigatorCurrentPage', html)) or '1')
|
||||||
|
|
||||||
def _fetch_media_data(self, ids, video_id):
|
def _fetch_media_data(self, ids, video_id):
|
||||||
data = {}
|
data = {}
|
||||||
for i, id in enumerate(ids):
|
for i, id in enumerate(ids):
|
||||||
@ -232,11 +234,10 @@ def _parse_pages(self, url, playlist_id):
|
|||||||
for page_url, page_title in re.findall(r'<a href=\"([^\"]+)\">([^<]+)</a>', content_html):
|
for page_url, page_title in re.findall(r'<a href=\"([^\"]+)\">([^<]+)</a>', content_html):
|
||||||
yield self.url_result(page_url, PromoDJUserPageIE, video_title=page_title)
|
yield self.url_result(page_url, PromoDJUserPageIE, video_title=page_title)
|
||||||
|
|
||||||
def _fetch_blog_page(self, url, playlist_id, page):
|
def _fetch_blogs_page(self, url, playlist_id, page):
|
||||||
page_url = self._set_url_page(url, page + 1)
|
page_url = self._set_url_page(url, page + 1)
|
||||||
html = self._download_webpage(page_url, f'{playlist_id}-page-{page + 1}')
|
html = self._download_webpage(page_url, f'{playlist_id}-page-{page + 1}')
|
||||||
current_page = int(clean_html(get_element_by_class('NavigatorCurrentPage', html)) or '1')
|
if self._get_current_page(html) != page + 1:
|
||||||
if current_page != page + 1:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
for a in get_elements_html_by_class('post_title_moderated', html):
|
for a in get_elements_html_by_class('post_title_moderated', html):
|
||||||
@ -250,7 +251,7 @@ def _real_extract(self, url):
|
|||||||
entries = self._parse_pages(url, playlist_id)
|
entries = self._parse_pages(url, playlist_id)
|
||||||
elif type == 'blog':
|
elif type == 'blog':
|
||||||
entries = OnDemandPagedList(
|
entries = OnDemandPagedList(
|
||||||
functools.partial(self._fetch_blog_page, url, playlist_id),
|
functools.partial(self._fetch_blogs_page, url, playlist_id),
|
||||||
self._PAGE_SIZE)
|
self._PAGE_SIZE)
|
||||||
return self.playlist_result(entries, playlist_id)
|
return self.playlist_result(entries, playlist_id)
|
||||||
|
|
||||||
@ -472,14 +473,7 @@ def _parse_media(self, html, id, type):
|
|||||||
has_formats = len(formats_from_html) != 0
|
has_formats = len(formats_from_html) != 0
|
||||||
is_paid = re.search(self._IS_PAID_RE, meta_html)
|
is_paid = re.search(self._IS_PAID_RE, meta_html)
|
||||||
|
|
||||||
if not has_formats and is_paid:
|
if not has_formats and type == 'videos':
|
||||||
media_data_raw = self._search_regex(self._MUSIC_DATA_REGEX, html, 'media data')
|
|
||||||
media_data = self._parse_json(media_data_raw, id)
|
|
||||||
formats = [{
|
|
||||||
'url': source.get('URL'),
|
|
||||||
'size': int_or_none(source.get('size')),
|
|
||||||
} for source in traverse_obj(media_data, ('sources')) if url_or_none(source.get('URL'))]
|
|
||||||
elif not has_formats and type == 'videos':
|
|
||||||
media_data_raw = self._search_regex(self._VIDEO_DATA_REGEX, html, 'media data')
|
media_data_raw = self._search_regex(self._VIDEO_DATA_REGEX, html, 'media data')
|
||||||
media_data = self._parse_json(media_data_raw, id)
|
media_data = self._parse_json(media_data_raw, id)
|
||||||
video_config = self._parse_json(media_data['config'], id)
|
video_config = self._parse_json(media_data['config'], id)
|
||||||
@ -487,6 +481,13 @@ def _parse_media(self, html, id, type):
|
|||||||
formats = [{
|
formats = [{
|
||||||
'url': traverse_obj(video, ('play', '@url', {url_or_none})),
|
'url': traverse_obj(video, ('play', '@url', {url_or_none})),
|
||||||
}]
|
}]
|
||||||
|
elif not has_formats or is_paid:
|
||||||
|
media_data_raw = self._search_regex(self._MUSIC_DATA_REGEX, html, 'media data')
|
||||||
|
media_data = self._parse_json(media_data_raw, id)
|
||||||
|
formats = [{
|
||||||
|
'url': source.get('URL'),
|
||||||
|
'size': int_or_none(source.get('size')),
|
||||||
|
} for source in traverse_obj(media_data, ('sources')) if url_or_none(source.get('URL'))]
|
||||||
else:
|
else:
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': url,
|
'url': url,
|
||||||
@ -558,13 +559,10 @@ class PromoDJShortIE(PromoDJBaseIE):
|
|||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
_PAGE_URL_REGEX = r'<meta property="og:url"\s*content="(?P<url>[^"]+)"'
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
id = self._match_id(url)
|
id = self._match_id(url)
|
||||||
html = self._download_webpage(url, id)
|
html = self._download_webpage(url, id)
|
||||||
url = re.findall(self._PAGE_URL_REGEX, html)[0]
|
return self.url_result(self._og_search_url(html), PromoDJIE, id)
|
||||||
return self.url_result(url, PromoDJIE, id)
|
|
||||||
|
|
||||||
|
|
||||||
class PromoDJRadioIE(PromoDJBaseIE):
|
class PromoDJRadioIE(PromoDJBaseIE):
|
||||||
|
Loading…
Reference in New Issue
Block a user