2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from .vimeo
import VimeoIE
9 from ..compat
import compat_urllib_parse_unquote
23 class PatreonIE(InfoExtractor
):
24 _VALID_URL
= r
'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
26 'url': 'http://www.patreon.com/creation?hid=743933',
27 'md5': 'e25505eec1053a6e6813b8ed369875cc',
31 'title': 'Episode 166: David Smalley of Dogma Debate',
32 'description': 'md5:713b08b772cd6271b9f3906683cfacdf',
33 'uploader': 'Cognitive Dissonance Podcast',
34 'thumbnail': 're:^https?://.*$',
35 'timestamp': 1406473987,
36 'upload_date': '20140727',
37 'uploader_id': '87145',
40 'url': 'http://www.patreon.com/creation?hid=754133',
41 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
45 'title': 'CD 167 Extra',
46 'uploader': 'Cognitive Dissonance Podcast',
47 'thumbnail': 're:^https?://.*$',
49 'skip': 'Patron-only content',
51 'url': 'https://www.patreon.com/creation?hid=1682498',
55 'title': 'I\'m on Patreon!',
56 'uploader': 'TraciJHines',
57 'thumbnail': 're:^https?://.*$',
58 'upload_date': '20150211',
59 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
60 'uploader_id': 'TraciJHines',
64 'skip_download': True,
67 'url': 'https://www.patreon.com/posts/episode-166-of-743933',
68 'only_matching': True,
70 'url': 'https://www.patreon.com/posts/743933',
71 'only_matching': True,
73 'url': 'https://www.patreon.com/posts/kitchen-as-seen-51706779',
74 'md5': '96656690071f6d64895866008484251b',
78 'title': 'KITCHEN AS SEEN ON DEEZ NUTS EXTENDED!',
79 'uploader': 'Cold Ones',
80 'thumbnail': 're:^https?://.*$',
81 'upload_date': '20210526',
82 'description': 'md5:557a409bd79d3898689419094934ba79',
83 'uploader_id': '14936315',
85 'skip': 'Patron-only content'
88 # Currently Patreon exposes download URL via hidden CSS, so login is not
89 # needed. Keeping this commented for when this inevitably changes.
92 username, password = self._get_login_info()
97 'redirectUrl': 'http://www.patreon.com/',
102 request = sanitized_Request(
103 'https://www.patreon.com/processLogin',
104 compat_urllib_parse_urlencode(login_form).encode('utf-8')
106 login_page = self._download_webpage(request, None, note='Logging in')
108 if re.search(r'onLoginFailed', login_page):
109 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
111 def _real_initialize(self):
115 def _real_extract(self
, url
):
116 video_id
= self
._match
_id
(url
)
117 post
= self
._download
_json
(
118 'https://www.patreon.com/api/posts/' + video_id
, video_id
, query
={
119 'fields[media]': 'download_url,mimetype,size_bytes',
120 'fields[post]': 'comment_count,content,embed,image,like_count,post_file,published_at,title',
121 'fields[user]': 'full_name,url',
122 'json-api-use-default-includes': 'false',
123 'include': 'media,user',
125 attributes
= post
['data']['attributes']
126 title
= attributes
['title'].strip()
127 image
= attributes
.get('image') or {}
131 'description': clean_html(attributes
.get('content')),
132 'thumbnail': image
.get('large_url') or image
.get('url'),
133 'timestamp': parse_iso8601(attributes
.get('published_at')),
134 'like_count': int_or_none(attributes
.get('like_count')),
135 'comment_count': int_or_none(attributes
.get('comment_count')),
138 for i
in post
.get('included', []):
139 i_type
= i
.get('type')
140 if i_type
== 'media':
141 media_attributes
= i
.get('attributes') or {}
142 download_url
= media_attributes
.get('download_url')
143 ext
= mimetype2ext(media_attributes
.get('mimetype'))
144 if download_url
and ext
in KNOWN_EXTENSIONS
:
147 'filesize': int_or_none(media_attributes
.get('size_bytes')),
150 elif i_type
== 'user':
151 user_attributes
= i
.get('attributes')
154 'uploader': user_attributes
.get('full_name'),
155 'uploader_id': str_or_none(i
.get('id')),
156 'uploader_url': user_attributes
.get('url'),
159 if not info
.get('url'):
160 # handle Vimeo embeds
161 if try_get(attributes
, lambda x
: x
['embed']['provider']) == 'Vimeo':
162 embed_html
= try_get(attributes
, lambda x
: x
['embed']['html'])
163 v_url
= url_or_none(compat_urllib_parse_unquote(
164 self
._search
_regex
(r
'(https(?:%3A%2F%2F|://)player\.vimeo\.com.+app_id(?:=|%3D)+\d+)', embed_html
, 'vimeo url', fatal
=False)))
167 '_type': 'url_transparent',
168 'url': VimeoIE
._smuggle
_referrer
(v_url
, 'https://patreon.com'),
172 if not info
.get('url'):
173 embed_url
= try_get(attributes
, lambda x
: x
['embed']['url'])
180 if not info
.get('url'):
181 post_file
= attributes
['post_file']
182 ext
= determine_ext(post_file
.get('name'))
183 if ext
in KNOWN_EXTENSIONS
:
186 'url': post_file
['url'],
192 class PatreonUserIE(InfoExtractor
):
194 _VALID_URL
= r
'https?://(?:www\.)?patreon\.com/(?P<id>[-_\w\d]+)/?(?:posts/?)?'
197 'url': 'https://www.patreon.com/dissonancepod/',
199 'title': 'dissonancepod',
201 'playlist_mincount': 68,
202 'expected_warnings': 'Post not viewable by current user! Skipping!',
204 'url': 'https://www.patreon.com/dissonancepod/posts',
205 'only_matching': True
209 def suitable(cls
, url
):
210 return False if PatreonIE
.suitable(url
) else super(PatreonUserIE
, cls
).suitable(url
)
212 def _entries(self
, campaign_id
, user_id
):
215 'fields[campaign]': 'show_audio_post_download_links,name,url',
216 'fields[post]': 'current_user_can_view,embed,image,is_paid,post_file,published_at,patreon_url,url,post_type,thumbnail_url,title',
217 'filter[campaign_id]': campaign_id
,
218 'filter[is_draft]': 'false',
219 'sort': '-published_at',
220 'json-api-version': 1.0,
221 'json-api-use-default-includes': 'false',
224 for page
in itertools
.count(1):
226 params
.update({'page[cursor]': cursor}
if cursor
else {})
227 posts_json
= self
._download
_json
('https://www.patreon.com/api/posts', user_id
, note
='Downloading posts page %d' % page
, query
=params
, headers
={'Cookie': '.'}
)
229 cursor
= try_get(posts_json
, lambda x
: x
['meta']['pagination']['cursors']['next'])
231 for post
in posts_json
.get('data') or []:
232 yield self
.url_result(url_or_none(try_get(post
, lambda x
: x
['attributes']['patreon_url'])), 'Patreon')
237 def _real_extract(self
, url
):
239 user_id
= self
._match
_id
(url
)
240 webpage
= self
._download
_webpage
(url
, user_id
, headers
={'Cookie': '.'}
)
241 campaign_id
= self
._search
_regex
(r
'https://www.patreon.com/api/campaigns/(\d+)/?', webpage
, 'Campaign ID')
242 return self
.playlist_result(self
._entries
(campaign_id
, user_id
), playlist_title
=user_id
)