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.

111 lines
4.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. url_or_none,
  9. )
  10. class AolIE(InfoExtractor):
  11. IE_NAME = 'on.aol.com'
  12. _VALID_URL = r'(?:aol-video:|https?://(?:(?:www|on)\.)?aol\.com/(?:[^/]+/)*(?:[^/?#&]+-)?)(?P<id>[^/?#&]+)'
  13. _TESTS = [{
  14. # video with 5min ID
  15. 'url': 'http://on.aol.com/video/u-s--official-warns-of-largest-ever-irs-phone-scam-518167793?icid=OnHomepageC2Wide_MustSee_Img',
  16. 'md5': '18ef68f48740e86ae94b98da815eec42',
  17. 'info_dict': {
  18. 'id': '518167793',
  19. 'ext': 'mp4',
  20. 'title': 'U.S. Official Warns Of \'Largest Ever\' IRS Phone Scam',
  21. '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.',
  22. 'timestamp': 1395405060,
  23. 'upload_date': '20140321',
  24. 'uploader': 'Newsy Studio',
  25. },
  26. 'params': {
  27. # m3u8 download
  28. 'skip_download': True,
  29. }
  30. }, {
  31. # video with vidible ID
  32. 'url': 'http://www.aol.com/video/view/netflix-is-raising-rates/5707d6b8e4b090497b04f706/',
  33. 'info_dict': {
  34. 'id': '5707d6b8e4b090497b04f706',
  35. 'ext': 'mp4',
  36. 'title': 'Netflix is Raising Rates',
  37. 'description': 'Netflix is rewarding millions of it’s long-standing members with an increase in cost. Veuer’s Carly Figueroa has more.',
  38. 'upload_date': '20160408',
  39. 'timestamp': 1460123280,
  40. 'uploader': 'Veuer',
  41. },
  42. 'params': {
  43. # m3u8 download
  44. 'skip_download': True,
  45. }
  46. }, {
  47. 'url': 'http://on.aol.com/partners/abc-551438d309eab105804dbfe8/sneak-peek-was-haley-really-framed-570eaebee4b0448640a5c944',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'http://on.aol.com/shows/park-bench-shw518173474-559a1b9be4b0c3bfad3357a7?context=SH:SHW518173474:PL4327:1460619712763',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'http://on.aol.com/video/519442220',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'aol-video:5707d6b8e4b090497b04f706',
  57. 'only_matching': True,
  58. }]
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. response = self._download_json(
  62. 'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
  63. video_id)['response']
  64. if response['statusText'] != 'Ok':
  65. raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusText']), expected=True)
  66. video_data = response['data']
  67. formats = []
  68. m3u8_url = video_data.get('videoMasterPlaylist')
  69. if m3u8_url:
  70. formats.extend(self._extract_m3u8_formats(
  71. m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  72. for rendition in video_data.get('renditions', []):
  73. video_url = url_or_none(rendition.get('url'))
  74. if not video_url:
  75. continue
  76. ext = rendition.get('format')
  77. if ext == 'm3u8':
  78. formats.extend(self._extract_m3u8_formats(
  79. video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  80. else:
  81. f = {
  82. 'url': video_url,
  83. 'format_id': rendition.get('quality'),
  84. }
  85. mobj = re.search(r'(\d+)x(\d+)', video_url)
  86. if mobj:
  87. f.update({
  88. 'width': int(mobj.group(1)),
  89. 'height': int(mobj.group(2)),
  90. })
  91. formats.append(f)
  92. self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
  93. return {
  94. 'id': video_id,
  95. 'title': video_data['title'],
  96. 'duration': int_or_none(video_data.get('duration')),
  97. 'timestamp': int_or_none(video_data.get('publishDate')),
  98. 'view_count': int_or_none(video_data.get('views')),
  99. 'description': video_data.get('description'),
  100. 'uploader': video_data.get('videoOwner'),
  101. 'formats': formats,
  102. }