]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/patreon.py
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  13 class PatreonIE(InfoExtractor
): 
  14     _VALID_URL 
= r
'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)' 
  16         'url': 'http://www.patreon.com/creation?hid=743933', 
  17         'md5': 'e25505eec1053a6e6813b8ed369875cc', 
  21             'title': 'Episode 166: David Smalley of Dogma Debate', 
  22             'description': 'md5:713b08b772cd6271b9f3906683cfacdf', 
  23             'uploader': 'Cognitive Dissonance Podcast', 
  24             'thumbnail': 're:^https?://.*$', 
  25             'timestamp': 1406473987, 
  26             'upload_date': '20140727', 
  29         'url': 'http://www.patreon.com/creation?hid=754133', 
  30         'md5': '3eb09345bf44bf60451b8b0b81759d0a', 
  34             'title': 'CD 167 Extra', 
  35             'uploader': 'Cognitive Dissonance Podcast', 
  36             'thumbnail': 're:^https?://.*$', 
  38         'skip': 'Patron-only content', 
  40         'url': 'https://www.patreon.com/creation?hid=1682498', 
  44             'title': 'I\'m on Patreon!', 
  45             'uploader': 'TraciJHines', 
  46             'thumbnail': 're:^https?://.*$', 
  47             'upload_date': '20150211', 
  48             'description': 'md5:c5a706b1f687817a3de09db1eb93acd4', 
  49             'uploader_id': 'TraciJHines', 
  53             'skip_download': True, 
  56         'url': 'https://www.patreon.com/posts/episode-166-of-743933', 
  57         'only_matching': True, 
  59         'url': 'https://www.patreon.com/posts/743933', 
  60         'only_matching': True, 
  63     # Currently Patreon exposes download URL via hidden CSS, so login is not 
  64     # needed. Keeping this commented for when this inevitably changes. 
  67         username, password = self._get_login_info() 
  72             'redirectUrl': 'http://www.patreon.com/', 
  77         request = sanitized_Request( 
  78             'https://www.patreon.com/processLogin', 
  79             compat_urllib_parse_urlencode(login_form).encode('utf-8') 
  81         login_page = self._download_webpage(request, None, note='Logging in') 
  83         if re.search(r'onLoginFailed', login_page): 
  84             raise ExtractorError('Unable to login, incorrect username and/or password', expected=True) 
  86     def _real_initialize(self): 
  90     def _real_extract(self
, url
): 
  91         video_id 
= self
._match
_id
(url
) 
  92         post 
= self
._download
_json
( 
  93             'https://www.patreon.com/api/posts/' + video_id
, video_id
) 
  94         attributes 
= post
['data']['attributes'] 
  95         title 
= attributes
['title'].strip() 
  96         image 
= attributes
.get('image') or {} 
 100             'description': clean_html(attributes
.get('content')), 
 101             'thumbnail': image
.get('large_url') or image
.get('url'), 
 102             'timestamp': parse_iso8601(attributes
.get('published_at')), 
 103             'like_count': int_or_none(attributes
.get('like_count')), 
 104             'comment_count': int_or_none(attributes
.get('comment_count')), 
 107         def add_file(file_data
): 
 108             file_url 
= file_data
.get('url') 
 112                     'ext': determine_ext(file_data
.get('name'), 'mp3'), 
 115         for i 
in post
.get('included', []): 
 116             i_type 
= i
.get('type') 
 117             if i_type 
== 'attachment': 
 118                 add_file(i
.get('attributes') or {}) 
 119             elif i_type 
== 'user': 
 120                 user_attributes 
= i
.get('attributes') 
 123                         'uploader': user_attributes
.get('full_name'), 
 124                         'uploader_url': user_attributes
.get('url'), 
 127         if not info
.get('url'): 
 128             add_file(attributes
.get('post_file') or {}) 
 130         if not info
.get('url'): 
 133                 'url': attributes
['embed']['url'],