2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
11 compat_urllib_parse_urlparse
,
16 class CondeNastIE(InfoExtractor
):
18 Condé Nast is a media group, some of its sites use a custom HTML5 player
19 that works the same in all of them.
22 # The keys are the supported sites and the values are the name to be shown
23 # to the user and in the extractor description.
29 'wmagazine': 'W Magazine',
30 'vanityfair': 'Vanity Fair',
33 _VALID_URL
= r
'http://(video|www)\.(?P<site>%s)\.com/(?P<type>watch|series|video)/(?P<id>.+)' % '|'.join(_SITES
.keys())
34 IE_DESC
= 'Condé Nast media group: %s' % ', '.join(sorted(_SITES
.values()))
37 'url': 'http://video.wired.com/watch/3d-printed-speakers-lit-with-led',
38 'file': '5171b343c2b4c00dd0c1ccb3.mp4',
39 'md5': '1921f713ed48aabd715691f774c451f7',
41 'title': '3D Printed Speakers Lit With LED',
42 '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.',
46 def _extract_series(self
, url
, webpage
):
47 title
= self
._html
_search
_regex
(r
'<div class="cne-series-info">.*?<h1>(.+?)</h1>',
48 webpage
, 'series title', flags
=re
.DOTALL
)
49 url_object
= compat_urllib_parse_urlparse(url
)
50 base_url
= '%s://%s' % (url_object
.scheme
, url_object
.netloc
)
51 m_paths
= re
.finditer(r
'<p class="cne-thumb-title">.*?<a href="(/watch/.+?)["\?]',
52 webpage
, flags
=re
.DOTALL
)
53 paths
= orderedSet(m
.group(1) for m
in m_paths
)
54 build_url
= lambda path
: compat_urlparse
.urljoin(base_url
, path
)
55 entries
= [self
.url_result(build_url(path
), 'CondeNast') for path
in paths
]
56 return self
.playlist_result(entries
, playlist_title
=title
)
58 def _extract_video(self
, webpage
):
59 description
= self
._html
_search
_regex
([r
'<div class="cne-video-description">(.+?)</div>',
60 r
'<div class="video-post-content">(.+?)</div>',
62 webpage
, 'description',
63 fatal
=False, flags
=re
.DOTALL
)
64 params
= self
._search
_regex
(r
'var params = {(.+?)}[;,]', webpage
,
65 'player params', flags
=re
.DOTALL
)
66 video_id
= self
._search
_regex
(r
'videoId: [\'"](.+?)[\'"]', params, 'video
id')
67 player_id = self._search_regex(r'playerId
: [\'"](.+?)[\'"]', params, 'player
id')
68 target = self._search_regex(r'target
: [\'"](.+?)[\'"]', params, 'target
')
69 data = compat_urllib_parse.urlencode({'videoId
': video_id,
70 'playerId
': player_id,
73 base_info_url = self._search_regex(r'url
= [\'"](.+?)[\'"][,;]',
74 webpage, 'base info url
',
75 default='http
://player
.cnevids
.com
/player
/loader
.js?
')
76 info_url = base_info_url + data
77 info_page = self._download_webpage(info_url, video_id,
78 'Downloading video info
')
79 video_info = self._search_regex(r'var video
= ({.+?
});', info_page, 'video info
')
80 video_info = json.loads(video_info)
83 'format_id
': '%s-%s' % (fdata['type'].split('/')[-1], fdata['quality
']),
85 'ext
': fdata['type'].split('/')[-1],
86 'quality
': 1 if fdata['quality
'] == 'high
' else 0,
87 } for fdata in video_info['sources
'][0]]
88 self._sort_formats(formats)
93 'title
': video_info['title
'],
94 'thumbnail
': video_info['poster_frame
'],
95 'description
': description,
98 def _real_extract(self, url):
99 mobj = re.match(self._VALID_URL, url)
100 site = mobj.group('site
')
101 url_type = mobj.group('type')
102 id = mobj.group('id')
104 self.to_screen(u'Extracting
from %s with the Condé Nast extractor
' % self._SITES[site])
105 webpage = self._download_webpage(url, id)
107 if url_type == 'series
':
108 return self._extract_series(url, webpage)
110 return self._extract_video(webpage)