[wsj] improve extraction

This commit is contained in:
remitamine 2016-04-29 21:35:09 +01:00
parent ca278a182b
commit 69c4cde4ba

View file

@ -4,16 +4,22 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
int_or_none, int_or_none,
float_or_none,
unified_strdate, unified_strdate,
) )
class WSJIE(InfoExtractor): class WSJIE(InfoExtractor):
_VALID_URL = r'https?://video-api\.wsj\.com/api-video/player/iframe\.html\?guid=(?P<id>[a-zA-Z0-9-]+)' _VALID_URL = r'''(?x)https?://
(?:
video-api\.wsj\.com/api-video/player/iframe\.html\?guid=|
(?:www\.)?wsj\.com/video/[^/]+/
)
(?P<id>[a-zA-Z0-9-]+)'''
IE_DESC = 'Wall Street Journal' IE_DESC = 'Wall Street Journal'
_TEST = { _TESTS = [{
'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A', 'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
'md5': '9747d7a6ebc2f4df64b981e1dde9efa9', 'md5': 'e230a5bb249075e40793b655a54a02e4',
'info_dict': { 'info_dict': {
'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A', 'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
'ext': 'mp4', 'ext': 'mp4',
@ -24,65 +30,60 @@ class WSJIE(InfoExtractor):
'duration': 90, 'duration': 90,
'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo', 'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo',
}, },
} }, {
'url': 'http://www.wsj.com/video/can-alphabet-build-a-smarter-city/359DDAA8-9AC1-489C-82E6-0429C1E430E0.html',
'only_matching': True,
}]
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
bitrates = [128, 174, 264, 320, 464, 664, 1264]
api_url = ( api_url = (
'http://video-api.wsj.com/api-video/find_all_videos.asp?' 'http://video-api.wsj.com/api-video/find_all_videos.asp?'
'type=guid&count=1&query=%s&' 'type=guid&count=1&query=%s&fields=type,hls,videoMP4List,'
'fields=hls,adZone,thumbnailList,guid,state,secondsUntilStartTime,' 'thumbnailList,author,description,name,duration,videoURL,'
'author,description,name,linkURL,videoStillURL,duration,videoURL,' 'titletag,formattedCreationDate,keywords,editor' % video_id)
'adCategory,catastrophic,linkShortURL,doctypeID,youtubeID,'
'titletag,rssURL,wsj-section,wsj-subsection,allthingsd-section,'
'allthingsd-subsection,sm-section,sm-subsection,provider,'
'formattedCreationDate,keywords,keywordsOmniture,column,editor,'
'emailURL,emailPartnerID,showName,omnitureProgramName,'
'omnitureVideoFormat,linkRelativeURL,touchCastID,'
'omniturePublishDate,%s') % (
video_id, ','.join('video%dkMP4Url' % br for br in bitrates))
info = self._download_json(api_url, video_id)['items'][0] info = self._download_json(api_url, video_id)['items'][0]
# Thumbnails are conveniently in the correct format already
thumbnails = info.get('thumbnailList')
creator = info.get('author')
uploader_id = info.get('editor')
categories = info.get('keywords')
duration = int_or_none(info.get('duration'))
upload_date = unified_strdate(
info.get('formattedCreationDate'), day_first=False)
title = info.get('name', info.get('titletag')) title = info.get('name', info.get('titletag'))
formats = [{ formats = []
'format_id': 'f4m',
'format_note': 'f4m (meta URL)', f4m_url = info.get('videoURL')
'url': info['videoURL'], if f4m_url:
}] formats.extend(self._extract_f4m_formats(
if info.get('hls'): f4m_url, video_id, f4m_id='hds', fatal=False))
m3u8_url = info.get('hls')
if m3u8_url:
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
info['hls'], video_id, ext='mp4', info['hls'], video_id, ext='mp4',
preference=0, entry_protocol='m3u8_native')) entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
for br in bitrates:
field = 'video%dkMP4Url' % br for v in info.get('videoMP4List', []):
if info.get(field): mp4_url = v.get('url')
formats.append({ if not mp4_url:
'format_id': 'mp4-%d' % br, continue
'container': 'mp4', tbr = int_or_none(v.get('bitrate'))
'tbr': br, formats.append({
'url': info[field], 'url': mp4_url,
}) 'format_id': 'http' + ('-%d' % tbr if tbr else ''),
'tbr': tbr,
'width': int_or_none(v.get('width')),
'height': int_or_none(v.get('height')),
'fps': float_or_none(v.get('fps')),
})
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'formats': formats, 'formats': formats,
'thumbnails': thumbnails, # Thumbnails are conveniently in the correct format already
'creator': creator, 'thumbnails': info.get('thumbnailList'),
'uploader_id': uploader_id, 'creator': info.get('author'),
'duration': duration, 'uploader_id': info.get('editor'),
'upload_date': upload_date, 'duration': int_or_none(info.get('duration')),
'upload_date': unified_strdate(info.get(
'formattedCreationDate'), day_first=False),
'title': title, 'title': title,
'categories': categories, 'categories': info.get('keywords'),
} }