1 from __future__ import unicode_literals
3 from .common import InfoExtractor
6 class HowStuffWorksIE(InfoExtractor):
7 _VALID_URL = r'https?://[\da-z-]+\.howstuffworks\.com/(?:[^/]+/)*\d+-(?P<id>.+?)-video\.htm'
10 'url': 'http://adventure.howstuffworks.com/39521-deadliest-catch-nautical-collision-video.htm',
14 'title': 'Deadliest Catch: Nautical Collision',
15 'description': 'Check out this clip to get an exclusive look at the Deadliest Catch crew back in action.',
16 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/39521.jpg',
20 'url': 'http://adventure.howstuffworks.com/7199-survival-zone-food-and-water-in-the-savanna-video.htm',
24 'title': 'Survival Zone: Food and Water In the Savanna',
25 'description': 'Learn how to find both food and water while trekking in the African savannah. In this video from the Discovery Channel.',
26 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/7199.jpg',
30 'url': 'http://entertainment.howstuffworks.com/arts/34476-time-warp-fire-breathing-disaster-video.htm',
34 'title': 'Time Warp: Fire-Breathing Disaster',
35 'description': 'Fire-breathers are safe from flames when they angle their heads up as they blow -- see what would happen if they looked down instead. Check out this clip from Discovery\'s "Time Warp" series to learn more.',
36 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/34476.jpg',
41 def _extract_clip_info(self, key, clip_info, name=None, **kargs):
44 return self._html_search_regex(
45 r"\s*%s\s*: '?([^'\n]*[^'\n,])" % key, clip_info, name, **kargs)
47 def _real_extract(self, url):
48 display_id = self._match_id(url)
49 webpage = self._download_webpage(url, display_id)
50 clip_info = self._search_regex('(?s)var clip = {(.*?)};', webpage, 'clip info')
51 video_id = self._extract_clip_info('content_id', clip_info, 'video id')
53 m3u8_url = self._extract_clip_info('m3u8', clip_info, 'm3u8 url', default=None)
54 if m3u8_url is not None:
55 formats += self._extract_m3u8_formats(m3u8_url , video_id, 'mp4')
56 mp4 = self._parse_json(
57 self._extract_clip_info(
58 'mp4', clip_info, 'formats').replace('},]','}]'), video_id)
62 'format_id': video['bitrate'],
63 'tbr': int(video['bitrate'].rstrip('k')),
65 self._sort_formats(formats)
69 'display_id': display_id,
70 'title': self._extract_clip_info('clip_title', clip_info, 'title'),
71 'description': self._extract_clip_info('caption', clip_info, 'description', fatal=False),
72 'thumbnail': self._extract_clip_info('video_still_url', clip_info, 'thumbnail'),
73 'duration': self._extract_clip_info('duration', clip_info),