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.

296 lines
12 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 re
  3. import json
  4. import random
  5. import collections
  6. from .common import InfoExtractor
  7. from ..compat import (
  8. compat_str,
  9. compat_urlparse,
  10. )
  11. from ..utils import (
  12. ExtractorError,
  13. int_or_none,
  14. parse_duration,
  15. qualities,
  16. sanitized_Request,
  17. urlencode_postdata,
  18. )
  19. class PluralsightBaseIE(InfoExtractor):
  20. _API_BASE = 'http://app.pluralsight.com'
  21. class PluralsightIE(PluralsightBaseIE):
  22. IE_NAME = 'pluralsight'
  23. _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/training/player\?'
  24. _LOGIN_URL = 'https://app.pluralsight.com/id/'
  25. _NETRC_MACHINE = 'pluralsight'
  26. _TESTS = [{
  27. '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',
  28. 'md5': '4d458cf5cf4c593788672419a8dd4cf8',
  29. 'info_dict': {
  30. 'id': 'hosting-sql-server-windows-azure-iaas-m7-mgmt-04',
  31. 'ext': 'mp4',
  32. 'title': 'Management of SQL Server - Demo Monitoring',
  33. 'duration': 338,
  34. },
  35. 'skip': 'Requires pluralsight account credentials',
  36. }, {
  37. 'url': 'https://app.pluralsight.com/training/player?course=angularjs-get-started&author=scott-allen&name=angularjs-get-started-m1-introduction&clip=0&mode=live',
  38. 'only_matching': True,
  39. }, {
  40. # available without pluralsight account
  41. 'url': 'http://app.pluralsight.com/training/player?author=scott-allen&name=angularjs-get-started-m1-introduction&mode=live&clip=0&course=angularjs-get-started',
  42. 'only_matching': True,
  43. }]
  44. def _real_initialize(self):
  45. self._login()
  46. def _login(self):
  47. (username, password) = self._get_login_info()
  48. if username is None:
  49. return
  50. login_page = self._download_webpage(
  51. self._LOGIN_URL, None, 'Downloading login page')
  52. login_form = self._hidden_inputs(login_page)
  53. login_form.update({
  54. 'Username': username,
  55. 'Password': password,
  56. })
  57. post_url = self._search_regex(
  58. r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
  59. 'post url', default=self._LOGIN_URL, group='url')
  60. if not post_url.startswith('http'):
  61. post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
  62. request = sanitized_Request(
  63. post_url, urlencode_postdata(login_form))
  64. request.add_header('Content-Type', 'application/x-www-form-urlencoded')
  65. response = self._download_webpage(
  66. request, None, 'Logging in as %s' % username)
  67. error = self._search_regex(
  68. r'<span[^>]+class="field-validation-error"[^>]*>([^<]+)</span>',
  69. response, 'error message', default=None)
  70. if error:
  71. raise ExtractorError('Unable to login: %s' % error, expected=True)
  72. if all(p not in response for p in ('__INITIAL_STATE__', '"currentUser"')):
  73. raise ExtractorError('Unable to log in')
  74. def _real_extract(self, url):
  75. qs = compat_urlparse.parse_qs(compat_urlparse.urlparse(url).query)
  76. author = qs.get('author', [None])[0]
  77. name = qs.get('name', [None])[0]
  78. clip_id = qs.get('clip', [None])[0]
  79. course = qs.get('course', [None])[0]
  80. if any(not f for f in (author, name, clip_id, course,)):
  81. raise ExtractorError('Invalid URL', expected=True)
  82. display_id = '%s-%s' % (name, clip_id)
  83. webpage = self._download_webpage(url, display_id)
  84. modules = self._search_regex(
  85. r'moduleCollection\s*:\s*new\s+ModuleCollection\((\[.+?\])\s*,\s*\$rootScope\)',
  86. webpage, 'modules', default=None)
  87. if modules:
  88. collection = self._parse_json(modules, display_id)
  89. else:
  90. # Webpage may be served in different layout (see
  91. # https://github.com/rg3/youtube-dl/issues/7607)
  92. collection = self._parse_json(
  93. self._search_regex(
  94. r'var\s+initialState\s*=\s*({.+?});\n', webpage, 'initial state'),
  95. display_id)['course']['modules']
  96. module, clip = None, None
  97. for module_ in collection:
  98. if name in (module_.get('moduleName'), module_.get('name')):
  99. module = module_
  100. for clip_ in module_.get('clips', []):
  101. clip_index = clip_.get('clipIndex')
  102. if clip_index is None:
  103. clip_index = clip_.get('index')
  104. if clip_index is None:
  105. continue
  106. if compat_str(clip_index) == clip_id:
  107. clip = clip_
  108. break
  109. if not clip:
  110. raise ExtractorError('Unable to resolve clip')
  111. QUALITIES = {
  112. 'low': {'width': 640, 'height': 480},
  113. 'medium': {'width': 848, 'height': 640},
  114. 'high': {'width': 1024, 'height': 768},
  115. 'high-widescreen': {'width': 1280, 'height': 720},
  116. }
  117. QUALITIES_PREFERENCE = ('low', 'medium', 'high', 'high-widescreen',)
  118. quality_key = qualities(QUALITIES_PREFERENCE)
  119. AllowedQuality = collections.namedtuple('AllowedQuality', ['ext', 'qualities'])
  120. ALLOWED_QUALITIES = (
  121. AllowedQuality('webm', ['high', ]),
  122. AllowedQuality('mp4', ['low', 'medium', 'high', ]),
  123. )
  124. # Some courses also offer widescreen resolution for high quality (see
  125. # https://github.com/rg3/youtube-dl/issues/7766)
  126. widescreen = True if re.search(
  127. r'courseSupportsWidescreenVideoFormats\s*:\s*true', webpage) else False
  128. best_quality = 'high-widescreen' if widescreen else 'high'
  129. if widescreen:
  130. for allowed_quality in ALLOWED_QUALITIES:
  131. allowed_quality.qualities.append(best_quality)
  132. # In order to minimize the number of calls to ViewClip API and reduce
  133. # the probability of being throttled or banned by Pluralsight we will request
  134. # only single format until formats listing was explicitly requested.
  135. if self._downloader.params.get('listformats', False):
  136. allowed_qualities = ALLOWED_QUALITIES
  137. else:
  138. def guess_allowed_qualities():
  139. req_format = self._downloader.params.get('format') or 'best'
  140. req_format_split = req_format.split('-', 1)
  141. if len(req_format_split) > 1:
  142. req_ext, req_quality = req_format_split
  143. for allowed_quality in ALLOWED_QUALITIES:
  144. if req_ext == allowed_quality.ext and req_quality in allowed_quality.qualities:
  145. return (AllowedQuality(req_ext, (req_quality, )), )
  146. req_ext = 'webm' if self._downloader.params.get('prefer_free_formats') else 'mp4'
  147. return (AllowedQuality(req_ext, (best_quality, )), )
  148. allowed_qualities = guess_allowed_qualities()
  149. formats = []
  150. for ext, qualities_ in allowed_qualities:
  151. for quality in qualities_:
  152. f = QUALITIES[quality].copy()
  153. clip_post = {
  154. 'a': author,
  155. 'cap': 'false',
  156. 'cn': clip_id,
  157. 'course': course,
  158. 'lc': 'en',
  159. 'm': name,
  160. 'mt': ext,
  161. 'q': '%dx%d' % (f['width'], f['height']),
  162. }
  163. request = sanitized_Request(
  164. '%s/training/Player/ViewClip' % self._API_BASE,
  165. json.dumps(clip_post).encode('utf-8'))
  166. request.add_header('Content-Type', 'application/json;charset=utf-8')
  167. format_id = '%s-%s' % (ext, quality)
  168. clip_url = self._download_webpage(
  169. request, display_id, 'Downloading %s URL' % format_id, fatal=False)
  170. # Pluralsight tracks multiple sequential calls to ViewClip API and start
  171. # to return 429 HTTP errors after some time (see
  172. # https://github.com/rg3/youtube-dl/pull/6989). Moreover it may even lead
  173. # to account ban (see https://github.com/rg3/youtube-dl/issues/6842).
  174. # To somewhat reduce the probability of these consequences
  175. # we will sleep random amount of time before each call to ViewClip.
  176. self._sleep(
  177. random.randint(2, 5), display_id,
  178. '%(video_id)s: Waiting for %(timeout)s seconds to avoid throttling')
  179. if not clip_url:
  180. continue
  181. f.update({
  182. 'url': clip_url,
  183. 'ext': ext,
  184. 'format_id': format_id,
  185. 'quality': quality_key(quality),
  186. })
  187. formats.append(f)
  188. self._sort_formats(formats)
  189. # TODO: captions
  190. # http://www.pluralsight.com/training/Player/ViewClip + cap = true
  191. # or
  192. # http://www.pluralsight.com/training/Player/Captions
  193. # { a = author, cn = clip_id, lc = end, m = name }
  194. return {
  195. 'id': clip.get('clipName') or clip['name'],
  196. 'title': '%s - %s' % (module['title'], clip['title']),
  197. 'duration': int_or_none(clip.get('duration')) or parse_duration(clip.get('formattedDuration')),
  198. 'creator': author,
  199. 'formats': formats
  200. }
  201. class PluralsightCourseIE(PluralsightBaseIE):
  202. IE_NAME = 'pluralsight:course'
  203. _VALID_URL = r'https?://(?:(?:www|app)\.)?pluralsight\.com/(?:library/)?courses/(?P<id>[^/]+)'
  204. _TESTS = [{
  205. # Free course from Pluralsight Starter Subscription for Microsoft TechNet
  206. # https://offers.pluralsight.com/technet?loc=zTS3z&prod=zOTprodz&tech=zOttechz&prog=zOTprogz&type=zSOz&media=zOTmediaz&country=zUSz
  207. 'url': 'http://www.pluralsight.com/courses/hosting-sql-server-windows-azure-iaas',
  208. 'info_dict': {
  209. 'id': 'hosting-sql-server-windows-azure-iaas',
  210. 'title': 'Hosting SQL Server in Microsoft Azure IaaS Fundamentals',
  211. 'description': 'md5:61b37e60f21c4b2f91dc621a977d0986',
  212. },
  213. 'playlist_count': 31,
  214. }, {
  215. # available without pluralsight account
  216. 'url': 'https://www.pluralsight.com/courses/angularjs-get-started',
  217. 'only_matching': True,
  218. }, {
  219. 'url': 'https://app.pluralsight.com/library/courses/understanding-microsoft-azure-amazon-aws/table-of-contents',
  220. 'only_matching': True,
  221. }]
  222. def _real_extract(self, url):
  223. course_id = self._match_id(url)
  224. # TODO: PSM cookie
  225. course = self._download_json(
  226. '%s/data/course/%s' % (self._API_BASE, course_id),
  227. course_id, 'Downloading course JSON')
  228. title = course['title']
  229. description = course.get('description') or course.get('shortDescription')
  230. course_data = self._download_json(
  231. '%s/data/course/content/%s' % (self._API_BASE, course_id),
  232. course_id, 'Downloading course data JSON')
  233. entries = []
  234. for num, module in enumerate(course_data, 1):
  235. for clip in module.get('clips', []):
  236. player_parameters = clip.get('playerParameters')
  237. if not player_parameters:
  238. continue
  239. entries.append({
  240. '_type': 'url_transparent',
  241. 'url': '%s/training/player?%s' % (self._API_BASE, player_parameters),
  242. 'ie_key': PluralsightIE.ie_key(),
  243. 'chapter': module.get('title'),
  244. 'chapter_number': num,
  245. 'chapter_id': module.get('moduleRef'),
  246. })
  247. return self.playlist_result(entries, course_id, title, description)