]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
9bb8e0a3 PH |
2 | from __future__ import unicode_literals |
3 | ||
4 | from .common import InfoExtractor | |
5 | from ..utils import ( | |
6 | int_or_none, | |
69c4cde4 | 7 | float_or_none, |
9bb8e0a3 PH |
8 | unified_strdate, |
9 | ) | |
10 | ||
11 | ||
12 | class WSJIE(InfoExtractor): | |
3266d08a | 13 | _VALID_URL = r'''(?x) |
b2a19e38 S |
14 | (?: |
15 | https?://video-api\.wsj\.com/api-video/player/iframe\.html\?.*?\bguid=| | |
16 | https?://(?:www\.)?wsj\.com/video/[^/]+/| | |
17 | wsj: | |
18 | ) | |
19 | (?P<id>[a-fA-F0-9-]{36}) | |
20 | ''' | |
9bb8e0a3 | 21 | IE_DESC = 'Wall Street Journal' |
69c4cde4 | 22 | _TESTS = [{ |
9bb8e0a3 | 23 | 'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A', |
69c4cde4 | 24 | 'md5': 'e230a5bb249075e40793b655a54a02e4', |
9bb8e0a3 PH |
25 | 'info_dict': { |
26 | 'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A', | |
27 | 'ext': 'mp4', | |
28 | 'upload_date': '20150202', | |
d8443cd3 PH |
29 | 'uploader_id': 'jdesai', |
30 | 'creator': 'jdesai', | |
9bb8e0a3 PH |
31 | 'categories': list, # a long list |
32 | 'duration': 90, | |
33 | 'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo', | |
34 | }, | |
69c4cde4 | 35 | }, { |
36 | 'url': 'http://www.wsj.com/video/can-alphabet-build-a-smarter-city/359DDAA8-9AC1-489C-82E6-0429C1E430E0.html', | |
37 | 'only_matching': True, | |
38 | }] | |
9bb8e0a3 PH |
39 | |
40 | def _real_extract(self, url): | |
41 | video_id = self._match_id(url) | |
42 | ||
b2a19e38 S |
43 | info = self._download_json( |
44 | 'http://video-api.wsj.com/api-video/find_all_videos.asp', video_id, | |
45 | query={ | |
46 | 'type': 'guid', | |
47 | 'count': 1, | |
48 | 'query': video_id, | |
49 | 'fields': ','.join(( | |
50 | 'type', 'hls', 'videoMP4List', 'thumbnailList', 'author', | |
51 | 'description', 'name', 'duration', 'videoURL', 'titletag', | |
52 | 'formattedCreationDate', 'keywords', 'editor')), | |
53 | })['items'][0] | |
9bb8e0a3 PH |
54 | title = info.get('name', info.get('titletag')) |
55 | ||
69c4cde4 | 56 | formats = [] |
57 | ||
58 | f4m_url = info.get('videoURL') | |
59 | if f4m_url: | |
60 | formats.extend(self._extract_f4m_formats( | |
61 | f4m_url, video_id, f4m_id='hds', fatal=False)) | |
62 | ||
63 | m3u8_url = info.get('hls') | |
64 | if m3u8_url: | |
9bb8e0a3 PH |
65 | formats.extend(self._extract_m3u8_formats( |
66 | info['hls'], video_id, ext='mp4', | |
69c4cde4 | 67 | entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)) |
68 | ||
69 | for v in info.get('videoMP4List', []): | |
70 | mp4_url = v.get('url') | |
71 | if not mp4_url: | |
72 | continue | |
73 | tbr = int_or_none(v.get('bitrate')) | |
74 | formats.append({ | |
75 | 'url': mp4_url, | |
76 | 'format_id': 'http' + ('-%d' % tbr if tbr else ''), | |
77 | 'tbr': tbr, | |
78 | 'width': int_or_none(v.get('width')), | |
79 | 'height': int_or_none(v.get('height')), | |
80 | 'fps': float_or_none(v.get('fps')), | |
81 | }) | |
9bb8e0a3 PH |
82 | self._sort_formats(formats) |
83 | ||
84 | return { | |
85 | 'id': video_id, | |
86 | 'formats': formats, | |
69c4cde4 | 87 | # Thumbnails are conveniently in the correct format already |
88 | 'thumbnails': info.get('thumbnailList'), | |
89 | 'creator': info.get('author'), | |
90 | 'uploader_id': info.get('editor'), | |
91 | 'duration': int_or_none(info.get('duration')), | |
92 | 'upload_date': unified_strdate(info.get( | |
93 | 'formattedCreationDate'), day_first=False), | |
9bb8e0a3 | 94 | 'title': title, |
69c4cde4 | 95 | 'categories': info.get('keywords'), |
9bb8e0a3 | 96 | } |
3266d08a JH |
97 | |
98 | ||
99 | class WSJArticleIE(InfoExtractor): | |
b2a19e38 S |
100 | _VALID_URL = r'(?i)https?://(?:www\.)?wsj\.com/articles/(?P<id>[^/?#&]+)' |
101 | _TEST = { | |
3266d08a JH |
102 | 'url': 'https://www.wsj.com/articles/dont-like-china-no-pandas-for-you-1490366939?', |
103 | 'info_dict': { | |
104 | 'id': '4B13FA62-1D8C-45DB-8EA1-4105CB20B362', | |
105 | 'ext': 'mp4', | |
106 | 'upload_date': '20170221', | |
107 | 'uploader_id': 'ralcaraz', | |
108 | 'title': 'Bao Bao the Panda Leaves for China', | |
109 | } | |
b2a19e38 | 110 | } |
3266d08a JH |
111 | |
112 | def _real_extract(self, url): | |
113 | article_id = self._match_id(url) | |
114 | webpage = self._download_webpage(url, article_id) | |
b2a19e38 S |
115 | video_id = self._search_regex( |
116 | r'data-src=["\']([a-fA-F0-9-]{36})', webpage, 'video id') | |
3266d08a | 117 | return self.url_result('wsj:%s' % video_id, WSJIE.ie_key(), video_id) |