]>
Commit | Line | Data |
---|---|---|
e1fb2456 | 1 | # coding: utf-8 |
6e249060 | 2 | from __future__ import unicode_literals |
e1fb2456 JMF |
3 | |
4 | import re | |
e1fb2456 JMF |
5 | |
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..compat import ( |
e1fb2456 JMF |
8 | compat_urllib_parse_urlparse, |
9 | compat_urlparse, | |
10 | ) | |
1cc79574 PH |
11 | from ..utils import ( |
12 | orderedSet, | |
c6b8f4d0 | 13 | remove_end, |
4f427c4b RA |
14 | extract_attributes, |
15 | mimetype2ext, | |
16 | determine_ext, | |
17 | int_or_none, | |
18 | parse_iso8601, | |
1cc79574 | 19 | ) |
e1fb2456 JMF |
20 | |
21 | ||
22 | class CondeNastIE(InfoExtractor): | |
23 | """ | |
24 | Condé Nast is a media group, some of its sites use a custom HTML5 player | |
25 | that works the same in all of them. | |
26 | """ | |
27 | ||
28 | # The keys are the supported sites and the values are the name to be shown | |
29 | # to the user and in the extractor description. | |
6e249060 | 30 | _SITES = { |
882fc905 | 31 | 'allure': 'Allure', |
32 | 'architecturaldigest': 'Architectural Digest', | |
33 | 'arstechnica': 'Ars Technica', | |
42ca72df | 34 | 'bonappetit': 'Bon Appétit', |
882fc905 | 35 | 'brides': 'Brides', |
36 | 'cnevids': 'Condé Nast', | |
37 | 'cntraveler': 'Condé Nast Traveler', | |
38 | 'details': 'Details', | |
39 | 'epicurious': 'Epicurious', | |
40 | 'glamour': 'Glamour', | |
41 | 'golfdigest': 'Golf Digest', | |
6e249060 | 42 | 'gq': 'GQ', |
882fc905 | 43 | 'newyorker': 'The New Yorker', |
44 | 'self': 'SELF', | |
45 | 'teenvogue': 'Teen Vogue', | |
46 | 'vanityfair': 'Vanity Fair', | |
6e249060 | 47 | 'vogue': 'Vogue', |
882fc905 | 48 | 'wired': 'WIRED', |
6e249060 | 49 | 'wmagazine': 'W Magazine', |
6e249060 | 50 | } |
e1fb2456 | 51 | |
5886b38d | 52 | _VALID_URL = r'https?://(?:video|www|player)\.(?P<site>%s)\.com/(?P<type>watch|series|video|embed(?:js)?)/(?P<id>[^/?#]+)' % '|'.join(_SITES.keys()) |
6e249060 | 53 | IE_DESC = 'Condé Nast media group: %s' % ', '.join(sorted(_SITES.values())) |
e1fb2456 | 54 | |
c6b8f4d0 | 55 | EMBED_URL = r'(?:https?:)?//player\.(?P<site>%s)\.com/(?P<type>embed(?:js)?)/.+?' % '|'.join(_SITES.keys()) |
1419fafd | 56 | |
c6b8f4d0 | 57 | _TESTS = [{ |
6e249060 | 58 | 'url': 'http://video.wired.com/watch/3d-printed-speakers-lit-with-led', |
6e249060 PH |
59 | 'md5': '1921f713ed48aabd715691f774c451f7', |
60 | 'info_dict': { | |
fa35cdad PH |
61 | 'id': '5171b343c2b4c00dd0c1ccb3', |
62 | 'ext': 'mp4', | |
6e249060 PH |
63 | 'title': '3D Printed Speakers Lit With LED', |
64 | 'description': 'Check out these beautiful 3D printed LED speakers. You can\'t actually buy them, but LumiGeek is working on a board that will let you make you\'re own.', | |
4f427c4b RA |
65 | 'uploader': 'wired', |
66 | 'upload_date': '20130314', | |
67 | 'timestamp': 1363219200, | |
e1fb2456 | 68 | } |
c6b8f4d0 S |
69 | }, { |
70 | # JS embed | |
71 | 'url': 'http://player.cnevids.com/embedjs/55f9cf8b61646d1acf00000c/5511d76261646d5566020000.js', | |
72 | 'md5': 'f1a6f9cafb7083bab74a710f65d08999', | |
73 | 'info_dict': { | |
74 | 'id': '55f9cf8b61646d1acf00000c', | |
75 | 'ext': 'mp4', | |
76 | 'title': '3D printed TSA Travel Sentry keys really do open TSA locks', | |
4f427c4b RA |
77 | 'uploader': 'arstechnica', |
78 | 'upload_date': '20150916', | |
79 | 'timestamp': 1442434955, | |
c6b8f4d0 S |
80 | } |
81 | }] | |
e1fb2456 JMF |
82 | |
83 | def _extract_series(self, url, webpage): | |
4f427c4b RA |
84 | title = self._html_search_regex( |
85 | r'(?s)<div class="cne-series-info">.*?<h1>(.+?)</h1>', | |
86 | webpage, 'series title') | |
e1fb2456 JMF |
87 | url_object = compat_urllib_parse_urlparse(url) |
88 | base_url = '%s://%s' % (url_object.scheme, url_object.netloc) | |
4f427c4b RA |
89 | m_paths = re.finditer( |
90 | r'(?s)<p class="cne-thumb-title">.*?<a href="(/watch/.+?)["\?]', webpage) | |
e1fb2456 JMF |
91 | paths = orderedSet(m.group(1) for m in m_paths) |
92 | build_url = lambda path: compat_urlparse.urljoin(base_url, path) | |
93 | entries = [self.url_result(build_url(path), 'CondeNast') for path in paths] | |
94 | return self.playlist_result(entries, playlist_title=title) | |
95 | ||
fa35cdad | 96 | def _extract_video(self, webpage, url_type): |
4f427c4b RA |
97 | query = {} |
98 | params = self._search_regex( | |
99 | r'(?s)var params = {(.+?)}[;,]', webpage, 'player params', default=None) | |
100 | if params: | |
101 | query.update({ | |
102 | 'videoId': self._search_regex(r'videoId: [\'"](.+?)[\'"]', params, 'video id'), | |
103 | 'playerId': self._search_regex(r'playerId: [\'"](.+?)[\'"]', params, 'player id'), | |
104 | 'target': self._search_regex(r'target: [\'"](.+?)[\'"]', params, 'target'), | |
105 | }) | |
fa35cdad | 106 | else: |
4f427c4b RA |
107 | params = extract_attributes(self._search_regex( |
108 | r'(<[^>]+data-js="video-player"[^>]+>)', | |
109 | webpage, 'player params element')) | |
110 | query.update({ | |
111 | 'videoId': params['data-video'], | |
112 | 'playerId': params['data-player'], | |
113 | 'target': params['id'], | |
114 | }) | |
115 | video_id = query['videoId'] | |
e563c0d7 | 116 | video_info = None |
4f427c4b RA |
117 | info_page = self._download_webpage( |
118 | 'http://player.cnevids.com/player/video.js', | |
e563c0d7 RA |
119 | video_id, 'Downloading video info', query=query, fatal=False) |
120 | if info_page: | |
121 | video_info = self._parse_json(self._search_regex( | |
122 | r'loadCallback\(({.+})\)', info_page, 'video info'), video_id)['video'] | |
123 | else: | |
124 | info_page = self._download_webpage( | |
125 | 'http://player.cnevids.com/player/loader.js', | |
126 | video_id, 'Downloading loader info', query=query) | |
127 | video_info = self._parse_json(self._search_regex( | |
128 | r'var\s+video\s*=\s*({.+?});', info_page, 'video info'), video_id) | |
4f427c4b RA |
129 | title = video_info['title'] |
130 | ||
131 | formats = [] | |
132 | for fdata in video_info.get('sources', [{}])[0]: | |
133 | src = fdata.get('src') | |
134 | if not src: | |
135 | continue | |
136 | ext = mimetype2ext(fdata.get('type')) or determine_ext(src) | |
137 | quality = fdata.get('quality') | |
138 | formats.append({ | |
139 | 'format_id': ext + ('-%s' % quality if quality else ''), | |
140 | 'url': src, | |
141 | 'ext': ext, | |
142 | 'quality': 1 if quality == 'high' else 0, | |
143 | }) | |
d0da491e | 144 | self._sort_formats(formats) |
e1fb2456 | 145 | |
1e7f602e S |
146 | info = self._search_json_ld( |
147 | webpage, video_id, fatal=False) if url_type != 'embed' else {} | |
4f427c4b | 148 | info.update({ |
d0da491e PH |
149 | 'id': video_id, |
150 | 'formats': formats, | |
4f427c4b RA |
151 | 'title': title, |
152 | 'thumbnail': video_info.get('poster_frame'), | |
153 | 'uploader': video_info.get('brand'), | |
154 | 'duration': int_or_none(video_info.get('duration')), | |
155 | 'tags': video_info.get('tags'), | |
156 | 'series': video_info.get('series_title'), | |
157 | 'season': video_info.get('season_title'), | |
158 | 'timestamp': parse_iso8601(video_info.get('premiere_date')), | |
159 | }) | |
160 | return info | |
e1fb2456 JMF |
161 | |
162 | def _real_extract(self, url): | |
4f427c4b | 163 | site, url_type, item_id = re.match(self._VALID_URL, url).groups() |
e1fb2456 | 164 | |
c6b8f4d0 S |
165 | # Convert JS embed to regular embed |
166 | if url_type == 'embedjs': | |
167 | parsed_url = compat_urlparse.urlparse(url) | |
168 | url = compat_urlparse.urlunparse(parsed_url._replace( | |
169 | path=remove_end(parsed_url.path, '.js').replace('/embedjs/', '/embed/'))) | |
170 | url_type = 'embed' | |
171 | ||
fa35cdad PH |
172 | self.to_screen('Extracting from %s with the Condé Nast extractor' % self._SITES[site]) |
173 | webpage = self._download_webpage(url, item_id) | |
e1fb2456 JMF |
174 | |
175 | if url_type == 'series': | |
176 | return self._extract_series(url, webpage) | |
177 | else: | |
fa35cdad | 178 | return self._extract_video(webpage, url_type) |