Compare commits

...

7 Commits

Author SHA1 Message Date
Chris Putnam
b6d50cb39f
Merge 35f987487b1dfde08b29855faeaff78d2d237d65 into da7223d4aa42ff9fc680b0951d043dd03cec2d30 2025-03-22 07:11:22 +08:00
Chris Putnam
35f987487b convention fix, simplified login request 2021-01-22 14:33:26 -06:00
Chris Putnam
271426aa58 use mp4 extension for patreon-hosted videos 2021-01-22 01:45:23 -06:00
Chris Putnam
456987e022 fixing embarrassing lint issues 2021-01-22 01:15:51 -06:00
Chris Putnam
f6abfd2627 adding test case for paywalled patreon-hosted video 2021-01-22 01:11:04 -06:00
Chris Putnam
7f0a28e925 code style fixes 2021-01-22 00:54:47 -06:00
Chris Putnam
8c5e9e0213 [patreon] add support for patreon-hosted video embeds 2021-01-22 00:49:35 -06:00

View File

@ -1,10 +1,14 @@
# coding: utf-8
from __future__ import unicode_literals
import json
import re
from .common import InfoExtractor
from ..utils import (
clean_html,
determine_ext,
ExtractorError,
int_or_none,
KNOWN_EXTENSIONS,
mimetype2ext,
@ -16,6 +20,7 @@ from ..utils import (
class PatreonIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
_NETRC_MACHINE = 'patreon'
_TESTS = [{
'url': 'http://www.patreon.com/creation?hid=743933',
'md5': 'e25505eec1053a6e6813b8ed369875cc',
@ -63,34 +68,40 @@ class PatreonIE(InfoExtractor):
}, {
'url': 'https://www.patreon.com/posts/743933',
'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):
username, password = self._get_login_info()
if username is None:
return
login_form = {
'redirectUrl': 'http://www.patreon.com/',
'email': username,
'password': password,
'data': {
'type': 'user',
'attributes': {
'email': username,
'password': password
},
'relationships': {}
}
}
request = sanitized_Request(
'https://www.patreon.com/processLogin',
compat_urllib_parse_urlencode(login_form).encode('utf-8')
)
login_page = self._download_webpage(request, None, note='Logging in')
login_page = self._download_webpage(
'https://www.patreon.com/api/login',
video_id=None,
note='Logging in',
data=json.dumps(login_form).encode('ascii'))
if re.search(r'onLoginFailed', login_page):
raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
def _real_initialize(self):
self._login()
'''
def _real_extract(self, url):
video_id = self._match_id(url)
@ -146,11 +157,18 @@ class PatreonIE(InfoExtractor):
if not info.get('url'):
post_file = attributes['post_file']
ext = determine_ext(post_file.get('name'))
if ext in KNOWN_EXTENSIONS:
if post_file.get('name') == 'video':
# single video embed
info.update({
'ext': ext,
'ext': 'mp4',
'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