6 from .common
import InfoExtractor
10 compat_urllib_parse_urlparse
,
15 class CondeNastIE(InfoExtractor
):
17 Condé Nast is a media group, some of its sites use a custom HTML5 player
18 that works the same in all of them.
21 # The keys are the supported sites and the values are the name to be shown
22 # to the user and in the extractor description.
23 _SITES
= {'wired': u
'WIRED',
26 'glamour': u
'Glamour',
27 'wmagazine': u
'W Magazine',
28 'vanityfair': u
'Vanity Fair',
31 _VALID_URL
= r
'http://(video|www).(?P<site>%s).com/(?P<type>watch|series|video)/(?P<id>.+)' % '|'.join(_SITES
.keys())
32 IE_DESC
= u
'Condé Nast media group: %s' % ', '.join(sorted(_SITES
.values()))
35 u
'url': u
'http://video.wired.com/watch/3d-printed-speakers-lit-with-led',
36 u
'file': u
'5171b343c2b4c00dd0c1ccb3.mp4',
37 u
'md5': u
'1921f713ed48aabd715691f774c451f7',
39 u
'title': u
'3D Printed Speakers Lit With LED',
40 u
'description': u
'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.',
44 def _extract_series(self
, url
, webpage
):
45 title
= self
._html
_search
_regex
(r
'<div class="cne-series-info">.*?<h1>(.+?)</h1>',
46 webpage
, u
'series title', flags
=re
.DOTALL
)
47 url_object
= compat_urllib_parse_urlparse(url
)
48 base_url
= '%s://%s' % (url_object
.scheme
, url_object
.netloc
)
49 m_paths
= re
.finditer(r
'<p class="cne-thumb-title">.*?<a href="(/watch/.+?)["\?]',
50 webpage
, flags
=re
.DOTALL
)
51 paths
= orderedSet(m
.group(1) for m
in m_paths
)
52 build_url
= lambda path
: compat_urlparse
.urljoin(base_url
, path
)
53 entries
= [self
.url_result(build_url(path
), 'CondeNast') for path
in paths
]
54 return self
.playlist_result(entries
, playlist_title
=title
)
56 def _extract_video(self
, webpage
):
57 description
= self
._html
_search
_regex
([r
'<div class="cne-video-description">(.+?)</div>',
58 r
'<div class="video-post-content">(.+?)</div>',
60 webpage
, u
'description',
61 fatal
=False, flags
=re
.DOTALL
)
62 params
= self
._search
_regex
(r
'var params = {(.+?)}[;,]', webpage
,
63 u
'player params', flags
=re
.DOTALL
)
64 video_id
= self
._search
_regex
(r
'videoId: [\'"](.+?)[\'"]', params, u'video
id')
65 player_id = self._search_regex(r'playerId
: [\'"](.+?)[\'"]', params, u'player
id')
66 target = self._search_regex(r'target
: [\'"](.+?)[\'"]', params, u'target
')
67 data = compat_urllib_parse.urlencode({'videoId
': video_id,
68 'playerId
': player_id,
71 base_info_url = self._search_regex(r'url
= [\'"](.+?)[\'"][,;]',
72 webpage, u'base info url
',
73 default='http
://player
.cnevids
.com
/player
/loader
.js?
')
74 info_url = base_info_url + data
75 info_page = self._download_webpage(info_url, video_id,
76 u'Downloading video info
')
77 video_info = self._search_regex(r'var video
= ({.+?
});', info_page, u'video info
')
78 video_info = json.loads(video_info)
80 def _formats_sort_key(f):
81 type_ord = 1 if f['type'] == 'video
/mp4
' else 0
82 quality_ord = 1 if f['quality
'] == 'high
' else 0
83 return (quality_ord, type_ord)
84 best_format = sorted(video_info['sources
'][0], key=_formats_sort_key)[-1]
86 return {'id': video_id,
87 'url
': best_format['src
'],
88 'ext
': best_format['type'].split('/')[-1],
89 'title
': video_info['title
'],
90 'thumbnail
': video_info['poster_frame
'],
91 'description
': description,
94 def _real_extract(self, url):
95 mobj = re.match(self._VALID_URL, url)
96 site = mobj.group('site
')
97 url_type = mobj.group('type')
100 self.to_screen(u'Extracting
from %s with the Condé Nast extractor
' % self._SITES[site])
101 webpage = self._download_webpage(url, id)
103 if url_type == 'series
':
104 return self._extract_series(url, webpage)
106 return self._extract_video(webpage)