2 from __future__ import unicode_literals
7 from .common import InfoExtractor
13 class PatreonIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?patreon\.com/creation\?hid=(?P<id>[^&#]+)'
17 'url': 'http://www.patreon.com/creation?hid=743933',
18 'md5': 'e25505eec1053a6e6813b8ed369875cc',
22 'title': 'Episode 166: David Smalley of Dogma Debate',
23 'uploader': 'Cognitive Dissonance Podcast',
24 'thumbnail': 're:^https?://.*$',
28 'url': 'http://www.patreon.com/creation?hid=754133',
29 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
33 'title': 'CD 167 Extra',
34 'uploader': 'Cognitive Dissonance Podcast',
35 'thumbnail': 're:^https?://.*$',
40 # Currently Patreon exposes download URL via hidden CSS, so login is not
41 # needed. Keeping this commented for when this inevitably changes.
44 (username, password) = self._get_login_info()
49 'redirectUrl': 'http://www.patreon.com/',
54 request = compat_urllib_request.Request(
55 'https://www.patreon.com/processLogin',
56 compat_urllib_parse.urlencode(login_form).encode('utf-8')
58 login_page = self._download_webpage(request, None, note='Logging in as %s' % username)
60 if re.search(r'onLoginFailed', login_page):
61 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
63 def _real_initialize(self):
67 def _real_extract(self, url):
68 video_id = self._match_id(url)
69 webpage = self._download_webpage(url, video_id)
70 title = self._og_search_title(webpage).strip()
72 attach_fn = self._html_search_regex(
73 r'<div class="attach"><a target="_blank" href="([^"]+)">',
74 webpage, 'attachment URL', default=None)
75 if attach_fn is not None:
76 video_url = 'http://www.patreon.com' + attach_fn
77 thumbnail = self._og_search_thumbnail(webpage)
78 uploader = self._html_search_regex(
79 r'<strong>(.*?)</strong> is creating', webpage, 'uploader')
81 playlist = self._parse_json(self._search_regex(
82 r'(?s)new\s+jPlayerPlaylist\(\s*\{\s*[^}]*},\s*(\[.*?,?\s*\])',
83 webpage, 'playlist JSON'),
84 video_id, transform_source=js_to_json)
86 video_url = self._proto_relative_url(data['mp3'])
87 thumbnail = self._proto_relative_url(data.get('cover'))
88 uploader = data.get('artist')
96 'thumbnail': thumbnail,