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.

115 lines
4.0 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. from .common import InfoExtractor
  4. from ..utils import js_to_json
  5. class PatreonIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?patreon\.com/creation\?hid=(?P<id>[^&#]+)'
  7. _TESTS = [
  8. {
  9. 'url': 'http://www.patreon.com/creation?hid=743933',
  10. 'md5': 'e25505eec1053a6e6813b8ed369875cc',
  11. 'info_dict': {
  12. 'id': '743933',
  13. 'ext': 'mp3',
  14. 'title': 'Episode 166: David Smalley of Dogma Debate',
  15. 'uploader': 'Cognitive Dissonance Podcast',
  16. 'thumbnail': 're:^https?://.*$',
  17. },
  18. },
  19. {
  20. 'url': 'http://www.patreon.com/creation?hid=754133',
  21. 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
  22. 'info_dict': {
  23. 'id': '754133',
  24. 'ext': 'mp3',
  25. 'title': 'CD 167 Extra',
  26. 'uploader': 'Cognitive Dissonance Podcast',
  27. 'thumbnail': 're:^https?://.*$',
  28. },
  29. },
  30. {
  31. 'url': 'https://www.patreon.com/creation?hid=1682498',
  32. 'info_dict': {
  33. 'id': 'SU4fj_aEMVw',
  34. 'ext': 'mp4',
  35. 'title': 'I\'m on Patreon!',
  36. 'uploader': 'TraciJHines',
  37. 'thumbnail': 're:^https?://.*$',
  38. 'upload_date': '20150211',
  39. 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
  40. 'uploader_id': 'TraciJHines',
  41. },
  42. 'params': {
  43. 'noplaylist': True,
  44. 'skip_download': True,
  45. }
  46. }
  47. ]
  48. # Currently Patreon exposes download URL via hidden CSS, so login is not
  49. # needed. Keeping this commented for when this inevitably changes.
  50. '''
  51. def _login(self):
  52. (username, password) = self._get_login_info()
  53. if username is None:
  54. return
  55. login_form = {
  56. 'redirectUrl': 'http://www.patreon.com/',
  57. 'email': username,
  58. 'password': password,
  59. }
  60. request = sanitized_Request(
  61. 'https://www.patreon.com/processLogin',
  62. compat_urllib_parse.urlencode(login_form).encode('utf-8')
  63. )
  64. login_page = self._download_webpage(request, None, note='Logging in as %s' % username)
  65. if re.search(r'onLoginFailed', login_page):
  66. raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
  67. def _real_initialize(self):
  68. self._login()
  69. '''
  70. def _real_extract(self, url):
  71. video_id = self._match_id(url)
  72. webpage = self._download_webpage(url, video_id)
  73. title = self._og_search_title(webpage).strip()
  74. attach_fn = self._html_search_regex(
  75. r'<div class="attach"><a target="_blank" href="([^"]+)">',
  76. webpage, 'attachment URL', default=None)
  77. embed = self._html_search_regex(
  78. r'<div[^>]+id="watchCreation"[^>]*>\s*<iframe[^>]+src="([^"]+)"',
  79. webpage, 'embedded URL', default=None)
  80. if attach_fn is not None:
  81. video_url = 'http://www.patreon.com' + attach_fn
  82. thumbnail = self._og_search_thumbnail(webpage)
  83. uploader = self._html_search_regex(
  84. r'<strong>(.*?)</strong> is creating', webpage, 'uploader')
  85. elif embed is not None:
  86. return self.url_result(embed)
  87. else:
  88. playlist = self._parse_json(self._search_regex(
  89. r'(?s)new\s+jPlayerPlaylist\(\s*\{\s*[^}]*},\s*(\[.*?,?\s*\])',
  90. webpage, 'playlist JSON'),
  91. video_id, transform_source=js_to_json)
  92. data = playlist[0]
  93. video_url = self._proto_relative_url(data['mp3'])
  94. thumbnail = self._proto_relative_url(data.get('cover'))
  95. uploader = data.get('artist')
  96. return {
  97. 'id': video_id,
  98. 'url': video_url,
  99. 'ext': 'mp3',
  100. 'title': title,
  101. 'uploader': uploader,
  102. 'thumbnail': thumbnail,
  103. }