aol.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. int_or_none,
  7. )
  8. class AolIE(InfoExtractor):
  9. IE_NAME = 'on.aol.com'
  10. _VALID_URL = r'(?:aol-video:|https?://on\.aol\.com/video/.*-)(?P<id>[^/?-]+)'
  11. _TESTS = [{
  12. 'url': 'http://on.aol.com/video/u-s--official-warns-of-largest-ever-irs-phone-scam-518167793?icid=OnHomepageC2Wide_MustSee_Img',
  13. 'md5': '18ef68f48740e86ae94b98da815eec42',
  14. 'info_dict': {
  15. 'id': '518167793',
  16. 'ext': 'mp4',
  17. 'title': 'U.S. Official Warns Of \'Largest Ever\' IRS Phone Scam',
  18. 'description': 'A major phone scam has cost thousands of taxpayers more than $1 million, with less than a month until income tax returns are due to the IRS.',
  19. 'timestamp': 1395405060,
  20. 'upload_date': '20140321',
  21. 'uploader': 'Newsy Studio',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. }
  27. }, {
  28. 'url': 'http://on.aol.com/video/netflix-is-raising-rates-5707d6b8e4b090497b04f706?context=PC:homepage:PL1944:1460189336183',
  29. 'info_dict': {
  30. 'id': '5707d6b8e4b090497b04f706',
  31. 'ext': 'mp4',
  32. 'title': 'Netflix is Raising Rates',
  33. 'description': 'Netflix is rewarding millions of it’s long-standing members with an increase in cost. Veuer’s Carly Figueroa has more.',
  34. 'upload_date': '20160408',
  35. 'timestamp': 1460123280,
  36. 'uploader': 'Veuer',
  37. },
  38. 'params': {
  39. # m3u8 download
  40. 'skip_download': True,
  41. }
  42. }]
  43. def _real_extract(self, url):
  44. video_id = self._match_id(url)
  45. response = self._download_json(
  46. 'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
  47. video_id)['response']
  48. if response['statusText'] != 'Ok':
  49. raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusText']), expected=True)
  50. video_data = response['data']
  51. formats = []
  52. m3u8_url = video_data.get('videoMasterPlaylist')
  53. if m3u8_url:
  54. formats.extend(self._extract_m3u8_formats(
  55. m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  56. for rendition in video_data.get('renditions', []):
  57. video_url = rendition.get('url')
  58. if not video_url:
  59. continue
  60. ext = rendition.get('format')
  61. if ext == 'm3u8':
  62. formats.extend(self._extract_m3u8_formats(
  63. video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  64. else:
  65. f = {
  66. 'url': video_url,
  67. 'format_id': rendition.get('quality'),
  68. }
  69. mobj = re.search(r'(\d+)x(\d+)', video_url)
  70. if mobj:
  71. f.update({
  72. 'width': int(mobj.group(1)),
  73. 'height': int(mobj.group(2)),
  74. })
  75. formats.append(f)
  76. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  77. return {
  78. 'id': video_id,
  79. 'title': video_data['title'],
  80. 'duration': int_or_none(video_data.get('duration')),
  81. 'timestamp': int_or_none(video_data.get('publishDate')),
  82. 'view_count': int_or_none(video_data.get('views')),
  83. 'description': video_data.get('description'),
  84. 'uploader': video_data.get('videoOwner'),
  85. 'formats': formats,
  86. }
  87. class AolFeaturesIE(InfoExtractor):
  88. IE_NAME = 'features.aol.com'
  89. _VALID_URL = r'https?://features\.aol\.com/video/(?P<id>[^/?#]+)'
  90. _TESTS = [{
  91. 'url': 'http://features.aol.com/video/behind-secret-second-careers-late-night-talk-show-hosts',
  92. 'md5': '7db483bb0c09c85e241f84a34238cc75',
  93. 'info_dict': {
  94. 'id': '519507715',
  95. 'ext': 'mp4',
  96. 'title': 'What To Watch - February 17, 2016',
  97. },
  98. 'add_ie': ['FiveMin'],
  99. }]
  100. def _real_extract(self, url):
  101. display_id = self._match_id(url)
  102. webpage = self._download_webpage(url, display_id)
  103. return self.url_result(self._search_regex(
  104. r'<script type="text/javascript" src="(https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js[^"]+)"',
  105. webpage, '5min embed url'), 'FiveMin')