You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.4 KiB

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