1 from __future__ import unicode_literals
8 from .common import InfoExtractor
9 from ..utils import find_xpath_attr
12 class HowStuffWorksIE(InfoExtractor):
13 _VALID_URL = r'https?://[\da-z-]+\.howstuffworks\.com/(?:[^/]+/)*\d+-(?P<id>.+?)-video\.htm'
16 'url': 'http://adventure.howstuffworks.com/5266-cool-jobs-iditarod-musher-video.htm',
19 'display_id': 'cool-jobs-iditarod-musher',
21 'title': 'Cool Jobs - Iditarod Musher',
22 'description': 'md5:82bb58438a88027b8186a1fccb365f90',
23 'thumbnail': 're:^https?://.*\.jpg$',
26 # md5 is not consistent
31 'url': 'http://adventure.howstuffworks.com/39516-deadliest-catch-jakes-farewell-pots-video.htm',
34 'display_id': 'deadliest-catch-jakes-farewell-pots',
36 'title': 'Deadliest Catch: Jake\'s Farewell Pots',
37 'description': 'md5:9632c346d5e43ee238028c9cefd8dbbc',
38 'thumbnail': 're:^https?://.*\.jpg$',
41 # md5 is not consistent
46 'url': 'http://entertainment.howstuffworks.com/arts/2706-sword-swallowing-1-by-dan-meyer-video.htm',
49 'display_id': 'sword-swallowing-1-by-dan-meyer',
51 'title': 'Sword Swallowing #1 by Dan Meyer',
52 'description': 'md5:b2409e88172913e2e7d3d1159b0ef735',
53 'thumbnail': 're:^https?://.*\.jpg$',
56 # md5 is not consistent
62 def _real_extract(self, url):
63 mobj = re.match(self._VALID_URL, url)
64 display_id = mobj.group('id')
65 webpage = self._download_webpage(url, display_id)
67 content_id = self._search_regex(r'var siteSectionId="(\d+)";', webpage, 'content id')
69 mp4 = self._search_regex(
70 r'''(?xs)var\s+clip\s*=\s*{\s*
72 content_id\s*:\s*%s\s*,\s*
74 mp4\s*:\s*\[(.*?),?\]\s*
76 videoData\.push\(clip\);''' % content_id,
77 webpage, 'mp4', fatal=False, default=None)
79 smil = self._download_xml(
80 'http://services.media.howstuffworks.com/videos/%s/smil-service.smil' % content_id,
81 content_id, 'Downloading video SMIL')
83 http_base = find_xpath_attr(
85 './{0}head/{0}meta'.format('{http://www.w3.org/2001/SMIL20/Language}'),
87 'httpBase').get('content')
89 def random_string(str_len=0):
90 return ''.join([random.choice(string.ascii_uppercase) for _ in range(str_len)])
92 URL_SUFFIX = '?v=2.11.3&fp=LNX 11,2,202,356&r=%s&g=%s' % (random_string(5), random_string(12))
97 for video in json.loads('[%s]' % mp4):
98 bitrate = video['bitrate']
100 'url': video['src'].replace('http://pmd.video.howstuffworks.com', http_base) + URL_SUFFIX,
101 'format_id': bitrate,
103 m = re.search(r'(?P<vbr>\d+)[Kk]', bitrate)
105 fmt['vbr'] = int(m.group('vbr'))
108 for video in smil.findall(
109 './/{0}body/{0}switch/{0}video'.format('{http://www.w3.org/2001/SMIL20/Language}')):
110 vbr = int(video.attrib['system-bitrate']) / 1000
112 'url': '%s/%s%s' % (http_base, video.attrib['src'], URL_SUFFIX),
113 'format_id': '%dk' % vbr,
117 self._sort_formats(formats)
119 title = self._og_search_title(webpage)
120 TITLE_SUFFIX = ' : HowStuffWorks'
121 if title.endswith(TITLE_SUFFIX):
122 title = title[:-len(TITLE_SUFFIX)]
124 description = self._og_search_description(webpage)
125 thumbnail = self._og_search_thumbnail(webpage)
129 'display_id': display_id,
131 'description': description,
132 'thumbnail': thumbnail,