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.

156 lines
5.2 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
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .brightcove import BrightcoveLegacyIE
  6. from ..utils import (
  7. ExtractorError,
  8. sanitized_Request,
  9. smuggle_url,
  10. std_headers,
  11. urlencode_postdata,
  12. )
  13. class SafariBaseIE(InfoExtractor):
  14. _LOGIN_URL = 'https://www.safaribooksonline.com/accounts/login/'
  15. _SUCCESSFUL_LOGIN_REGEX = r'<a href="/accounts/logout/"[^>]*>Sign Out</a>'
  16. _NETRC_MACHINE = 'safari'
  17. _API_BASE = 'https://www.safaribooksonline.com/api/v1/book'
  18. _API_FORMAT = 'json'
  19. LOGGED_IN = False
  20. def _real_initialize(self):
  21. # We only need to log in once for courses or individual videos
  22. if not self.LOGGED_IN:
  23. self._login()
  24. SafariBaseIE.LOGGED_IN = True
  25. def _login(self):
  26. (username, password) = self._get_login_info()
  27. if username is None:
  28. self.raise_login_required('safaribooksonline.com account is required')
  29. headers = std_headers
  30. if 'Referer' not in headers:
  31. headers['Referer'] = self._LOGIN_URL
  32. login_page = self._download_webpage(
  33. self._LOGIN_URL, None,
  34. 'Downloading login form')
  35. csrf = self._html_search_regex(
  36. r"name='csrfmiddlewaretoken'\s+value='([^']+)'",
  37. login_page, 'csrf token')
  38. login_form = {
  39. 'csrfmiddlewaretoken': csrf,
  40. 'email': username,
  41. 'password1': password,
  42. 'login': 'Sign In',
  43. 'next': '',
  44. }
  45. request = sanitized_Request(
  46. self._LOGIN_URL, urlencode_postdata(login_form), headers=headers)
  47. login_page = self._download_webpage(
  48. request, None, 'Logging in as %s' % username)
  49. if re.search(self._SUCCESSFUL_LOGIN_REGEX, login_page) is None:
  50. raise ExtractorError(
  51. 'Login failed; make sure your credentials are correct and try again.',
  52. expected=True)
  53. self.to_screen('Login successful')
  54. class SafariIE(SafariBaseIE):
  55. IE_NAME = 'safari'
  56. IE_DESC = 'safaribooksonline.com online video'
  57. _VALID_URL = r'''(?x)https?://
  58. (?:www\.)?safaribooksonline\.com/
  59. (?:
  60. library/view/[^/]+|
  61. api/v1/book
  62. )/
  63. (?P<course_id>[^/]+)/
  64. (?:chapter(?:-content)?/)?
  65. (?P<part>part\d+)\.html
  66. '''
  67. _TESTS = [{
  68. 'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/part00.html',
  69. 'md5': '5b0c4cc1b3c1ba15dda7344085aa5592',
  70. 'info_dict': {
  71. 'id': '2842601850001',
  72. 'ext': 'mp4',
  73. 'title': 'Introduction',
  74. },
  75. 'skip': 'Requires safaribooksonline account credentials',
  76. }, {
  77. 'url': 'https://www.safaribooksonline.com/api/v1/book/9780133392838/chapter/part00.html',
  78. 'only_matching': True,
  79. }, {
  80. # non-digits in course id
  81. 'url': 'https://www.safaribooksonline.com/library/view/create-a-nodejs/100000006A0210/part00.html',
  82. 'only_matching': True,
  83. }]
  84. def _real_extract(self, url):
  85. mobj = re.match(self._VALID_URL, url)
  86. course_id = mobj.group('course_id')
  87. part = mobj.group('part')
  88. webpage = self._download_webpage(
  89. '%s/%s/chapter-content/%s.html' % (self._API_BASE, course_id, part),
  90. part)
  91. bc_url = BrightcoveLegacyIE._extract_brightcove_url(webpage)
  92. if not bc_url:
  93. raise ExtractorError('Could not extract Brightcove URL from %s' % url, expected=True)
  94. return self.url_result(smuggle_url(bc_url, {'Referer': url}), 'BrightcoveLegacy')
  95. class SafariCourseIE(SafariBaseIE):
  96. IE_NAME = 'safari:course'
  97. IE_DESC = 'safaribooksonline.com online courses'
  98. _VALID_URL = r'https?://(?:www\.)?safaribooksonline\.com/(?:library/view/[^/]+|api/v1/book)/(?P<id>[^/]+)/?(?:[#?]|$)'
  99. _TESTS = [{
  100. 'url': 'https://www.safaribooksonline.com/library/view/hadoop-fundamentals-livelessons/9780133392838/',
  101. 'info_dict': {
  102. 'id': '9780133392838',
  103. 'title': 'Hadoop Fundamentals LiveLessons',
  104. },
  105. 'playlist_count': 22,
  106. 'skip': 'Requires safaribooksonline account credentials',
  107. }, {
  108. 'url': 'https://www.safaribooksonline.com/api/v1/book/9781449396459/?override_format=json',
  109. 'only_matching': True,
  110. }]
  111. def _real_extract(self, url):
  112. course_id = self._match_id(url)
  113. course_json = self._download_json(
  114. '%s/%s/?override_format=%s' % (self._API_BASE, course_id, self._API_FORMAT),
  115. course_id, 'Downloading course JSON')
  116. if 'chapters' not in course_json:
  117. raise ExtractorError(
  118. 'No chapters found for course %s' % course_id, expected=True)
  119. entries = [
  120. self.url_result(chapter, 'Safari')
  121. for chapter in course_json['chapters']]
  122. course_title = course_json['title']
  123. return self.playlist_result(entries, course_id, course_title)