]>
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 | 8 | compat_urllib_parse, |
e1fb2456 JMF |
9 | compat_urllib_parse_urlparse, |
10 | compat_urlparse, | |
11 | ) | |
1cc79574 PH |
12 | from ..utils import ( |
13 | orderedSet, | |
c6b8f4d0 | 14 | remove_end, |
1cc79574 | 15 | ) |
e1fb2456 JMF |
16 | |
17 | ||
18 | class CondeNastIE(InfoExtractor): | |
19 | """ | |
20 | Condé Nast is a media group, some of its sites use a custom HTML5 player | |
21 | that works the same in all of them. | |
22 | """ | |
23 | ||
24 | # The keys are the supported sites and the values are the name to be shown | |
25 | # to the user and in the extractor description. | |
6e249060 | 26 | _SITES = { |
882fc905 | 27 | 'allure': 'Allure', |
28 | 'architecturaldigest': 'Architectural Digest', | |
29 | 'arstechnica': 'Ars Technica', | |
42ca72df | 30 | 'bonappetit': 'Bon Appétit', |
882fc905 | 31 | 'brides': 'Brides', |
32 | 'cnevids': 'Condé Nast', | |
33 | 'cntraveler': 'Condé Nast Traveler', | |
34 | 'details': 'Details', | |
35 | 'epicurious': 'Epicurious', | |
36 | 'glamour': 'Glamour', | |
37 | 'golfdigest': 'Golf Digest', | |
6e249060 | 38 | 'gq': 'GQ', |
882fc905 | 39 | 'newyorker': 'The New Yorker', |
40 | 'self': 'SELF', | |
41 | 'teenvogue': 'Teen Vogue', | |
42 | 'vanityfair': 'Vanity Fair', | |
6e249060 | 43 | 'vogue': 'Vogue', |
882fc905 | 44 | 'wired': 'WIRED', |
6e249060 | 45 | 'wmagazine': 'W Magazine', |
6e249060 | 46 | } |
e1fb2456 | 47 | |
c6b8f4d0 | 48 | _VALID_URL = r'http://(?:video|www|player)\.(?P<site>%s)\.com/(?P<type>watch|series|video|embed(?:js)?)/(?P<id>[^/?#]+)' % '|'.join(_SITES.keys()) |
6e249060 | 49 | IE_DESC = 'Condé Nast media group: %s' % ', '.join(sorted(_SITES.values())) |
e1fb2456 | 50 | |
c6b8f4d0 | 51 | EMBED_URL = r'(?:https?:)?//player\.(?P<site>%s)\.com/(?P<type>embed(?:js)?)/.+?' % '|'.join(_SITES.keys()) |
1419fafd | 52 | |
c6b8f4d0 | 53 | _TESTS = [{ |
6e249060 | 54 | 'url': 'http://video.wired.com/watch/3d-printed-speakers-lit-with-led', |
6e249060 PH |
55 | 'md5': '1921f713ed48aabd715691f774c451f7', |
56 | 'info_dict': { | |
fa35cdad PH |
57 | 'id': '5171b343c2b4c00dd0c1ccb3', |
58 | 'ext': 'mp4', | |
6e249060 PH |
59 | 'title': '3D Printed Speakers Lit With LED', |
60 | '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.', | |
e1fb2456 | 61 | } |
c6b8f4d0 S |
62 | }, { |
63 | # JS embed | |
64 | 'url': 'http://player.cnevids.com/embedjs/55f9cf8b61646d1acf00000c/5511d76261646d5566020000.js', | |
65 | 'md5': 'f1a6f9cafb7083bab74a710f65d08999', | |
66 | 'info_dict': { | |
67 | 'id': '55f9cf8b61646d1acf00000c', | |
68 | 'ext': 'mp4', | |
69 | 'title': '3D printed TSA Travel Sentry keys really do open TSA locks', | |
70 | } | |
71 | }] | |
e1fb2456 JMF |
72 | |
73 | def _extract_series(self, url, webpage): | |
74 | title = self._html_search_regex(r'<div class="cne-series-info">.*?<h1>(.+?)</h1>', | |
6e249060 | 75 | webpage, 'series title', flags=re.DOTALL) |
e1fb2456 JMF |
76 | url_object = compat_urllib_parse_urlparse(url) |
77 | base_url = '%s://%s' % (url_object.scheme, url_object.netloc) | |
78 | m_paths = re.finditer(r'<p class="cne-thumb-title">.*?<a href="(/watch/.+?)["\?]', | |
79 | webpage, flags=re.DOTALL) | |
80 | paths = orderedSet(m.group(1) for m in m_paths) | |
81 | build_url = lambda path: compat_urlparse.urljoin(base_url, path) | |
82 | entries = [self.url_result(build_url(path), 'CondeNast') for path in paths] | |
83 | return self.playlist_result(entries, playlist_title=title) | |
84 | ||
fa35cdad PH |
85 | def _extract_video(self, webpage, url_type): |
86 | if url_type != 'embed': | |
87 | description = self._html_search_regex( | |
88 | [ | |
89 | r'<div class="cne-video-description">(.+?)</div>', | |
90 | r'<div class="video-post-content">(.+?)</div>', | |
91 | ], | |
92 | webpage, 'description', fatal=False, flags=re.DOTALL) | |
93 | else: | |
94 | description = None | |
e1fb2456 | 95 | params = self._search_regex(r'var params = {(.+?)}[;,]', webpage, |
6e249060 PH |
96 | 'player params', flags=re.DOTALL) |
97 | video_id = self._search_regex(r'videoId: [\'"](.+?)[\'"]', params, 'video id') | |
98 | player_id = self._search_regex(r'playerId: [\'"](.+?)[\'"]', params, 'player id') | |
99 | target = self._search_regex(r'target: [\'"](.+?)[\'"]', params, 'target') | |
e1fb2456 JMF |
100 | data = compat_urllib_parse.urlencode({'videoId': video_id, |
101 | 'playerId': player_id, | |
102 | 'target': target, | |
103 | }) | |
104 | base_info_url = self._search_regex(r'url = [\'"](.+?)[\'"][,;]', | |
6e249060 | 105 | webpage, 'base info url', |
e1fb2456 JMF |
106 | default='http://player.cnevids.com/player/loader.js?') |
107 | info_url = base_info_url + data | |
108 | info_page = self._download_webpage(info_url, video_id, | |
6e249060 | 109 | 'Downloading video info') |
2949a6cd | 110 | video_info = self._search_regex(r'var\s+video\s*=\s*({.+?});', info_page, 'video info') |
882fc905 | 111 | video_info = self._parse_json(video_info, video_id) |
e1fb2456 | 112 | |
d0da491e PH |
113 | formats = [{ |
114 | 'format_id': '%s-%s' % (fdata['type'].split('/')[-1], fdata['quality']), | |
115 | 'url': fdata['src'], | |
116 | 'ext': fdata['type'].split('/')[-1], | |
117 | 'quality': 1 if fdata['quality'] == 'high' else 0, | |
118 | } for fdata in video_info['sources'][0]] | |
119 | self._sort_formats(formats) | |
e1fb2456 | 120 | |
d0da491e PH |
121 | return { |
122 | 'id': video_id, | |
123 | 'formats': formats, | |
124 | 'title': video_info['title'], | |
125 | 'thumbnail': video_info['poster_frame'], | |
126 | 'description': description, | |
127 | } | |
e1fb2456 JMF |
128 | |
129 | def _real_extract(self, url): | |
130 | mobj = re.match(self._VALID_URL, url) | |
131 | site = mobj.group('site') | |
132 | url_type = mobj.group('type') | |
fa35cdad | 133 | item_id = mobj.group('id') |
e1fb2456 | 134 | |
c6b8f4d0 S |
135 | # Convert JS embed to regular embed |
136 | if url_type == 'embedjs': | |
137 | parsed_url = compat_urlparse.urlparse(url) | |
138 | url = compat_urlparse.urlunparse(parsed_url._replace( | |
139 | path=remove_end(parsed_url.path, '.js').replace('/embedjs/', '/embed/'))) | |
140 | url_type = 'embed' | |
141 | ||
fa35cdad PH |
142 | self.to_screen('Extracting from %s with the Condé Nast extractor' % self._SITES[site]) |
143 | webpage = self._download_webpage(url, item_id) | |
e1fb2456 JMF |
144 | |
145 | if url_type == 'series': | |
146 | return self._extract_series(url, webpage) | |
147 | else: | |
fa35cdad | 148 | return self._extract_video(webpage, url_type) |