logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

scte.py (4993B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. decode_packed_codes,
  6. ExtractorError,
  7. urlencode_postdata,
  8. )
  9. class SCTEBaseIE(InfoExtractor):
  10. _LOGIN_URL = 'https://www.scte.org/SCTE/Sign_In.aspx'
  11. _NETRC_MACHINE = 'scte'
  12. def _real_initialize(self):
  13. self._login()
  14. def _login(self):
  15. username, password = self._get_login_info()
  16. if username is None:
  17. return
  18. login_popup = self._download_webpage(
  19. self._LOGIN_URL, None, 'Downloading login popup')
  20. def is_logged(webpage):
  21. return any(re.search(p, webpage) for p in (
  22. r'class=["\']welcome\b', r'>Sign Out<'))
  23. # already logged in
  24. if is_logged(login_popup):
  25. return
  26. login_form = self._hidden_inputs(login_popup)
  27. login_form.update({
  28. 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$signInUserName': username,
  29. 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$signInPassword': password,
  30. 'ctl01$TemplateBody$WebPartManager1$gwpciNewContactSignInCommon$ciNewContactSignInCommon$RememberMe': 'on',
  31. })
  32. response = self._download_webpage(
  33. self._LOGIN_URL, None, 'Logging in',
  34. data=urlencode_postdata(login_form))
  35. if '|pageRedirect|' not in response and not is_logged(response):
  36. error = self._html_search_regex(
  37. r'(?s)<[^>]+class=["\']AsiError["\'][^>]*>(.+?)</',
  38. response, 'error message', default=None)
  39. if error:
  40. raise ExtractorError('Unable to login: %s' % error, expected=True)
  41. raise ExtractorError('Unable to log in')
  42. class SCTEIE(SCTEBaseIE):
  43. _VALID_URL = r'https?://learning\.scte\.org/mod/scorm/view\.php?.*?\bid=(?P<id>\d+)'
  44. _TESTS = [{
  45. 'url': 'https://learning.scte.org/mod/scorm/view.php?id=31484',
  46. 'info_dict': {
  47. 'title': 'Introduction to DOCSIS Engineering Professional',
  48. 'id': '31484',
  49. },
  50. 'playlist_count': 5,
  51. 'skip': 'Requires account credentials',
  52. }]
  53. def _real_extract(self, url):
  54. video_id = self._match_id(url)
  55. webpage = self._download_webpage(url, video_id)
  56. title = self._search_regex(r'<h1>(.+?)</h1>', webpage, 'title')
  57. context_id = self._search_regex(r'context-(\d+)', webpage, video_id)
  58. content_base = 'https://learning.scte.org/pluginfile.php/%s/mod_scorm/content/8/' % context_id
  59. context = decode_packed_codes(self._download_webpage(
  60. '%smobile/data.js' % content_base, video_id))
  61. data = self._parse_xml(
  62. self._search_regex(
  63. r'CreateData\(\s*"(.+?)"', context, 'data').replace(r"\'", "'"),
  64. video_id)
  65. entries = []
  66. for asset in data.findall('.//asset'):
  67. asset_url = asset.get('url')
  68. if not asset_url or not asset_url.endswith('.mp4'):
  69. continue
  70. asset_id = self._search_regex(
  71. r'video_([^_]+)_', asset_url, 'asset id', default=None)
  72. if not asset_id:
  73. continue
  74. entries.append({
  75. 'id': asset_id,
  76. 'title': title,
  77. 'url': content_base + asset_url,
  78. })
  79. return self.playlist_result(entries, video_id, title)
  80. class SCTECourseIE(SCTEBaseIE):
  81. _VALID_URL = r'https?://learning\.scte\.org/(?:mod/sub)?course/view\.php?.*?\bid=(?P<id>\d+)'
  82. _TESTS = [{
  83. 'url': 'https://learning.scte.org/mod/subcourse/view.php?id=31491',
  84. 'only_matching': True,
  85. }, {
  86. 'url': 'https://learning.scte.org/course/view.php?id=3639',
  87. 'only_matching': True,
  88. }, {
  89. 'url': 'https://learning.scte.org/course/view.php?id=3073',
  90. 'only_matching': True,
  91. }]
  92. def _real_extract(self, url):
  93. course_id = self._match_id(url)
  94. webpage = self._download_webpage(url, course_id)
  95. title = self._search_regex(
  96. r'<h1>(.+?)</h1>', webpage, 'title', default=None)
  97. entries = []
  98. for mobj in re.finditer(
  99. r'''(?x)
  100. <a[^>]+
  101. href=(["\'])
  102. (?P<url>
  103. https?://learning\.scte\.org/mod/
  104. (?P<kind>scorm|subcourse)/view\.php?(?:(?!\1).)*?
  105. \bid=\d+
  106. )
  107. ''',
  108. webpage):
  109. item_url = mobj.group('url')
  110. if item_url == url:
  111. continue
  112. ie = (SCTEIE.ie_key() if mobj.group('kind') == 'scorm'
  113. else SCTECourseIE.ie_key())
  114. entries.append(self.url_result(item_url, ie=ie))
  115. return self.playlist_result(entries, course_id, title)