]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/howstuffworks.py
1 from __future__
import unicode_literals
3 from .common
import InfoExtractor
13 class HowStuffWorksIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://[\da-z-]+\.(?:howstuffworks|stuff(?:(?:youshould|theydontwantyouto)know|toblowyourmind|momnevertoldyou)|(?:brain|car)stuffshow|fwthinking|geniusstuff)\.com/(?:[^/]+/)*(?:\d+-)?(?P<id>.+?)-video\.htm'
17 'url': 'http://www.stufftoblowyourmind.com/videos/optical-illusions-video.htm',
18 'md5': '76646a5acc0c92bf7cd66751ca5db94d',
22 'title': 'Your Trickster Brain: Optical Illusions -- Science on the Web',
23 'description': 'md5:e374ff9561f6833ad076a8cc0a5ab2fb',
27 'url': 'http://shows.howstuffworks.com/more-shows/why-does-balloon-stick-to-hair-video.htm',
28 'only_matching': True,
32 def _real_extract(self
, url
):
33 display_id
= self
._match
_id
(url
)
34 webpage
= self
._download
_webpage
(url
, display_id
)
35 clip_js
= self
._search
_regex
(
36 r
'(?s)var clip = ({.*?});', webpage
, 'clip info')
37 clip_info
= self
._parse
_json
(
38 clip_js
, display_id
, transform_source
=js_to_json
)
40 video_id
= clip_info
['content_id']
42 m3u8_url
= clip_info
.get('m3u8')
43 if m3u8_url
and determine_ext(m3u8_url
) == 'm3u8':
44 formats
.extend(self
._extract
_m
3u8_formats
(m3u8_url
, video_id
, 'mp4', format_id
='hls', fatal
=True))
45 flv_url
= clip_info
.get('flv_url')
51 for video
in clip_info
.get('mp4', []):
54 'format_id': 'mp4-%s' % video
['bitrate'],
55 'vbr': int_or_none(video
['bitrate'].rstrip('k')),
59 smil
= self
._download
_xml
(
60 'http://services.media.howstuffworks.com/videos/%s/smil-service.smil' % video_id
,
61 video_id
, 'Downloading video SMIL')
63 http_base
= find_xpath_attr(
65 './{0}head/{0}meta'.format('{http://www.w3.org/2001/SMIL20/Language}'),
67 'httpBase').get('content')
69 URL_SUFFIX
= '?v=2.11.3&fp=LNX 11,2,202,356&r=A&g=A'
71 for video
in smil
.findall(
72 './{0}body/{0}switch/{0}video'.format('{http://www.w3.org/2001/SMIL20/Language}')):
73 vbr
= int_or_none(video
.attrib
['system-bitrate'], scale
=1000)
75 'url': '%s/%s%s' % (http_base
, video
.attrib
['src'], URL_SUFFIX
),
76 'format_id': '%dk' % vbr
,
80 self
._sort
_formats
(formats
)
83 'id': '%s' % video_id
,
84 'display_id': display_id
,
85 'title': unescapeHTML(clip_info
['clip_title']),
86 'description': unescapeHTML(clip_info
.get('caption')),
87 'thumbnail': clip_info
.get('video_still_url'),
88 'duration': int_or_none(clip_info
.get('duration')),