]>
Commit | Line | Data |
---|---|---|
c990bb36 S |
1 | from __future__ import unicode_literals |
2 | ||
c990bb36 | 3 | from .common import InfoExtractor |
62651c55 PH |
4 | from ..utils import ( |
5 | find_xpath_attr, | |
6 | int_or_none, | |
7 | js_to_json, | |
8 | unescapeHTML, | |
9 | ) | |
c990bb36 S |
10 | |
11 | ||
12 | class HowStuffWorksIE(InfoExtractor): | |
13 | _VALID_URL = r'https?://[\da-z-]+\.howstuffworks\.com/(?:[^/]+/)*\d+-(?P<id>.+?)-video\.htm' | |
14 | _TESTS = [ | |
15 | { | |
e638e836 | 16 | 'url': 'http://adventure.howstuffworks.com/5266-cool-jobs-iditarod-musher-video.htm', |
c990bb36 | 17 | 'info_dict': { |
e638e836 TF |
18 | 'id': '450221', |
19 | 'ext': 'flv', | |
20 | 'title': 'Cool Jobs - Iditarod Musher', | |
21 | 'description': 'Cold sleds, freezing temps and warm dog breath... an Iditarod musher\'s dream. Kasey-Dee Gardner jumps on a sled to find out what the big deal is.', | |
62651c55 PH |
22 | 'display_id': 'cool-jobs-iditarod-musher', |
23 | 'thumbnail': 're:^https?://.*\.jpg$', | |
24 | 'duration': 161, | |
c990bb36 | 25 | }, |
c990bb36 S |
26 | }, |
27 | { | |
f4cf848d | 28 | 'url': 'http://adventure.howstuffworks.com/7199-survival-zone-food-and-water-in-the-savanna-video.htm', |
c990bb36 | 29 | 'info_dict': { |
f4cf848d | 30 | 'id': '453464', |
c990bb36 | 31 | 'ext': 'mp4', |
f4cf848d | 32 | 'title': 'Survival Zone: Food and Water In the Savanna', |
d958fa9f | 33 | 'description': 'Learn how to find both food and water while trekking in the African savannah. In this video from the Discovery Channel.', |
62651c55 PH |
34 | 'display_id': 'survival-zone-food-and-water-in-the-savanna', |
35 | 'thumbnail': 're:^https?://.*\.jpg$', | |
c990bb36 | 36 | }, |
c990bb36 S |
37 | }, |
38 | { | |
e638e836 | 39 | 'url': 'http://entertainment.howstuffworks.com/arts/2706-sword-swallowing-1-by-dan-meyer-video.htm', |
c990bb36 | 40 | 'info_dict': { |
e638e836 TF |
41 | 'id': '440011', |
42 | 'ext': 'flv', | |
43 | 'title': 'Sword Swallowing #1 by Dan Meyer', | |
44 | 'description': 'Video footage (1 of 3) used by permission of the owner Dan Meyer through Sword Swallowers Association International <www.swordswallow.org>', | |
62651c55 PH |
45 | 'display_id': 'sword-swallowing-1-by-dan-meyer', |
46 | 'thumbnail': 're:^https?://.*\.jpg$', | |
c990bb36 | 47 | }, |
c990bb36 S |
48 | }, |
49 | ] | |
50 | ||
51 | def _real_extract(self, url): | |
d958fa9f | 52 | display_id = self._match_id(url) |
c990bb36 | 53 | webpage = self._download_webpage(url, display_id) |
62651c55 PH |
54 | clip_js = self._search_regex( |
55 | r'(?s)var clip = ({.*?});', webpage, 'clip info') | |
56 | clip_info = self._parse_json( | |
57 | clip_js, display_id, transform_source=js_to_json) | |
e638e836 | 58 | |
62651c55 | 59 | video_id = clip_info['content_id'] |
c990bb36 | 60 | formats = [] |
62651c55 PH |
61 | m3u8_url = clip_info.get('m3u8') |
62 | if m3u8_url: | |
63 | formats += self._extract_m3u8_formats(m3u8_url, video_id, 'mp4') | |
64 | for video in clip_info.get('mp4', []): | |
d958fa9f TF |
65 | formats.append({ |
66 | 'url': video['src'], | |
67 | 'format_id': video['bitrate'], | |
e638e836 | 68 | 'vbr': int(video['bitrate'].rstrip('k')), |
d958fa9f | 69 | }) |
e638e836 TF |
70 | |
71 | if not formats: | |
72 | smil = self._download_xml( | |
73 | 'http://services.media.howstuffworks.com/videos/%s/smil-service.smil' % video_id, | |
74 | video_id, 'Downloading video SMIL') | |
75 | ||
76 | http_base = find_xpath_attr( | |
77 | smil, | |
78 | './{0}head/{0}meta'.format('{http://www.w3.org/2001/SMIL20/Language}'), | |
79 | 'name', | |
80 | 'httpBase').get('content') | |
81 | ||
82 | URL_SUFFIX = '?v=2.11.3&fp=LNX 11,2,202,356&r=A&g=A' | |
83 | ||
84 | for video in smil.findall( | |
85 | './{0}body/{0}switch/{0}video'.format('{http://www.w3.org/2001/SMIL20/Language}')): | |
62651c55 | 86 | vbr = int_or_none(video.attrib['system-bitrate'], scale=1000) |
e638e836 TF |
87 | formats.append({ |
88 | 'url': '%s/%s%s' % (http_base, video.attrib['src'], URL_SUFFIX), | |
89 | 'format_id': '%dk' % vbr, | |
90 | 'vbr': vbr, | |
91 | }) | |
92 | ||
c990bb36 S |
93 | self._sort_formats(formats) |
94 | ||
c990bb36 | 95 | return { |
62651c55 | 96 | 'id': '%s' % video_id, |
c990bb36 | 97 | 'display_id': display_id, |
62651c55 PH |
98 | 'title': unescapeHTML(clip_info['clip_title']), |
99 | 'description': unescapeHTML(clip_info.get('caption')), | |
100 | 'thumbnail': clip_info.get('video_still_url'), | |
101 | 'duration': clip_info.get('duration'), | |
c990bb36 S |
102 | 'formats': formats, |
103 | } |