This commit is contained in:
Chris Putnam 2024-08-21 22:33:17 -04:00 committed by GitHub
commit 9de7d414ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,10 +1,14 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import json
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
clean_html, clean_html,
determine_ext, determine_ext,
ExtractorError,
int_or_none, int_or_none,
KNOWN_EXTENSIONS, KNOWN_EXTENSIONS,
mimetype2ext, mimetype2ext,
@ -16,6 +20,7 @@ from ..utils import (
class PatreonIE(InfoExtractor): class PatreonIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)' _VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
_NETRC_MACHINE = 'patreon'
_TESTS = [{ _TESTS = [{
'url': 'http://www.patreon.com/creation?hid=743933', 'url': 'http://www.patreon.com/creation?hid=743933',
'md5': 'e25505eec1053a6e6813b8ed369875cc', 'md5': 'e25505eec1053a6e6813b8ed369875cc',
@ -63,34 +68,40 @@ class PatreonIE(InfoExtractor):
}, { }, {
'url': 'https://www.patreon.com/posts/743933', 'url': 'https://www.patreon.com/posts/743933',
'only_matching': True, 'only_matching': True,
}, {
# embedded patreon-hosted video, paywalled
'url': 'https://www.patreon.com/posts/terps-part-1-46181905',
'only_matching': True,
'skip': 'Patron-only content'
}] }]
# Currently Patreon exposes download URL via hidden CSS, so login is not
# needed. Keeping this commented for when this inevitably changes.
'''
def _login(self): def _login(self):
username, password = self._get_login_info() username, password = self._get_login_info()
if username is None: if username is None:
return return
login_form = { login_form = {
'redirectUrl': 'http://www.patreon.com/', 'data': {
'email': username, 'type': 'user',
'password': password, 'attributes': {
'email': username,
'password': password
},
'relationships': {}
}
} }
request = sanitized_Request( login_page = self._download_webpage(
'https://www.patreon.com/processLogin', 'https://www.patreon.com/api/login',
compat_urllib_parse_urlencode(login_form).encode('utf-8') video_id=None,
) note='Logging in',
login_page = self._download_webpage(request, None, note='Logging in') data=json.dumps(login_form).encode('ascii'))
if re.search(r'onLoginFailed', login_page): if re.search(r'onLoginFailed', login_page):
raise ExtractorError('Unable to login, incorrect username and/or password', expected=True) raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
def _real_initialize(self): def _real_initialize(self):
self._login() self._login()
'''
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
@ -146,11 +157,18 @@ class PatreonIE(InfoExtractor):
if not info.get('url'): if not info.get('url'):
post_file = attributes['post_file'] post_file = attributes['post_file']
ext = determine_ext(post_file.get('name')) if post_file.get('name') == 'video':
if ext in KNOWN_EXTENSIONS: # single video embed
info.update({ info.update({
'ext': ext, 'ext': 'mp4',
'url': post_file['url'], 'url': post_file['url'],
}) })
else:
# video is attached as a file
ext = determine_ext(post_file.get('name'))
if ext in KNOWN_EXTENSIONS:
info.update({
'ext': ext,
'url': post_file['url'],
})
return info return info