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.
91 def _perform_login(self, username, password):
93 'redirectUrl': 'http://www.patreon.com/',
98 request = sanitized_Request(
99 'https://www.patreon.com/processLogin',
100 compat_urllib_parse_urlencode(login_form).encode('utf-8')
102 login_page = self._download_webpage(request, None, note='Logging in')
104 if re.search(r'onLoginFailed', login_page):
105 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
109 def _real_extract(self
, url
):
110 video_id
= self
._match
_id
(url
)
111 post
= self
._download
_json
(
112 'https://www.patreon.com/api/posts/' + video_id
, video_id
, query
={
113 'fields[media]': 'download_url,mimetype,size_bytes',
114 'fields[post]': 'comment_count,content,embed,image,like_count,post_file,published_at,title',
115 'fields[user]': 'full_name,url',
116 'json-api-use-default-includes': 'false',
117 'include': 'media,user',
119 attributes
= post
['data']['attributes']
120 title
= attributes
['title'].strip()
121 image
= attributes
.get('image') or {}
125 'description': clean_html(attributes
.get('content')),
126 'thumbnail': image
.get('large_url') or image
.get('url'),
127 'timestamp': parse_iso8601(attributes
.get('published_at')),
128 'like_count': int_or_none(attributes
.get('like_count')),
129 'comment_count': int_or_none(attributes
.get('comment_count')),
132 for i
in post
.get('included', []):
133 i_type
= i
.get('type')
134 if i_type
== 'media':
135 media_attributes
= i
.get('attributes') or {}
136 download_url
= media_attributes
.get('download_url')
137 ext
= mimetype2ext(media_attributes
.get('mimetype'))
138 if download_url
and ext
in KNOWN_EXTENSIONS
:
141 'filesize': int_or_none(media_attributes
.get('size_bytes')),
144 elif i_type
== 'user':
145 user_attributes
= i
.get('attributes')
148 'uploader': user_attributes
.get('full_name'),
149 'uploader_id': str_or_none(i
.get('id')),
150 'uploader_url': user_attributes
.get('url'),
153 if not info
.get('url'):
154 # handle Vimeo embeds
155 if try_get(attributes
, lambda x
: x
['embed']['provider']) == 'Vimeo':
156 embed_html
= try_get(attributes
, lambda x
: x
['embed']['html'])
157 v_url
= url_or_none(compat_urllib_parse_unquote(
158 self
._search
_regex
(r
'(https(?:%3A%2F%2F|://)player\.vimeo\.com.+app_id(?:=|%3D)+\d+)', embed_html
, 'vimeo url', fatal
=False)))
161 '_type': 'url_transparent',
162 'url': VimeoIE
._smuggle
_referrer
(v_url
, 'https://patreon.com'),
166 if not info
.get('url'):
167 embed_url
= try_get(attributes
, lambda x
: x
['embed']['url'])
174 if not info
.get('url'):
175 post_file
= attributes
['post_file']
176 ext
= determine_ext(post_file
.get('name'))
177 if ext
in KNOWN_EXTENSIONS
:
180 'url': post_file
['url'],
186 class PatreonUserIE(InfoExtractor
):
188 _VALID_URL
= r
'https?://(?:www\.)?patreon\.com/(?!rss)(?P<id>[-\w]+)'
191 'url': 'https://www.patreon.com/dissonancepod/',
193 'title': 'dissonancepod',
195 'playlist_mincount': 68,
196 'expected_warnings': 'Post not viewable by current user! Skipping!',
198 'url': 'https://www.patreon.com/dissonancepod/posts',
199 'only_matching': True
203 def suitable(cls
, url
):
204 return False if PatreonIE
.suitable(url
) else super(PatreonUserIE
, cls
).suitable(url
)
206 def _entries(self
, campaign_id
, user_id
):
209 'fields[campaign]': 'show_audio_post_download_links,name,url',
210 'fields[post]': 'current_user_can_view,embed,image,is_paid,post_file,published_at,patreon_url,url,post_type,thumbnail_url,title',
211 'filter[campaign_id]': campaign_id
,
212 'filter[is_draft]': 'false',
213 'sort': '-published_at',
214 'json-api-version': 1.0,
215 'json-api-use-default-includes': 'false',
218 for page
in itertools
.count(1):
220 params
.update({'page[cursor]': cursor}
if cursor
else {})
221 posts_json
= self
._download
_json
('https://www.patreon.com/api/posts', user_id
, note
='Downloading posts page %d' % page
, query
=params
, headers
={'Cookie': '.'}
)
223 cursor
= try_get(posts_json
, lambda x
: x
['meta']['pagination']['cursors']['next'])
225 for post
in posts_json
.get('data') or []:
226 yield self
.url_result(url_or_none(try_get(post
, lambda x
: x
['attributes']['patreon_url'])), 'Patreon')
231 def _real_extract(self
, url
):
233 user_id
= self
._match
_id
(url
)
234 webpage
= self
._download
_webpage
(url
, user_id
, headers
={'Cookie': '.'}
)
235 campaign_id
= self
._search
_regex
(r
'https://www.patreon.com/api/campaigns/(\d+)/?', webpage
, 'Campaign ID')
236 return self
.playlist_result(self
._entries
(campaign_id
, user_id
), playlist_title
=user_id
)