]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/kickstarter.py
Update Standards-Version to 3.9.8 (no changes required).
[youtubedl] / youtube_dl / extractor / kickstarter.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import smuggle_url
6
7
8 class KickStarterIE(InfoExtractor):
9 _VALID_URL = r'https?://www\.kickstarter\.com/projects/(?P<id>[^/]*)/.*'
10 _TESTS = [{
11 'url': 'https://www.kickstarter.com/projects/1404461844/intersection-the-story-of-josh-grant/description',
12 'md5': 'c81addca81327ffa66c642b5d8b08cab',
13 'info_dict': {
14 'id': '1404461844',
15 'ext': 'mp4',
16 'title': 'Intersection: The Story of Josh Grant by Kyle Cowling',
17 'description': (
18 'A unique motocross documentary that examines the '
19 'life and mind of one of sports most elite athletes: Josh Grant.'
20 ),
21 },
22 }, {
23 'note': 'Embedded video (not using the native kickstarter video service)',
24 'url': 'https://www.kickstarter.com/projects/597507018/pebble-e-paper-watch-for-iphone-and-android/posts/659178',
25 'info_dict': {
26 'id': '78704821',
27 'ext': 'mp4',
28 'uploader_id': 'pebble',
29 'uploader': 'Pebble Technology',
30 'title': 'Pebble iOS Notifications',
31 },
32 'add_ie': ['Vimeo'],
33 }, {
34 'url': 'https://www.kickstarter.com/projects/1420158244/power-drive-2000/widget/video.html',
35 'info_dict': {
36 'id': '1420158244',
37 'ext': 'mp4',
38 'title': 'Power Drive 2000',
39 },
40 'expected_warnings': ['OpenGraph description'],
41 }]
42
43 def _real_extract(self, url):
44 video_id = self._match_id(url)
45 webpage = self._download_webpage(url, video_id)
46
47 title = self._html_search_regex(
48 r'<title>\s*(.*?)(?:\s*&mdash;\s*Kickstarter)?\s*</title>',
49 webpage, 'title')
50 video_url = self._search_regex(
51 r'data-video-url="(.*?)"',
52 webpage, 'video URL', default=None)
53 if video_url is None: # No native kickstarter, look for embedded videos
54 return {
55 '_type': 'url_transparent',
56 'ie_key': 'Generic',
57 'url': smuggle_url(url, {'to_generic': True}),
58 'title': title,
59 }
60
61 thumbnail = self._og_search_thumbnail(webpage, default=None)
62 if thumbnail is None:
63 thumbnail = self._html_search_regex(
64 r'<img[^>]+class="[^"]+\s*poster\s*[^"]+"[^>]+src="([^"]+)"',
65 webpage, 'thumbnail image', fatal=False)
66 return {
67 'id': video_id,
68 'url': video_url,
69 'title': title,
70 'description': self._og_search_description(webpage),
71 'thumbnail': thumbnail,
72 }