2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from .vimeo
import VimeoIE
7 from ..compat
import compat_urllib_parse_unquote
21 class PatreonIE(InfoExtractor
):
22 _VALID_URL
= r
'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
24 'url': 'http://www.patreon.com/creation?hid=743933',
25 'md5': 'e25505eec1053a6e6813b8ed369875cc',
29 'title': 'Episode 166: David Smalley of Dogma Debate',
30 'description': 'md5:713b08b772cd6271b9f3906683cfacdf',
31 'uploader': 'Cognitive Dissonance Podcast',
32 'thumbnail': 're:^https?://.*$',
33 'timestamp': 1406473987,
34 'upload_date': '20140727',
35 'uploader_id': '87145',
38 'url': 'http://www.patreon.com/creation?hid=754133',
39 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
43 'title': 'CD 167 Extra',
44 'uploader': 'Cognitive Dissonance Podcast',
45 'thumbnail': 're:^https?://.*$',
47 'skip': 'Patron-only content',
49 'url': 'https://www.patreon.com/creation?hid=1682498',
53 'title': 'I\'m on Patreon!',
54 'uploader': 'TraciJHines',
55 'thumbnail': 're:^https?://.*$',
56 'upload_date': '20150211',
57 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
58 'uploader_id': 'TraciJHines',
62 'skip_download': True,
65 'url': 'https://www.patreon.com/posts/episode-166-of-743933',
66 'only_matching': True,
68 'url': 'https://www.patreon.com/posts/743933',
69 'only_matching': True,
71 'url': 'https://www.patreon.com/posts/kitchen-as-seen-51706779',
72 'md5': '96656690071f6d64895866008484251b',
76 'title': 'KITCHEN AS SEEN ON DEEZ NUTS EXTENDED!',
77 'uploader': 'Cold Ones',
78 'thumbnail': 're:^https?://.*$',
79 'upload_date': '20210526',
80 'description': 'md5:557a409bd79d3898689419094934ba79',
81 'uploader_id': '14936315',
83 'skip': 'Patron-only content'
86 # Currently Patreon exposes download URL via hidden CSS, so login is not
87 # needed. Keeping this commented for when this inevitably changes.
90 username, password = self._get_login_info()
95 'redirectUrl': 'http://www.patreon.com/',
100 request = sanitized_Request(
101 'https://www.patreon.com/processLogin',
102 compat_urllib_parse_urlencode(login_form).encode('utf-8')
104 login_page = self._download_webpage(request, None, note='Logging in')
106 if re.search(r'onLoginFailed', login_page):
107 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
109 def _real_initialize(self):
113 def _real_extract(self
, url
):
114 video_id
= self
._match
_id
(url
)
115 post
= self
._download
_json
(
116 'https://www.patreon.com/api/posts/' + video_id
, video_id
, query
={
117 'fields[media]': 'download_url,mimetype,size_bytes',
118 'fields[post]': 'comment_count,content,embed,image,like_count,post_file,published_at,title',
119 'fields[user]': 'full_name,url',
120 'json-api-use-default-includes': 'false',
121 'include': 'media,user',
123 attributes
= post
['data']['attributes']
124 title
= attributes
['title'].strip()
125 image
= attributes
.get('image') or {}
129 'description': clean_html(attributes
.get('content')),
130 'thumbnail': image
.get('large_url') or image
.get('url'),
131 'timestamp': parse_iso8601(attributes
.get('published_at')),
132 'like_count': int_or_none(attributes
.get('like_count')),
133 'comment_count': int_or_none(attributes
.get('comment_count')),
136 for i
in post
.get('included', []):
137 i_type
= i
.get('type')
138 if i_type
== 'media':
139 media_attributes
= i
.get('attributes') or {}
140 download_url
= media_attributes
.get('download_url')
141 ext
= mimetype2ext(media_attributes
.get('mimetype'))
142 if download_url
and ext
in KNOWN_EXTENSIONS
:
145 'filesize': int_or_none(media_attributes
.get('size_bytes')),
148 elif i_type
== 'user':
149 user_attributes
= i
.get('attributes')
152 'uploader': user_attributes
.get('full_name'),
153 'uploader_id': str_or_none(i
.get('id')),
154 'uploader_url': user_attributes
.get('url'),
157 if not info
.get('url'):
158 # handle Vimeo embeds
159 if try_get(attributes
, lambda x
: x
['embed']['provider']) == 'Vimeo':
160 embed_html
= try_get(attributes
, lambda x
: x
['embed']['html'])
161 v_url
= url_or_none(compat_urllib_parse_unquote(
162 self
._search
_regex
(r
'src=(https%3A%2F%2Fplayer\.vimeo\.com.+)%3F', embed_html
, 'vimeo url', fatal
=False)))
165 '_type': 'url_transparent',
166 'url': VimeoIE
._smuggle
_referrer
(v_url
, 'https://patreon.com'),
170 if not info
.get('url'):
171 embed_url
= try_get(attributes
, lambda x
: x
['embed']['url'])
178 if not info
.get('url'):
179 post_file
= attributes
['post_file']
180 ext
= determine_ext(post_file
.get('name'))
181 if ext
in KNOWN_EXTENSIONS
:
184 'url': post_file
['url'],