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