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.

89 lines
3.1 KiB

  1. # encoding: 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)https?://
  11. (?:
  12. video-api\.wsj\.com/api-video/player/iframe\.html\?guid=|
  13. (?:www\.)?wsj\.com/video/[^/]+/
  14. )
  15. (?P<id>[a-zA-Z0-9-]+)'''
  16. IE_DESC = 'Wall Street Journal'
  17. _TESTS = [{
  18. 'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
  19. 'md5': 'e230a5bb249075e40793b655a54a02e4',
  20. 'info_dict': {
  21. 'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
  22. 'ext': 'mp4',
  23. 'upload_date': '20150202',
  24. 'uploader_id': 'jdesai',
  25. 'creator': 'jdesai',
  26. 'categories': list, # a long list
  27. 'duration': 90,
  28. 'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo',
  29. },
  30. }, {
  31. 'url': 'http://www.wsj.com/video/can-alphabet-build-a-smarter-city/359DDAA8-9AC1-489C-82E6-0429C1E430E0.html',
  32. 'only_matching': True,
  33. }]
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. api_url = (
  37. 'http://video-api.wsj.com/api-video/find_all_videos.asp?'
  38. 'type=guid&count=1&query=%s&fields=type,hls,videoMP4List,'
  39. 'thumbnailList,author,description,name,duration,videoURL,'
  40. 'titletag,formattedCreationDate,keywords,editor' % video_id)
  41. info = self._download_json(api_url, video_id)['items'][0]
  42. title = info.get('name', info.get('titletag'))
  43. formats = []
  44. f4m_url = info.get('videoURL')
  45. if f4m_url:
  46. formats.extend(self._extract_f4m_formats(
  47. f4m_url, video_id, f4m_id='hds', fatal=False))
  48. m3u8_url = info.get('hls')
  49. if m3u8_url:
  50. formats.extend(self._extract_m3u8_formats(
  51. info['hls'], video_id, ext='mp4',
  52. entry_protocol='m3u8_native', m3u8_id='hls', fatal=False))
  53. for v in info.get('videoMP4List', []):
  54. mp4_url = v.get('url')
  55. if not mp4_url:
  56. continue
  57. tbr = int_or_none(v.get('bitrate'))
  58. formats.append({
  59. 'url': mp4_url,
  60. 'format_id': 'http' + ('-%d' % tbr if tbr else ''),
  61. 'tbr': tbr,
  62. 'width': int_or_none(v.get('width')),
  63. 'height': int_or_none(v.get('height')),
  64. 'fps': float_or_none(v.get('fps')),
  65. })
  66. self._sort_formats(formats)
  67. return {
  68. 'id': video_id,
  69. 'formats': formats,
  70. # Thumbnails are conveniently in the correct format already
  71. 'thumbnails': info.get('thumbnailList'),
  72. 'creator': info.get('author'),
  73. 'uploader_id': info.get('editor'),
  74. 'duration': int_or_none(info.get('duration')),
  75. 'upload_date': unified_strdate(info.get(
  76. 'formattedCreationDate'), day_first=False),
  77. 'title': title,
  78. 'categories': info.get('keywords'),
  79. }