Compare commits

...

5 Commits

Author SHA1 Message Date
Mozi
6c25ca9d0e [brilliantpala] flake8 2023-09-23 20:11:58 +08:00
Mozi
575b699c2d [brilliantpala] simplify "_html_search_regex" call
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
2023-09-23 20:00:32 +08:00
Mozi
ce192082c7 [brilliantpala] find formats simply and safely
Q: Why does "hls_aes" work outside of "formats"?
A: The downloader receives the "format" combined with "info_dict". See https://github.com/yt-dlp/yt-dlp/blob/2023.07.06/yt_dlp/YoutubeDL.py#L2880-L2882 .

"live_status = None" does not hurt for VoD.

Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
2023-09-23 17:45:15 +08:00
Mozi
76e12336f5 [brilliantpala] get url by URL handle instead of "og:url"; make regex robust
https://ogp.me/ said:
    og:url - The canonical URL of your object that will be used as its permanent ID in the graph

canonical != real

Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
2023-09-23 15:56:50 +08:00
Mozi
06c3d1d44e [brilliantpala] simplify class var
Co-authored-by: bashonly <88596187+bashonly@users.noreply.github.com>
2023-09-23 15:55:46 +08:00

View File

@ -3,7 +3,6 @@ import hashlib
from .common import InfoExtractor
from ..utils import (
ExtractorError,
dict_get,
traverse_obj,
urlencode_postdata,
)
@ -20,11 +19,12 @@ class BrilliantpalaIE(InfoExtractor):
self._CONTENT_API = f'{self._HOMEPAGE}/api/v2.4/contents/{{content_id}}/'
self._HLS_AES_URI = f'{self._HOMEPAGE}/api/v2.5/video_contents/{{content_id}}/key/'
def _get_logged_in_username(self, webpage):
if self._LOGIN_API == self._og_search_property('url', webpage):
def _get_logged_in_username(self, url, video_id):
webpage, urlh = self._download_webpage_handle(url, video_id)
if self._LOGIN_API == urlh.url:
self.raise_login_required()
return self._html_search_regex(
r'"username":\s*"(?P<username>[^"]+)"', webpage, 'stream page info', 'username')
r'"username"\s*:\s*"(?P<username>[^"]+)"', webpage, 'stream page info', 'username')
def _perform_login(self, username, password):
login_form = self._hidden_inputs(self._download_webpage(
@ -40,13 +40,11 @@ class BrilliantpalaIE(InfoExtractor):
data=urlencode_postdata(login_form))
if self._html_search_regex(
r'(?P<warning>Your username / email and password)', logged_page,
'authentication failure warning', group='warning', fatal=False, default=''):
r'(Your username / email and password)', logged_page, 'auth fail', default=None):
raise ExtractorError('wrong username or password', expected=True)
if self._html_search_regex(
r'(?P<button_text>Logout Other Devices)', logged_page, 'logout device button',
group='button_text', fatal=False, default=''):
r'(Logout Other Devices)', logged_page, 'logout devices button', default=None):
logout_device_form = self._hidden_inputs(logged_page)
self._download_webpage(
self._LOGOUT_DEVICES_API, None, headers={'Referer': self._LOGIN_API},
@ -56,28 +54,25 @@ class BrilliantpalaIE(InfoExtractor):
course_id, content_id = self._match_valid_url(url).group('course_id', 'content_id')
video_id = f'{course_id}-{content_id}'
username = self._get_logged_in_username(self._download_webpage(url, video_id))
username = self._get_logged_in_username(url, video_id)
content_json = self._download_json(
self._CONTENT_API.format(content_id=content_id), video_id,
note='Fetching content info', errnote='Unable to fetch content info')
entries = []
for stream in traverse_obj(content_json, ('video', 'streams')):
formats = self._extract_m3u8_formats(
m3u8_url=stream['url'], video_id=video_id)
for format in formats:
format['hls_aes'] = {
'uri': self._HLS_AES_URI.format(content_id=content_id)}
entry = {
for stream in traverse_obj(content_json, ('video', 'streams', lambda _, v: v['id'] and v['url'])):
formats = self._extract_m3u8_formats(stream['url'], video_id, fatal=False)
if not formats:
continue
entries.append({
'id': str(stream['id']),
'title': dict_get(content_json, 'title', ''),
'title': content_json.get('title'),
'formats': formats,
'hls_aes': {'uri': self._HLS_AES_URI.format(content_id=content_id)},
'http_headers': {'X-Key': hashlib.sha256(username.encode('ascii')).hexdigest()},
'thumbnail': content_json.get('cover_image'),
'live_status': 'not_live',
}
entries.append(entry)
})
return self.playlist_result(
entries, playlist_id=video_id, playlist_title=content_json.get('title'))
@ -104,11 +99,7 @@ class BrilliantpalaElearnIE(BrilliantpalaIE):
},
}]
_SUBDOMIAN = 'elearn'
def _initialize_pre_login(self):
self._DOMAIN = super()._DOMAIN.format(subdomain=self._SUBDOMIAN)
super()._initialize_pre_login()
_DOMAIN = BrilliantpalaIE._DOMAIN.format(subdomain='elearn')
class BrilliantpalaClassesIE(BrilliantpalaIE):
@ -132,8 +123,4 @@ class BrilliantpalaClassesIE(BrilliantpalaIE):
},
}]
_SUBDOMIAN = 'classes'
def _initialize_pre_login(self):
self._DOMAIN = super()._DOMAIN.format(subdomain=self._SUBDOMIAN)
super()._initialize_pre_login()
_DOMAIN = BrilliantpalaIE._DOMAIN.format(subdomain='classes')