X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fhowstuffworks.py;h=cf90ab3c9d976faabed8891fa4c1211853732f24;hb=HEAD;hp=9478e9e67e498b7e84c1cbe60df28f57bece94a0;hpb=e638e83662e5baa414b8d80145e46c1912f7998d;p=youtube-dl diff --git a/youtube_dl/extractor/howstuffworks.py b/youtube_dl/extractor/howstuffworks.py index 9478e9e67..cf90ab3c9 100644 --- a/youtube_dl/extractor/howstuffworks.py +++ b/youtube_dl/extractor/howstuffworks.py @@ -1,68 +1,58 @@ from __future__ import unicode_literals from .common import InfoExtractor -from ..utils import find_xpath_attr +from ..utils import ( + find_xpath_attr, + int_or_none, + js_to_json, + unescapeHTML, + determine_ext, +) class HowStuffWorksIE(InfoExtractor): - _VALID_URL = r'https?://[\da-z-]+\.howstuffworks\.com/(?:[^/]+/)*\d+-(?P.+?)-video\.htm' + _VALID_URL = r'https?://[\da-z-]+\.(?:howstuffworks|stuff(?:(?:youshould|theydontwantyouto)know|toblowyourmind|momnevertoldyou)|(?:brain|car)stuffshow|fwthinking|geniusstuff)\.com/(?:[^/]+/)*(?:\d+-)?(?P.+?)-video\.htm' _TESTS = [ { - 'url': 'http://adventure.howstuffworks.com/5266-cool-jobs-iditarod-musher-video.htm', + 'url': 'http://www.stufftoblowyourmind.com/videos/optical-illusions-video.htm', + 'md5': '76646a5acc0c92bf7cd66751ca5db94d', 'info_dict': { - 'id': '450221', - 'ext': 'flv', - 'title': 'Cool Jobs - Iditarod Musher', - '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.', - 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/5266.jpg', - }, - }, - { - 'url': 'http://adventure.howstuffworks.com/7199-survival-zone-food-and-water-in-the-savanna-video.htm', - 'info_dict': { - 'id': '453464', + 'id': '855410', 'ext': 'mp4', - 'title': 'Survival Zone: Food and Water In the Savanna', - 'description': 'Learn how to find both food and water while trekking in the African savannah. In this video from the Discovery Channel.', - 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/7199.jpg', + 'title': 'Your Trickster Brain: Optical Illusions -- Science on the Web', + 'description': 'md5:e374ff9561f6833ad076a8cc0a5ab2fb', }, }, { - 'url': 'http://entertainment.howstuffworks.com/arts/2706-sword-swallowing-1-by-dan-meyer-video.htm', - 'info_dict': { - 'id': '440011', - 'ext': 'flv', - 'title': 'Sword Swallowing #1 by Dan Meyer', - 'description': 'Video footage (1 of 3) used by permission of the owner Dan Meyer through Sword Swallowers Association International ', - 'thumbnail': 'http://s.hswstatic.com/gif/videos/480x360/118306353233.jpg', - }, - }, + 'url': 'http://shows.howstuffworks.com/more-shows/why-does-balloon-stick-to-hair-video.htm', + 'only_matching': True, + } ] def _real_extract(self, url): display_id = self._match_id(url) webpage = self._download_webpage(url, display_id) - clip_info = self._search_regex('(?s)var clip = {(.*?)};', webpage, 'clip info') - - def extract_clip_info(key, clip_info, name=None, **kargs): - if name is None: - name = key - return self._html_search_regex( - r"\s*%s\s*: '?([^'\n]*[^'\n,])" % key, clip_info, name, **kargs) + clip_js = self._search_regex( + r'(?s)var clip = ({.*?});', webpage, 'clip info') + clip_info = self._parse_json( + clip_js, display_id, transform_source=js_to_json) - video_id = extract_clip_info('content_id', clip_info, 'video id') + video_id = clip_info['content_id'] formats = [] - m3u8_url = extract_clip_info('m3u8', clip_info, 'm3u8 url', default=None) - if m3u8_url is not None: - formats += self._extract_m3u8_formats(m3u8_url , video_id, 'mp4') - mp4 = self._parse_json( - extract_clip_info( - 'mp4', clip_info, 'formats').replace('},]','}]'), video_id) - for video in mp4: + m3u8_url = clip_info.get('m3u8') + if m3u8_url and determine_ext(m3u8_url) == 'm3u8': + formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', format_id='hls', fatal=True)) + flv_url = clip_info.get('flv_url') + if flv_url: + formats.append({ + 'url': flv_url, + 'format_id': 'flv', + }) + for video in clip_info.get('mp4', []): formats.append({ 'url': video['src'], - 'format_id': video['bitrate'], - 'vbr': int(video['bitrate'].rstrip('k')), + 'format_id': 'mp4-%s' % video['bitrate'], + 'vbr': int_or_none(video['bitrate'].rstrip('k')), }) if not formats: @@ -80,7 +70,7 @@ class HowStuffWorksIE(InfoExtractor): for video in smil.findall( './{0}body/{0}switch/{0}video'.format('{http://www.w3.org/2001/SMIL20/Language}')): - vbr = int(video.attrib['system-bitrate']) / 1000 + vbr = int_or_none(video.attrib['system-bitrate'], scale=1000) formats.append({ 'url': '%s/%s%s' % (http_base, video.attrib['src'], URL_SUFFIX), 'format_id': '%dk' % vbr, @@ -90,11 +80,11 @@ class HowStuffWorksIE(InfoExtractor): self._sort_formats(formats) return { - 'id': video_id, + 'id': '%s' % video_id, 'display_id': display_id, - 'title': extract_clip_info('clip_title', clip_info, 'title'), - 'description': extract_clip_info('caption', clip_info, 'description', fatal=False), - 'thumbnail': extract_clip_info('video_still_url', clip_info, 'thumbnail'), - 'duration': extract_clip_info('duration', clip_info), + 'title': unescapeHTML(clip_info['clip_title']), + 'description': unescapeHTML(clip_info.get('caption')), + 'thumbnail': clip_info.get('video_still_url'), + 'duration': int_or_none(clip_info.get('duration')), 'formats': formats, }