mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-10-31 23:02:40 +00:00
Refactoring HotmartIE Extractor for Code Convention Compliance
Implemented code convention compliance throughout the HotmartIE extractor. The adjustments span from syntax and structure to proper usage of utility functions. The changes encompass quote usage, inline value extraction, long lines management, import order, fallbacks collapsing, trailing parentheses placement, and the use of conversion and parsing functions like url_or_none and int_or_none for safer data handling.
This commit is contained in:
parent
19cc97d1a1
commit
7f44d0fa02
1 changed files with 36 additions and 40 deletions
|
@ -2,32 +2,26 @@
|
|||
from ..utils import (
|
||||
get_element_by_id,
|
||||
traverse_obj,
|
||||
int_or_none,
|
||||
url_or_none,
|
||||
)
|
||||
|
||||
|
||||
class HotmartIE(InfoExtractor):
|
||||
_VALID_URL = r"https?://player\.hotmart\.com/embed/(?P<id>[a-zA-Z0-9]+)"
|
||||
_VALID_URL = r'https?://player\.hotmart\.com/embed/(?P<id>[a-zA-Z0-9]+)'
|
||||
_TESTS = [
|
||||
{
|
||||
"url": (
|
||||
"https://player.hotmart.com/embed/DLNy9QQ4qr?signature=cSnA"
|
||||
"r99eUZ0cne-ZMMJdjwwzV5hD4pLXVPO3urVQUF0XoWaG3MqF6jhfPFf7il"
|
||||
"Eh6YdtJeirComlat6kF_ZFQMFf1iW-lmqXfsWdANDVYfh8-lqjKY02_Xxg"
|
||||
"a0nwV3WwrYRkuQ7pnJZiueGkbSHvfixgNGzp12kNDqK1ynPojnVfIaijK2"
|
||||
"NQV9A0oeG7icUW2K-C9KD0phuuhQmt5qS8u7FxRC7buQm5MoSKYGMi_ot2"
|
||||
"FUSe2Mgx_S1TOYYNgi0FiTyUyixn884HouIIz8e_N4ceE8PF7x8mVK_IWH"
|
||||
"gIGic2NhBo9aAo7m8TmP4FA5SNaQnEIPqY1G7SHmDoBvcXyA==&token=a"
|
||||
"a2d356b-e2f0-45e8-9725-e0efc7b5d29c&autoplay=autoplay"
|
||||
'url': (
|
||||
'https://player.hotmart.com/embed/pRQKDWkKLB?signature=S0Pr1OaDwGvKwQ8i6Y9whykEo4uuok2P4AShiYcyarvFkQDT_rBlR5L1qdIbIferFBHfTVJlXcbgUAwMMPiV6sWaA0XIU4OO282MO092DX_Z8KqS1h0Y-452TMjAt3dW2ZYMKWtfA2A2sxM7JmpYZZdMKTrT7nwoPsfbythXfph3dCLzxNQ0gS-rHfD7SYWuKJGN1JmK6iAygJf1thpskoeOJyK04SpDwMoqIOYfsrUktvsJFlV3oWM1tVoeDIQPWSZGXE6WRWDPNmTz6h7IHvc-QKGzoRy3_CvzSEioq2SaDNDdloECrKH37V1eCNvdaIr0dQeHqH_vI0NMBsfCow==&token=aa2d356b-e2f0-45e8-9725-e0efc7b5d29c&autoplay=autoplay'
|
||||
),
|
||||
"md5": "620b25017119475adbd6f7932294129d",
|
||||
"info_dict": {
|
||||
"id": "DLNy9QQ4qr",
|
||||
"video_id": "DLNy9QQ4qr",
|
||||
"ext": "mp4",
|
||||
"title": "Hotmart video #DLNy9QQ4qr",
|
||||
"thumbnail": (
|
||||
r"re:https?://.*\.(?:jpg|jpeg|png|gif)\?token=exp=\d+~acl"
|
||||
r"=.*~hmac=[a-f0-9]+$"
|
||||
'md5': '95d7a252bb97954663fcf6c6db4b4555',
|
||||
'info_dict': {
|
||||
'id': 'pRQKDWkKLB',
|
||||
'video_id': 'pRQKDWkKLB',
|
||||
'ext': 'mp4',
|
||||
'title': 'Hotmart video #pRQKDWkKLB',
|
||||
'thumbnail': (
|
||||
r're:https?://.*\.(?:jpg|jpeg|png|gif)\?token=exp=\d+~acl=.*~hmac=[a-f0-9]+$'
|
||||
),
|
||||
},
|
||||
}
|
||||
|
@ -38,32 +32,34 @@ def _real_extract(self, url):
|
|||
|
||||
webpage = self._download_webpage(url, video_id)
|
||||
|
||||
video_data_string = get_element_by_id("__NEXT_DATA__", webpage)
|
||||
video_data = self._parse_json(video_data_string, video_id)
|
||||
video_data_string = get_element_by_id('__NEXT_DATA__', webpage)
|
||||
video_data = self._parse_json(video_data_string, video_id, fatal=False)
|
||||
|
||||
# Extract the title from the video_data object
|
||||
title = traverse_obj(
|
||||
video_data, ("props", "pageProps", "applicationData", "mediaTitle")
|
||||
title = self._html_search_meta(
|
||||
['og:title', 'title', 'twitter:title'],
|
||||
webpage, 'title', default='Hotmart video #' + video_id
|
||||
)
|
||||
|
||||
url = traverse_obj(
|
||||
video_data,
|
||||
(
|
||||
"props",
|
||||
"pageProps",
|
||||
"applicationData",
|
||||
"mediaAssets",
|
||||
'props',
|
||||
'pageProps',
|
||||
'applicationData',
|
||||
'mediaAssets',
|
||||
0,
|
||||
"urlEncrypted",
|
||||
'urlEncrypted',
|
||||
),
|
||||
expected_type=url_or_none,
|
||||
)
|
||||
thumbnail_url = traverse_obj(
|
||||
video_data,
|
||||
("props", "pageProps", "applicationData", "thumbnailUrl"),
|
||||
('props', 'pageProps', 'applicationData', 'thumbnailUrl'),
|
||||
expected_type=url_or_none,
|
||||
)
|
||||
|
||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||
url, video_id, "mp4"
|
||||
url, video_id, 'mp4', fatal=False
|
||||
)
|
||||
|
||||
description = self._og_search_description(webpage, default=None)
|
||||
|
@ -71,13 +67,13 @@ def _real_extract(self, url):
|
|||
chapter_number = None
|
||||
|
||||
return {
|
||||
"id": video_id,
|
||||
"video_id": video_id,
|
||||
"thumbnail": thumbnail_url,
|
||||
"formats": formats,
|
||||
"subtitles": subtitles,
|
||||
"title": title,
|
||||
"description": description,
|
||||
"chapter": chapter,
|
||||
"chapter_number": chapter_number,
|
||||
'id': video_id,
|
||||
'video_id': video_id,
|
||||
'thumbnail': thumbnail_url,
|
||||
'formats': formats,
|
||||
'subtitles': subtitles,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'chapter': chapter,
|
||||
'chapter_number': int_or_none(chapter_number),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue