1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-24 23:37:55 +01:00
youtube-dl/youtube_dl/extractor/wsj.py

90 lines
3.1 KiB
Python
Raw Normal View History

2016-10-02 13:39:18 +02:00
# coding: utf-8
2015-02-03 10:58:28 +01:00
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import (
int_or_none,
2016-04-29 22:35:09 +02:00
float_or_none,
2015-02-03 10:58:28 +01:00
unified_strdate,
)
class WSJIE(InfoExtractor):
2016-04-29 22:35:09 +02:00
_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-]+)'''
2015-02-03 10:58:28 +01:00
IE_DESC = 'Wall Street Journal'
2016-04-29 22:35:09 +02:00
_TESTS = [{
2015-02-03 10:58:28 +01:00
'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
2016-04-29 22:35:09 +02:00
'md5': 'e230a5bb249075e40793b655a54a02e4',
2015-02-03 10:58:28 +01:00
'info_dict': {
'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
'ext': 'mp4',
'upload_date': '20150202',
2015-02-18 19:56:24 +01:00
'uploader_id': 'jdesai',
'creator': 'jdesai',
2015-02-03 10:58:28 +01:00
'categories': list, # a long list
'duration': 90,
'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo',
},
2016-04-29 22:35:09 +02:00
}, {
'url': 'http://www.wsj.com/video/can-alphabet-build-a-smarter-city/359DDAA8-9AC1-489C-82E6-0429C1E430E0.html',
'only_matching': True,
}]
2015-02-03 10:58:28 +01:00
def _real_extract(self, url):
video_id = self._match_id(url)
api_url = (
'http://video-api.wsj.com/api-video/find_all_videos.asp?'
2016-04-29 22:35:09 +02:00
'type=guid&count=1&query=%s&fields=type,hls,videoMP4List,'
'thumbnailList,author,description,name,duration,videoURL,'
'titletag,formattedCreationDate,keywords,editor' % video_id)
2015-02-03 10:58:28 +01:00
info = self._download_json(api_url, video_id)['items'][0]
title = info.get('name', info.get('titletag'))
2016-04-29 22:35:09 +02:00
formats = []
f4m_url = info.get('videoURL')
if f4m_url:
formats.extend(self._extract_f4m_formats(
f4m_url, video_id, f4m_id='hds', fatal=False))
m3u8_url = info.get('hls')
if m3u8_url:
2015-02-03 10:58:28 +01:00
formats.extend(self._extract_m3u8_formats(
info['hls'], video_id, ext='mp4',
2016-04-29 22:35:09 +02:00
entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
for v in info.get('videoMP4List', []):
mp4_url = v.get('url')
if not mp4_url:
continue
tbr = int_or_none(v.get('bitrate'))
formats.append({
'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')),
})
2015-02-03 10:58:28 +01:00
self._sort_formats(formats)
return {
'id': video_id,
'formats': formats,
2016-04-29 22:35:09 +02:00
# Thumbnails are conveniently in the correct format already
'thumbnails': info.get('thumbnailList'),
'creator': info.get('author'),
'uploader_id': info.get('editor'),
'duration': int_or_none(info.get('duration')),
'upload_date': unified_strdate(info.get(
'formattedCreationDate'), day_first=False),
2015-02-03 10:58:28 +01:00
'title': title,
2016-04-29 22:35:09 +02:00
'categories': info.get('keywords'),
2015-02-03 10:58:28 +01:00
}