]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/howstuffworks.py
fccc238840887fd70ed56b2f642c47ea6aa4f43e
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/7199-survival-zone-food-and-water-in-the-savanna-video.htm',
34 'display_id': 'survival-zone-food-and-water-in-the-savanna',
36 'title': 'Survival Zone: Food and Water In the Savanna',
37 'description': 'md5:7e1c89f6411434970c15fa094170c371',
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
,