2 from __future__ import unicode_literals
4 from .common import InfoExtractor
17 class PatreonIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
20 'url': 'http://www.patreon.com/creation?hid=743933',
21 'md5': 'e25505eec1053a6e6813b8ed369875cc',
25 'title': 'Episode 166: David Smalley of Dogma Debate',
26 'description': 'md5:713b08b772cd6271b9f3906683cfacdf',
27 'uploader': 'Cognitive Dissonance Podcast',
28 'thumbnail': 're:^https?://.*$',
29 'timestamp': 1406473987,
30 'upload_date': '20140727',
31 'uploader_id': '87145',
34 'url': 'http://www.patreon.com/creation?hid=754133',
35 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
39 'title': 'CD 167 Extra',
40 'uploader': 'Cognitive Dissonance Podcast',
41 'thumbnail': 're:^https?://.*$',
43 'skip': 'Patron-only content',
45 'url': 'https://www.patreon.com/creation?hid=1682498',
49 'title': 'I\'m on Patreon!',
50 'uploader': 'TraciJHines',
51 'thumbnail': 're:^https?://.*$',
52 'upload_date': '20150211',
53 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
54 'uploader_id': 'TraciJHines',
58 'skip_download': True,
61 'url': 'https://www.patreon.com/posts/episode-166-of-743933',
62 'only_matching': True,
64 'url': 'https://www.patreon.com/posts/743933',
65 'only_matching': True,
68 # Currently Patreon exposes download URL via hidden CSS, so login is not
69 # needed. Keeping this commented for when this inevitably changes.
72 username, password = self._get_login_info()
77 'redirectUrl': 'http://www.patreon.com/',
82 request = sanitized_Request(
83 'https://www.patreon.com/processLogin',
84 compat_urllib_parse_urlencode(login_form).encode('utf-8')
86 login_page = self._download_webpage(request, None, note='Logging in')
88 if re.search(r'onLoginFailed', login_page):
89 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
91 def _real_initialize(self):
95 def _real_extract(self, url):
96 video_id = self._match_id(url)
97 post = self._download_json(
98 'https://www.patreon.com/api/posts/' + video_id, video_id, query={
99 'fields[media]': 'download_url,mimetype,size_bytes',
100 'fields[post]': 'comment_count,content,embed,image,like_count,post_file,published_at,title',
101 'fields[user]': 'full_name,url',
102 'json-api-use-default-includes': 'false',
103 'include': 'media,user',
105 attributes = post['data']['attributes']
106 title = attributes['title'].strip()
107 image = attributes.get('image') or {}
111 'description': clean_html(attributes.get('content')),
112 'thumbnail': image.get('large_url') or image.get('url'),
113 'timestamp': parse_iso8601(attributes.get('published_at')),
114 'like_count': int_or_none(attributes.get('like_count')),
115 'comment_count': int_or_none(attributes.get('comment_count')),
118 for i in post.get('included', []):
119 i_type = i.get('type')
120 if i_type == 'media':
121 media_attributes = i.get('attributes') or {}
122 download_url = media_attributes.get('download_url')
123 ext = mimetype2ext(media_attributes.get('mimetype'))
124 if download_url and ext in KNOWN_EXTENSIONS:
127 'filesize': int_or_none(media_attributes.get('size_bytes')),
130 elif i_type == 'user':
131 user_attributes = i.get('attributes')
134 'uploader': user_attributes.get('full_name'),
135 'uploader_id': str_or_none(i.get('id')),
136 'uploader_url': user_attributes.get('url'),
139 if not info.get('url'):
140 embed_url = try_get(attributes, lambda x: x['embed']['url'])
147 if not info.get('url'):
148 post_file = attributes['post_file']
149 ext = determine_ext(post_file.get('name'))
150 if ext in KNOWN_EXTENSIONS:
153 'url': post_file['url'],