1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
13 class SCTEBaseIE(InfoExtractor
):
14 _LOGIN_URL
= 'https://www.scte.org/SCTE/Sign_In.aspx'
15 _NETRC_MACHINE
= 'scte'
17 def _perform_login(self
, username
, password
):
18 login_popup
= self
._download
_webpage
(
19 self
._LOGIN
_URL
, None, 'Downloading login popup')
21 def is_logged(webpage
):
22 return any(re
.search(p
, webpage
) for p
in (
23 r
'class=["\']welcome
\b', r'>Sign Out
<'))
26 if is_logged(login_popup):
29 login_form = self._hidden_inputs(login_popup)
32 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$signInUserName
': username,
33 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$signInPassword
': password,
34 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$RememberMe
': 'on
',
37 response = self._download_webpage(
38 self._LOGIN_URL, None, 'Logging
in',
39 data=urlencode_postdata(login_form))
41 if '|pageRedirect|
' not in response and not is_logged(response):
42 error = self._html_search_regex(
43 r'(?s
)<[^
>]+class=["\']AsiError["\'][^
>]*>(.+?
)</',
44 response, 'error message
', default=None)
46 raise ExtractorError('Unable to login
: %s' % error, expected=True)
47 raise ExtractorError('Unable to log
in')
50 class SCTEIE(SCTEBaseIE):
51 _VALID_URL = r'https?
://learning\
.scte\
.org
/mod
/scorm
/view\
.php?
.*?
\bid
=(?P
<id>\d
+)'
53 'url
': 'https
://learning
.scte
.org
/mod
/scorm
/view
.php?
id=31484',
55 'title
': 'Introduction to DOCSIS Engineering Professional
',
59 'skip
': 'Requires account credentials
',
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
65 webpage = self._download_webpage(url, video_id)
67 title = self._search_regex(r'<h1
>(.+?
)</h1
>', webpage, 'title
')
69 context_id = self._search_regex(r'context
-(\d
+)', webpage, video_id)
70 content_base = 'https
://learning
.scte
.org
/pluginfile
.php
/%s/mod_scorm
/content
/8/' % context_id
71 context = decode_packed_codes(self._download_webpage(
72 '%smobile
/data
.js
' % content_base, video_id))
74 data = self._parse_xml(
76 r'CreateData\
(\s
*"(.+?)"', context, 'data
').replace(r"\'", "'"),
80 for asset in data.findall('.//asset'):
81 asset_url = asset.get('url')
82 if not asset_url or not asset_url.endswith('.mp4'):
84 asset_id = self._search_regex(
85 r'video_([^_]+)_', asset_url, 'asset id', default=None)
91 'url': content_base + asset_url,
94 return self.playlist_result(entries, video_id, title)
97 class SCTECourseIE(SCTEBaseIE):
98 _VALID_URL = r'https?://learning\.scte\.org/(?:mod/sub)?course/view\.php?.*?\bid=(?P<id>\d+)'
100 'url': 'https://learning.scte.org/mod/subcourse/view.php?id=31491',
101 'only_matching': True,
103 'url': 'https://learning.scte.org/course/view.php?id=3639',
104 'only_matching': True,
106 'url': 'https://learning.scte.org/course/view.php?id=3073',
107 'only_matching': True,
110 def _real_extract(self, url):
111 course_id = self._match_id(url)
113 webpage = self._download_webpage(url, course_id)
115 title = self._search_regex(
116 r'<h1>(.+?)</h1>', webpage, 'title', default=None)
119 for mobj in re.finditer(
124 https?
://learning\
.scte\
.org
/mod
/
125 (?P
<kind
>scorm|subcourse
)/view\
.php?
(?
:(?
!\
1).)*?
130 item_url = mobj.group('url')
133 ie = (SCTEIE.ie_key() if mobj.group('kind') == 'scorm'
134 else SCTECourseIE.ie_key())
135 entries.append(self.url_result(item_url, ie=ie))
137 return self.playlist_result(entries, course_id, title)