You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
11 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. from __future__ import unicode_literals
  2. import json
  3. import random
  4. import collections
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_str,
  8. compat_urllib_parse,
  9. compat_urlparse,
  10. )
  11. from ..utils import (
  12. ExtractorError,
  13. int_or_none,
  14. parse_duration,
  15. sanitized_Request,
  16. )
  17. class PluralsightBaseIE(InfoExtractor):
  18. _API_BASE = 'http://app.pluralsight.com'
  19. class PluralsightIE(PluralsightBaseIE):
  20. IE_NAME = 'pluralsight'
  21. _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/training/player\?'
  22. _LOGIN_URL = 'https://app.pluralsight.com/id/'
  23. _NETRC_MACHINE = 'pluralsight'
  24. _TESTS = [{
  25. 'url': 'http://www.pluralsight.com/training/player?author=mike-mckeown&name=hosting-sql-server-windows-azure-iaas-m7-mgmt&mode=live&clip=3&course=hosting-sql-server-windows-azure-iaas',
  26. 'md5': '4d458cf5cf4c593788672419a8dd4cf8',
  27. 'info_dict': {
  28. 'id': 'hosting-sql-server-windows-azure-iaas-m7-mgmt-04',
  29. 'ext': 'mp4',
  30. 'title': 'Management of SQL Server - Demo Monitoring',
  31. 'duration': 338,
  32. },
  33. 'skip': 'Requires pluralsight account credentials',
  34. }, {
  35. 'url': 'https://app.pluralsight.com/training/player?course=angularjs-get-started&author=scott-allen&name=angularjs-get-started-m1-introduction&clip=0&mode=live',
  36. 'only_matching': True,
  37. }, {
  38. # available without pluralsight account
  39. 'url': 'http://app.pluralsight.com/training/player?author=scott-allen&name=angularjs-get-started-m1-introduction&mode=live&clip=0&course=angularjs-get-started',
  40. 'only_matching': True,
  41. }]
  42. def _real_initialize(self):
  43. self._login()
  44. def _login(self):
  45. (username, password) = self._get_login_info()
  46. if username is None:
  47. return
  48. login_page = self._download_webpage(
  49. self._LOGIN_URL, None, 'Downloading login page')
  50. login_form = self._hidden_inputs(login_page)
  51. login_form.update({
  52. 'Username': username.encode('utf-8'),
  53. 'Password': password.encode('utf-8'),
  54. })
  55. post_url = self._search_regex(
  56. r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
  57. 'post url', default=self._LOGIN_URL, group='url')
  58. if not post_url.startswith('http'):
  59. post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
  60. request = sanitized_Request(
  61. post_url, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
  62. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  63. response = self._download_webpage(
  64. request, None, 'Logging in as %s' % username)
  65. error = self._search_regex(
  66. r'<span[^>]+class="field-validation-error"[^>]*>([^<]+)</span>',
  67. response, 'error message', default=None)
  68. if error:
  69. raise ExtractorError('Unable to login: %s' % error, expected=True)
  70. if all(p not in response for p in ('__INITIAL_STATE__', '"currentUser"')):
  71. raise ExtractorError('Unable to log in')
  72. def _real_extract(self, url):
  73. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  74. author = qs.get('author', [None])[0]
  75. name = qs.get('name', [None])[0]
  76. clip_id = qs.get('clip', [None])[0]
  77. course = qs.get('course', [None])[0]
  78. if any(not f for f in (author, name, clip_id, course,)):
  79. raise ExtractorError('Invalid URL', expected=True)
  80. display_id = '%s-%s' % (name, clip_id)
  81. webpage = self._download_webpage(url, display_id)
  82. modules = self._search_regex(
  83. r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
  84. webpage, 'modules', default=None)
  85. if modules:
  86. collection = self._parse_json(modules, display_id)
  87. else:
  88. # Webpage may be served in different layout (see
  89. # https://github.com/rg3/youtube-dl/issues/7607)
  90. collection = self._parse_json(
  91. self._search_regex(
  92. r'var\s+initialState\s*=\s*({.+?});\n', webpage, 'initial state'),
  93. display_id)['course']['modules']
  94. module, clip = None, None
  95. for module_ in collection:
  96. if name in (module_.get('moduleName'), module_.get('name')):
  97. module = module_
  98. for clip_ in module_.get('clips', []):
  99. clip_index = clip_.get('clipIndex')
  100. if clip_index is None:
  101. clip_index = clip_.get('index')
  102. if clip_index is None:
  103. continue
  104. if compat_str(clip_index) == clip_id:
  105. clip = clip_
  106. break
  107. if not clip:
  108. raise ExtractorError('Unable to resolve clip')
  109. QUALITIES = {
  110. 'low': {'width': 640, 'height': 480},
  111. 'medium': {'width': 848, 'height': 640},
  112. 'high': {'width': 1024, 'height': 768},
  113. }
  114. AllowedQuality = collections.namedtuple('AllowedQuality', ['ext', 'qualities'])
  115. ALLOWED_QUALITIES = (
  116. AllowedQuality('webm', ('high',)),
  117. AllowedQuality('mp4', ('low', 'medium', 'high',)),
  118. )
  119. # In order to minimize the number of calls to ViewClip API and reduce
  120. # the probability of being throttled or banned by Pluralsight we will request
  121. # only single format until formats listing was explicitly requested.
  122. if self._downloader.params.get('listformats', False):
  123. allowed_qualities = ALLOWED_QUALITIES
  124. else:
  125. def guess_allowed_qualities():
  126. req_format = self._downloader.params.get('format') or 'best'
  127. req_format_split = req_format.split('-')
  128. if len(req_format_split) > 1:
  129. req_ext, req_quality = req_format_split
  130. for allowed_quality in ALLOWED_QUALITIES:
  131. if req_ext == allowed_quality.ext and req_quality in allowed_quality.qualities:
  132. return (AllowedQuality(req_ext, (req_quality, )), )
  133. req_ext = 'webm' if self._downloader.params.get('prefer_free_formats') else 'mp4'
  134. return (AllowedQuality(req_ext, ('high', )), )
  135. allowed_qualities = guess_allowed_qualities()
  136. formats = []
  137. for ext, qualities in allowed_qualities:
  138. for quality in qualities:
  139. f = QUALITIES[quality].copy()
  140. clip_post = {
  141. 'a': author,
  142. 'cap': 'false',
  143. 'cn': clip_id,
  144. 'course': course,
  145. 'lc': 'en',
  146. 'm': name,
  147. 'mt': ext,
  148. 'q': '%dx%d' % (f['width'], f['height']),
  149. }
  150. request = sanitized_Request(
  151. '%s/training/Player/ViewClip' % self._API_BASE,
  152. json.dumps(clip_post).encode('utf-8'))
  153. request.add_header('Content-Type', 'application/json;charset=utf-8')
  154. format_id = '%s-%s' % (ext, quality)
  155. clip_url = self._download_webpage(
  156. request, display_id, 'Downloading %s URL' % format_id, fatal=False)
  157. # Pluralsight tracks multiple sequential calls to ViewClip API and start
  158. # to return 429 HTTP errors after some time (see
  159. # https://github.com/rg3/youtube-dl/pull/6989). Moreover it may even lead
  160. # to account ban (see https://github.com/rg3/youtube-dl/issues/6842).
  161. # To somewhat reduce the probability of these consequences
  162. # we will sleep random amount of time before each call to ViewClip.
  163. self._sleep(
  164. random.randint(2, 5), display_id,
  165. '%(video_id)s: Waiting for %(timeout)s seconds to avoid throttling')
  166. if not clip_url:
  167. continue
  168. f.update({
  169. 'url': clip_url,
  170. 'ext': ext,
  171. 'format_id': format_id,
  172. })
  173. formats.append(f)
  174. self._sort_formats(formats)
  175. # TODO: captions
  176. # http://www.pluralsight.com/training/Player/ViewClip + cap = true
  177. # or
  178. # http://www.pluralsight.com/training/Player/Captions
  179. # { a = author, cn = clip_id, lc = end, m = name }
  180. return {
  181. 'id': clip['clipName'],
  182. 'title': '%s - %s' % (module['title'], clip['title']),
  183. 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
  184. 'creator': author,
  185. 'formats': formats
  186. }
  187. class PluralsightCourseIE(PluralsightBaseIE):
  188. IE_NAME = 'pluralsight:course'
  189. _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/(?:library/)?courses/(?P<id>[^/]+)'
  190. _TESTS = [{
  191. # Free course from Pluralsight Starter Subscription for Microsoft TechNet
  192. # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
  193. 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
  194. 'info_dict': {
  195. 'id': 'hosting-sql-server-windows-azure-iaas',
  196. 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
  197. 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
  198. },
  199. 'playlist_count': 31,
  200. }, {
  201. # available without pluralsight account
  202. 'url': 'https://www.pluralsight.com/courses/angularjs-get-started',
  203. 'only_matching': True,
  204. }, {
  205. 'url': 'https://app.pluralsight.com/library/courses/understanding-microsoft-azure-amazon-aws/table-of-contents',
  206. 'only_matching': True,
  207. }]
  208. def _real_extract(self, url):
  209. course_id = self._match_id(url)
  210. # TODO: PSM cookie
  211. course = self._download_json(
  212. '%s/data/course/%s' % (self._API_BASE, course_id),
  213. course_id, 'Downloading course JSON')
  214. title = course['title']
  215. description = course.get('description') or course.get('shortDescription')
  216. course_data = self._download_json(
  217. '%s/data/course/content/%s' % (self._API_BASE, course_id),
  218. course_id, 'Downloading course data JSON')
  219. entries = []
  220. for module in course_data:
  221. for clip in module.get('clips', []):
  222. player_parameters = clip.get('playerParameters')
  223. if not player_parameters:
  224. continue
  225. entries.append(self.url_result(
  226. '%s/training/player?%s' % (self._API_BASE, player_parameters),
  227. 'Pluralsight'))
  228. return self.playlist_result(entries, course_id, title, description)