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.

136 lines
4.5 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
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. determine_ext,
  7. int_or_none,
  8. parse_iso8601,
  9. )
  10. class PatreonIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://www.patreon.com/creation?hid=743933',
  14. 'md5': 'e25505eec1053a6e6813b8ed369875cc',
  15. 'info_dict': {
  16. 'id': '743933',
  17. 'ext': 'mp3',
  18. 'title': 'Episode 166: David Smalley of Dogma Debate',
  19. 'description': 'md5:713b08b772cd6271b9f3906683cfacdf',
  20. 'uploader': 'Cognitive Dissonance Podcast',
  21. 'thumbnail': 're:^https?://.*$',
  22. 'timestamp': 1406473987,
  23. 'upload_date': '20140727',
  24. },
  25. }, {
  26. 'url': 'http://www.patreon.com/creation?hid=754133',
  27. 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
  28. 'info_dict': {
  29. 'id': '754133',
  30. 'ext': 'mp3',
  31. 'title': 'CD 167 Extra',
  32. 'uploader': 'Cognitive Dissonance Podcast',
  33. 'thumbnail': 're:^https?://.*$',
  34. },
  35. 'skip': 'Patron-only content',
  36. }, {
  37. 'url': 'https://www.patreon.com/creation?hid=1682498',
  38. 'info_dict': {
  39. 'id': 'SU4fj_aEMVw',
  40. 'ext': 'mp4',
  41. 'title': 'I\'m on Patreon!',
  42. 'uploader': 'TraciJHines',
  43. 'thumbnail': 're:^https?://.*$',
  44. 'upload_date': '20150211',
  45. 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
  46. 'uploader_id': 'TraciJHines',
  47. },
  48. 'params': {
  49. 'noplaylist': True,
  50. 'skip_download': True,
  51. }
  52. }, {
  53. 'url': 'https://www.patreon.com/posts/episode-166-of-743933',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'https://www.patreon.com/posts/743933',
  57. 'only_matching': True,
  58. }]
  59. # Currently Patreon exposes download URL via hidden CSS, so login is not
  60. # needed. Keeping this commented for when this inevitably changes.
  61. '''
  62. def _login(self):
  63. username, password = self._get_login_info()
  64. if username is None:
  65. return
  66. login_form = {
  67. 'redirectUrl': 'http://www.patreon.com/',
  68. 'email': username,
  69. 'password': password,
  70. }
  71. request = sanitized_Request(
  72. 'https://www.patreon.com/processLogin',
  73. compat_urllib_parse_urlencode(login_form).encode('utf-8')
  74. )
  75. login_page = self._download_webpage(request, None, note='Logging in')
  76. if re.search(r'onLoginFailed', login_page):
  77. raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
  78. def _real_initialize(self):
  79. self._login()
  80. '''
  81. def _real_extract(self, url):
  82. video_id = self._match_id(url)
  83. post = self._download_json(
  84. 'https://www.patreon.com/api/posts/' + video_id, video_id)
  85. attributes = post['data']['attributes']
  86. title = attributes['title'].strip()
  87. image = attributes.get('image') or {}
  88. info = {
  89. 'id': video_id,
  90. 'title': title,
  91. 'description': clean_html(attributes.get('content')),
  92. 'thumbnail': image.get('large_url') or image.get('url'),
  93. 'timestamp': parse_iso8601(attributes.get('published_at')),
  94. 'like_count': int_or_none(attributes.get('like_count')),
  95. 'comment_count': int_or_none(attributes.get('comment_count')),
  96. }
  97. def add_file(file_data):
  98. file_url = file_data.get('url')
  99. if file_url:
  100. info.update({
  101. 'url': file_url,
  102. 'ext': determine_ext(file_data.get('name'), 'mp3'),
  103. })
  104. for i in post.get('included', []):
  105. i_type = i.get('type')
  106. if i_type == 'attachment':
  107. add_file(i.get('attributes') or {})
  108. elif i_type == 'user':
  109. user_attributes = i.get('attributes')
  110. if user_attributes:
  111. info.update({
  112. 'uploader': user_attributes.get('full_name'),
  113. 'uploader_url': user_attributes.get('url'),
  114. })
  115. if not info.get('url'):
  116. add_file(attributes.get('post_file') or {})
  117. if not info.get('url'):
  118. info.update({
  119. '_type': 'url',
  120. 'url': attributes['embed']['url'],
  121. })
  122. return info