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.4 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. unified_strdate,
  7. )
  8. class WSJIE(InfoExtractor):
  9. _VALID_URL = r'https?://video-api\.wsj\.com/api-video/player/iframe\.html\?guid=(?P<id>[a-zA-Z0-9-]+)'
  10. IE_DESC = 'Wall Street Journal'
  11. _TEST = {
  12. 'url': 'http://video-api.wsj.com/api-video/player/iframe.html?guid=1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
  13. 'md5': '9747d7a6ebc2f4df64b981e1dde9efa9',
  14. 'info_dict': {
  15. 'id': '1BD01A4C-BFE8-40A5-A42F-8A8AF9898B1A',
  16. 'ext': 'mp4',
  17. 'upload_date': '20150202',
  18. 'uploader_id': 'bbright',
  19. 'creator': 'bbright',
  20. 'categories': list, # a long list
  21. 'duration': 90,
  22. 'title': 'Bills Coach Rex Ryan Updates His Old Jets Tattoo',
  23. },
  24. }
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. bitrates = [128, 174, 264, 320, 464, 664, 1264]
  28. api_url = (
  29. 'http://video-api.wsj.com/api-video/find_all_videos.asp?'
  30. 'type=guid&count=1&query=%s&'
  31. 'fields=hls,adZone,thumbnailList,guid,state,secondsUntilStartTime,'
  32. 'author,description,name,linkURL,videoStillURL,duration,videoURL,'
  33. 'adCategory,catastrophic,linkShortURL,doctypeID,youtubeID,'
  34. 'titletag,rssURL,wsj-section,wsj-subsection,allthingsd-section,'
  35. 'allthingsd-subsection,sm-section,sm-subsection,provider,'
  36. 'formattedCreationDate,keywords,keywordsOmniture,column,editor,'
  37. 'emailURL,emailPartnerID,showName,omnitureProgramName,'
  38. 'omnitureVideoFormat,linkRelativeURL,touchCastID,'
  39. 'omniturePublishDate,%s') % (
  40. video_id, ','.join('video%dkMP4Url' % br for br in bitrates))
  41. info = self._download_json(api_url, video_id)['items'][0]
  42. # Thumbnails are conveniently in the correct format already
  43. thumbnails = info.get('thumbnailList')
  44. creator = info.get('author')
  45. uploader_id = info.get('editor')
  46. categories = info.get('keywords')
  47. duration = int_or_none(info.get('duration'))
  48. upload_date = unified_strdate(
  49. info.get('formattedCreationDate'), day_first=False)
  50. title = info.get('name', info.get('titletag'))
  51. formats = [{
  52. 'format_id': 'f4m',
  53. 'format_note': 'f4m (meta URL)',
  54. 'url': info['videoURL'],
  55. }]
  56. if info.get('hls'):
  57. formats.extend(self._extract_m3u8_formats(
  58. info['hls'], video_id, ext='mp4',
  59. preference=0, entry_protocol='m3u8_native'))
  60. for br in bitrates:
  61. field = 'video%dkMP4Url' % br
  62. if info.get(field):
  63. formats.append({
  64. 'format_id': 'mp4-%d' % br,
  65. 'container': 'mp4',
  66. 'tbr': br,
  67. 'url': info[field],
  68. })
  69. self._sort_formats(formats)
  70. return {
  71. 'id': video_id,
  72. 'formats': formats,
  73. 'thumbnails': thumbnails,
  74. 'creator': creator,
  75. 'uploader_id': uploader_id,
  76. 'duration': duration,
  77. 'upload_date': upload_date,
  78. 'title': title,
  79. 'formats': formats,
  80. 'categories': categories,
  81. }