]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/voxmedia.py
[buildserver] Fix buildserver and make python2 compatible
[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 ..compat import compat_urllib_parse_unquote
6
7
8 class VoxMediaIE(InfoExtractor):
9     _VALID_URL = r'https?://(?:www\.)?(?:theverge|vox|sbnation|eater|polygon|curbed|racked)\.com/(?:[^/]+/)*(?P<id>[^/?]+)'
10     _TESTS = [{
11         'url': 'http://www.theverge.com/2014/6/27/5849272/material-world-how-google-discovered-what-software-is-made-of',
12         'md5': '73856edf3e89a711e70d5cf7cb280b37',
13         'info_dict': {
14             'id': '11eXZobjrG8DCSTgrNjVinU-YmmdYjhe',
15             'ext': 'mp4',
16             'title': 'Google\'s new material design direction',
17             'description': 'md5:2f44f74c4d14a1f800ea73e1c6832ad2',
18         },
19         'add_ie': ['Ooyala'],
20     }, {
21         # data-ooyala-id
22         'url': 'http://www.theverge.com/2014/10/21/7025853/google-nexus-6-hands-on-photos-video-android-phablet',
23         'md5': 'd744484ff127884cd2ba09e3fa604e4b',
24         'info_dict': {
25             'id': 'RkZXU4cTphOCPDMZg5oEounJyoFI0g-B',
26             'ext': 'mp4',
27             'title': 'The Nexus 6: hands-on with Google\'s phablet',
28             'description': 'md5:87a51fe95ff8cea8b5bdb9ac7ae6a6af',
29         },
30         'add_ie': ['Ooyala'],
31     }, {
32         # volume embed
33         'url': 'http://www.vox.com/2016/3/31/11336640/mississippi-lgbt-religious-freedom-bill',
34         'md5': '375c483c5080ab8cd85c9c84cfc2d1e4',
35         'info_dict': {
36             'id': 'wydzk3dDpmRz7PQoXRsTIX6XTkPjYL0b',
37             'ext': 'mp4',
38             'title': 'The new frontier of LGBTQ civil rights, explained',
39             'description': 'md5:0dc58e94a465cbe91d02950f770eb93f',
40         },
41         'add_ie': ['Ooyala'],
42     }, {
43         # youtube embed
44         'url': 'http://www.vox.com/2016/3/24/11291692/robot-dance',
45         'md5': '83b3080489fb103941e549352d3e0977',
46         'info_dict': {
47             'id': 'FcNHTJU1ufM',
48             'ext': 'mp4',
49             'title': 'How "the robot" became the greatest novelty dance of all time',
50             'description': 'md5:b081c0d588b8b2085870cda55e6da176',
51             'upload_date': '20160324',
52             'uploader_id': 'voxdotcom',
53             'uploader': 'Vox',
54         },
55         'add_ie': ['Youtube'],
56     }, {
57         # SBN.VideoLinkset.entryGroup multiple ooyala embeds
58         'url': 'http://www.sbnation.com/college-football-recruiting/2015/2/3/7970291/national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
59         'info_dict': {
60             'id': 'national-signing-day-rationalizations-itll-be-ok-itll-be-ok',
61             'title': '25 lies you will tell yourself on National Signing Day',
62             'description': 'It\'s the most self-delusional time of the year, and everyone\'s gonna tell the same lies together!',
63         },
64         'playlist': [{
65             'md5': '721fededf2ab74ae4176c8c8cbfe092e',
66             'info_dict': {
67                 'id': 'p3cThlMjE61VDi_SD9JlIteSNPWVDBB9',
68                 'ext': 'mp4',
69                 'title': 'Buddy Hield vs Steph Curry (and the world)',
70                 'description': 'Let’s dissect only the most important Final Four storylines.',
71             },
72         }, {
73             'md5': 'bf0c5cc115636af028be1bab79217ea9',
74             'info_dict': {
75                 'id': 'BmbmVjMjE6esPHxdALGubTrouQ0jYLHj',
76                 'ext': 'mp4',
77                 'title': 'Chasing Cinderella 2016: Syracuse basketball',
78                 'description': 'md5:e02d56b026d51aa32c010676765a690d',
79             },
80         }],
81     }]
82
83     def _real_extract(self, url):
84         display_id = self._match_id(url)
85         webpage = compat_urllib_parse_unquote(self._download_webpage(url, display_id))
86
87         def create_entry(provider_video_id, provider_video_type, title=None, description=None):
88             return {
89                 '_type': 'url_transparent',
90                 'url': provider_video_id if provider_video_type == 'youtube' else '%s:%s' % (provider_video_type, provider_video_id),
91                 'title': title or self._og_search_title(webpage),
92                 'description': description or self._og_search_description(webpage),
93             }
94
95         entries = []
96         entries_data = self._search_regex([
97             r'Chorus\.VideoContext\.addVideo\((\[{.+}\])\);',
98             r'var\s+entry\s*=\s*({.+});',
99             r'SBN\.VideoLinkset\.entryGroup\(\s*(\[.+\])',
100         ], webpage, 'video data', default=None)
101         if entries_data:
102             entries_data = self._parse_json(entries_data, display_id)
103             if isinstance(entries_data, dict):
104                 entries_data = [entries_data]
105             for video_data in entries_data:
106                 provider_video_id = video_data.get('provider_video_id')
107                 provider_video_type = video_data.get('provider_video_type')
108                 if provider_video_id and provider_video_type:
109                     entries.append(create_entry(
110                         provider_video_id, provider_video_type,
111                         video_data.get('title'), video_data.get('description')))
112
113         provider_video_id = self._search_regex(
114             r'data-ooyala-id="([^"]+)"', webpage, 'ooyala id', default=None)
115         if provider_video_id:
116             entries.append(create_entry(provider_video_id, 'ooyala'))
117
118         volume_uuid = self._search_regex(
119             r'data-volume-uuid="([^"]+)"', webpage, 'volume uuid', default=None)
120         if volume_uuid:
121             volume_webpage = self._download_webpage(
122                 'http://volume.vox-cdn.com/embed/%s' % volume_uuid, volume_uuid)
123             video_data = self._parse_json(self._search_regex(
124                 r'Volume\.createVideo\(({.+})\s*,\s*{.*}\s*,\s*\[.*\]\s*,\s*{.*}\);', volume_webpage, 'video data'), volume_uuid)
125             for provider_video_type in ('ooyala', 'youtube'):
126                 provider_video_id = video_data.get('%s_id' % provider_video_type)
127                 if provider_video_id:
128                     description = video_data.get('description_long') or video_data.get('description_short')
129                     entries.append(create_entry(
130                         provider_video_id, provider_video_type, video_data.get('title_short'), description))
131                     break
132
133         if len(entries) == 1:
134             return entries[0]
135         else:
136             return self.playlist_result(entries, display_id, self._og_search_title(webpage), self._og_search_description(webpage))