]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/voxmedia.py
[iwara] Improve extraction
[youtube-dl] / youtube_dl / extractor / voxmedia.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from .once import OnceIE
6 from ..compat import compat_urllib_parse_unquote
7 from ..utils import ExtractorError
8
9
10 class VoxMediaVolumeIE(OnceIE):
11     _VALID_URL = r'https?://volume\.vox-cdn\.com/embed/(?P<id>[0-9a-f]{9})'
12
13     def _real_extract(self, url):
14         video_id = self._match_id(url)
15         webpage = self._download_webpage(url, video_id)
16         video_data = self._parse_json(self._search_regex(
17             r'Volume\.createVideo\(({.+})\s*,\s*{.*}\s*,\s*\[.*\]\s*,\s*{.*}\);', webpage, 'video data'), video_id)
18         for provider_video_type in ('ooyala', 'youtube', 'brightcove'):
19             provider_video_id = video_data.get('%s_id' % provider_video_type)
20             if not provider_video_id:
21                 continue
22             info = {
23                 'id': video_id,
24                 'title': video_data.get('title_short'),
25                 'description': video_data.get('description_long') or video_data.get('description_short'),
26                 'thumbnail': video_data.get('brightcove_thumbnail')
27             }
28             if provider_video_type == 'brightcove':
29                 info['formats'] = self._extract_once_formats(provider_video_id)
30                 self._sort_formats(info['formats'])
31             else:
32                 info.update({
33                     '_type': 'url_transparent',
34                     'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
35                     'ie_key': provider_video_type.capitalize(),
36                 })
37             return info
38         raise ExtractorError('Unable to find provider video id')
39
40
41 class VoxMediaIE(InfoExtractor):
42     _VALID_URL = r'https?://(?:www\.)?(?:(?:theverge|vox|sbnation|eater|polygon|curbed|racked)\.com|recode\.net)/(?:[^/]+/)*(?P<id>[^/?]+)'
43     _TESTS = [{
44         'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
45         'info_dict': {
46             'id': '11eXZobjrG8DCSTgrNjVinU-YmmdYjhe',
47             'ext': 'mp4',
48             'title': 'Google\'s new material design direction',
49             'description': 'md5:2f44f74c4d14a1f800ea73e1c6832ad2',
50         },
51         'params': {
52             # m3u8 download
53             'skip_download': True,
54         },
55         'add_ie': ['Ooyala'],
56     }, {
57         # data-ooyala-id
58         'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
59         'md5': 'd744484ff127884cd2ba09e3fa604e4b',
60         'info_dict': {
61             'id': 'RkZXU4cTphOCPDMZg5oEounJyoFI0g-B',
62             'ext': 'mp4',
63             'title': 'The Nexus 6: hands-on with Google\'s phablet',
64             'description': 'md5:87a51fe95ff8cea8b5bdb9ac7ae6a6af',
65         },
66         'add_ie': ['Ooyala'],
67         'skip': 'Video Not Found',
68     }, {
69         # volume embed
70         'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
71         'info_dict': {
72             'id': 'wydzk3dDpmRz7PQoXRsTIX6XTkPjYL0b',
73             'ext': 'mp4',
74             'title': 'The new frontier of LGBTQ civil rights, explained',
75             'description': 'md5:0dc58e94a465cbe91d02950f770eb93f',
76         },
77         'params': {
78             # m3u8 download
79             'skip_download': True,
80         },
81         'add_ie': ['Ooyala'],
82     }, {
83         # youtube embed
84         'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
85         'md5': '83b3080489fb103941e549352d3e0977',
86         'info_dict': {
87             'id': 'FcNHTJU1ufM',
88             'ext': 'mp4',
89             'title': 'How "the robot" became the greatest novelty dance of all time',
90             'description': 'md5:b081c0d588b8b2085870cda55e6da176',
91             'upload_date': '20160324',
92             'uploader_id': 'voxdotcom',
93             'uploader': 'Vox',
94         },
95         'add_ie': ['Youtube'],
96     }, {
97         # SBN.VideoLinkset.entryGroup multiple ooyala embeds
98         'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
99         'info_dict': {
100             'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
101             'title': '25 lies you will tell yourself on National Signing Day',
102             'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
103         },
104         'playlist': [{
105             'md5': '721fededf2ab74ae4176c8c8cbfe092e',
106             'info_dict': {
107                 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
108                 'ext': 'mp4',
109                 'title': 'Buddy Hield vs Steph Curry (and the world)',
110                 'description': 'Let’s dissect only the most important Final Four storylines.',
111             },
112         }, {
113             'md5': 'bf0c5cc115636af028be1bab79217ea9',
114             'info_dict': {
115                 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
116                 'ext': 'mp4',
117                 'title': 'Chasing Cinderella 2016: Syracuse basketball',
118                 'description': 'md5:e02d56b026d51aa32c010676765a690d',
119             },
120         }],
121     }, {
122         # volume embed, Brightcove Once
123         'url': 'https://www.recode.net/2014/6/17/11628066/post-post-pc-ceo-the-full-code-conference-video-of-microsofts-satya',
124         'md5': '01571a896281f77dc06e084138987ea2',
125         'info_dict': {
126             'id': '1231c973d',
127             'ext': 'mp4',
128             'title': 'Post-Post-PC CEO: The Full Code Conference Video of Microsoft\'s Satya Nadella',
129             'description': 'The longtime veteran was chosen earlier this year as the software giant\'s third leader in its history.',
130         },
131         'add_ie': ['VoxMediaVolume'],
132     }]
133
134     def _real_extract(self, url):
135         display_id = self._match_id(url)
136         webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
137
138         def create_entry(provider_video_id, provider_video_type, title=None, description=None):
139             video_url = {
140                 'youtube': '%s',
141                 'ooyala': 'ooyala:%s',
142                 'volume': 'http://volume.vox-cdn.com/embed/%s',
143             }[provider_video_type] % provider_video_id
144             return {
145                 '_type': 'url_transparent',
146                 'url': video_url,
147                 'title': title or self._og_search_title(webpage),
148                 'description': description or self._og_search_description(webpage),
149             }
150
151         entries = []
152         entries_data = self._search_regex([
153             r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
154             r'var\s+entry\s*=\s*({.+});',
155             r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
156         ], webpage, 'video data', default=None)
157         if entries_data:
158             entries_data = self._parse_json(entries_data, display_id)
159             if isinstance(entries_data, dict):
160                 entries_data = [entries_data]
161             for video_data in entries_data:
162                 provider_video_id = video_data.get('provider_video_id')
163                 provider_video_type = video_data.get('provider_video_type')
164                 if provider_video_id and provider_video_type:
165                     entries.append(create_entry(
166                         provider_video_id, provider_video_type,
167                         video_data.get('title'), video_data.get('description')))
168
169         provider_video_id = self._search_regex(
170             r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
171         if provider_video_id:
172             entries.append(create_entry(provider_video_id, 'ooyala'))
173
174         volume_uuid = self._search_regex(
175             r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
176         if volume_uuid:
177             entries.append(create_entry(volume_uuid, 'volume'))
178
179         if len(entries) == 1:
180             return entries[0]
181         else:
182             return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))