2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..utils import js_to_json
8 class PatreonIE(InfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?patreon\.com/creation\?hid=(?P<id>[^&#]+)'
12 'url': 'http://www.patreon.com/creation?hid=743933',
13 'md5': 'e25505eec1053a6e6813b8ed369875cc',
17 'title': 'Episode 166: David Smalley of Dogma Debate',
18 'uploader': 'Cognitive Dissonance Podcast',
19 'thumbnail': 're:^https?://.*$',
23 'url': 'http://www.patreon.com/creation?hid=754133',
24 'md5': '3eb09345bf44bf60451b8b0b81759d0a',
28 'title': 'CD 167 Extra',
29 'uploader': 'Cognitive Dissonance Podcast',
30 'thumbnail': 're:^https?://.*$',
34 'url': 'https://www.patreon.com/creation?hid=1682498',
38 'title': 'I\'m on Patreon!',
39 'uploader': 'TraciJHines',
40 'thumbnail': 're:^https?://.*$',
41 'upload_date': '20150211',
42 'description': 'md5:c5a706b1f687817a3de09db1eb93acd4',
43 'uploader_id': 'TraciJHines',
47 'skip_download': True,
52 # Currently Patreon exposes download URL via hidden CSS, so login is not
53 # needed. Keeping this commented for when this inevitably changes.
56 (username, password) = self._get_login_info()
61 'redirectUrl': 'http://www.patreon.com/',
66 request = sanitized_Request(
67 'https://www.patreon.com/processLogin',
68 compat_urllib_parse.urlencode(login_form).encode('utf-8')
70 login_page = self._download_webpage(request, None, note='Logging in as %s' % username)
72 if re.search(r'onLoginFailed', login_page):
73 raise ExtractorError('Unable to login, incorrect username and/or password', expected=True)
75 def _real_initialize(self):
79 def _real_extract(self, url):
80 video_id = self._match_id(url)
81 webpage = self._download_webpage(url, video_id)
82 title = self._og_search_title(webpage).strip()
84 attach_fn = self._html_search_regex(
85 r'<div class="attach"><a target="_blank" href="([^"]+)">',
86 webpage, 'attachment URL', default=None)
87 embed = self._html_search_regex(
88 r'<div[^>]+id="watchCreation"[^>]*>\s*<iframe[^>]+src="([^"]+)"',
89 webpage, 'embedded URL', default=None)
91 if attach_fn is not None:
92 video_url = 'http://www.patreon.com' + attach_fn
93 thumbnail = self._og_search_thumbnail(webpage)
94 uploader = self._html_search_regex(
95 r'<strong>(.*?)</strong> is creating', webpage, 'uploader')
96 elif embed is not None:
97 return self.url_result(embed)
99 playlist = self._parse_json(self._search_regex(
100 r'(?s)new\s+jPlayerPlaylist\(\s*\{\s*[^}]*},\s*(\[.*?,?\s*\])',
101 webpage, 'playlist JSON'),
102 video_id, transform_source=js_to_json)
104 video_url = self._proto_relative_url(data['mp3'])
105 thumbnail = self._proto_relative_url(data.get('cover'))
106 uploader = data.get('artist')
113 'uploader': uploader,
114 'thumbnail': thumbnail,