]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/alura.py
3 from .common
import InfoExtractor
18 class AluraIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:cursos\.)?alura\.com\.br/course/(?P<course_name>[^/]+)/task/(?P<id>\d+)'
20 _LOGIN_URL
= 'https://cursos.alura.com.br/loginForm?urlAfterLogin=/loginForm'
21 _VIDEO_URL
= 'https://cursos.alura.com.br/course/%s/task/%s/video'
22 _NETRC_MACHINE
= 'alura'
24 'url': 'https://cursos.alura.com.br/course/clojure-mutabilidade-com-atoms-e-refs/task/60095',
28 'title': 'ReferĂȘncias, ref-set e alter'
30 'skip': 'Requires alura account credentials'},
33 'url': 'https://cursos.alura.com.br/course/clojure-mutabilidade-com-atoms-e-refs/task/60098',
34 'only_matching': True},
36 'url': 'https://cursos.alura.com.br/course/fundamentos-market-digital/task/55219',
37 'only_matching': True}
40 def _real_extract(self
, url
):
42 course
, video_id
= self
._match
_valid
_url
(url
)
43 video_url
= self
._VIDEO
_URL
% (course
, video_id
)
45 video_dict
= self
._download
_json
(video_url
, video_id
, 'Searching for videos')
48 webpage
= self
._download
_webpage
(url
, video_id
)
49 video_title
= clean_html(self
._search
_regex
(
50 r
'<span[^>]+class=(["\'])task
-body
-header
-title
-text\
1[^
>]*>(?P
<title
>[^
<]+)',
51 webpage, 'title
', group='title
'))
54 for video_obj in video_dict:
55 video_url_m3u8 = video_obj.get('link
')
56 video_format = self._extract_m3u8_formats(
57 video_url_m3u8, None, 'mp4
', entry_protocol='m3u8_native
',
58 m3u8_id='hls
', fatal=False)
59 for f in video_format:
60 m = re.search(r'^
[\w \W
]*-(?P
<res
>\w
*).mp4
[\W \w
]*', f['url
'])
62 if not f.get('height
'):
63 f['height
'] = int('720' if m.group('res
') == 'hd
' else '480')
64 formats.extend(video_format)
66 self._sort_formats(formats)
74 def _perform_login(self, username, password):
76 login_page = self._download_webpage(
77 self._LOGIN_URL, None, 'Downloading login popup
')
79 def is_logged(webpage):
80 return any(re.search(p, webpage) for p in (
81 r'href
=[\"|
\']?
/signout
[\"|
\']',
85 if is_logged(login_page):
88 login_form = self._hidden_inputs(login_page)
95 post_url = self._search_regex(
96 r'<form
[^
>]+class=["|\']signin-form["|
\'] action
=["|\'](?P<url>.+?)["|
\']', login_page,
97 'post url
', default=self._LOGIN_URL, group='url
')
99 if not post_url.startswith('http
'):
100 post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
102 response = self._download_webpage(
103 post_url, None, 'Logging
in',
104 data=urlencode_postdata(login_form),
105 headers={'Content-Type': 'application/x-www-form-urlencoded'})
107 if not is_logged(response):
108 error = self._html_search_regex(
109 r'(?s
)<p
[^
>]+class="alert-message[^"]*">(.+?)</p>',
110 response, 'error message', default=None)
112 raise ExtractorError('Unable to login: %s' % error, expected=True)
113 raise ExtractorError('Unable to log in')
116 class AluraCourseIE(AluraIE):
118 _VALID_URL = r'https?://(?:cursos\.)?alura\.com\.br/course/(?P<id>[^/]+)'
119 _LOGIN_URL = 'https://cursos.alura.com.br/loginForm?urlAfterLogin=/loginForm'
120 _NETRC_MACHINE = 'aluracourse'
122 'url': 'https://cursos.alura.com.br/course/clojure-mutabilidade-com-atoms-e-refs',
123 'only_matching': True,
127 def suitable(cls, url):
128 return False if AluraIE.suitable(url) else super(AluraCourseIE, cls).suitable(url)
130 def _real_extract(self, url):
132 course_path = self._match_id(url)
133 webpage = self._download_webpage(url, course_path)
135 course_title = self._search_regex(
136 r'<h1.*?>(.*?)<strong>(?P<course_title>.*?)</strong></h[0-9]>', webpage,
137 'course title', default=course_path, group='course_title')
141 for path in re.findall(r'<a\b(?=[^>]* class="[^
"]*(?<=[" ])courseSectionList
-section
[" ])(?=[^>]* href="([^
"]*))', webpage):
142 page_url = urljoin(url, path)
143 section_path = self._download_webpage(page_url, course_path)
144 for path_video in re.findall(r'<a\b(?=[^>]* class="[^
"]*(?<=[" ])task
-menu
-nav
-item
-link
-VIDEO
[" ])(?=[^>]* href="([^
"]*))', section_path):
145 chapter = clean_html(
147 r'<h3[^>]+class=(["\'])task
-menu
-section
-title
-text\
1[^
>]*>(?P
<chapter
>[^
<]+)',
152 chapter_number = int_or_none(
154 r'<span
[^
>]+class=(["\'])task-menu-section-title-number[^>]*>(.*?)<strong>(?P<chapter_number>[^<]+)</strong>',
157 group='chapter_number'))
158 video_url = urljoin(url, path_video)
161 '_type': 'url_transparent',
162 'id': self._match_id(video_url),
164 'id_key': self.ie_key(),
166 'chapter_number': chapter_number
168 entries.append(entry)
169 return self.playlist_result(entries, course_path, course_title)