aol.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import re
  2. from .yahoo import YahooIE
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. parse_qs,
  7. url_or_none,
  8. )
  9. class AolIE(YahooIE): # XXX: Do not subclass from concrete IE
  10. _WORKING = False
  11. IE_NAME = 'aol.com'
  12. _VALID_URL = r'(?:aol-video:|https?://(?:www\.)?aol\.(?:com|ca|co\.uk|de|jp)/video/(?:[^/]+/)*)(?P<id>\d{9}|[0-9a-f]{24}|[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})'
  13. _TESTS = [{
  14. # video with 5min ID
  15. 'url': 'https://www.aol.com/video/view/u-s--official-warns-of-largest-ever-irs-phone-scam/518167793/',
  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': 'https://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': 'https://www.aol.com/video/view/park-bench-season-2-trailer/559a1b9be4b0c3bfad3357a7/',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'https://www.aol.com/video/view/donald-trump-spokeswoman-tones-down-megyn-kelly-attacks/519442220/',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'aol-video:5707d6b8e4b090497b04f706',
  54. 'only_matching': True,
  55. }, {
  56. 'url': 'https://www.aol.com/video/playlist/PL8245/5ca79d19d21f1a04035db606/',
  57. 'only_matching': True,
  58. }, {
  59. 'url': 'https://www.aol.ca/video/view/u-s-woman-s-family-arrested-for-murder-first-pinned-on-panhandler-police/5c7ccf45bc03931fa04b2fe1/',
  60. 'only_matching': True,
  61. }, {
  62. 'url': 'https://www.aol.co.uk/video/view/-one-dead-and-22-hurt-in-bus-crash-/5cb3a6f3d21f1a072b457347/',
  63. 'only_matching': True,
  64. }, {
  65. 'url': 'https://www.aol.de/video/view/eva-braun-privataufnahmen-von-hitlers-geliebter-werden-digitalisiert/5cb2d49de98ab54c113d3d5d/',
  66. 'only_matching': True,
  67. }, {
  68. 'url': 'https://www.aol.jp/video/playlist/5a28e936a1334d000137da0c/5a28f3151e642219fde19831/',
  69. 'only_matching': True,
  70. }, {
  71. # Yahoo video
  72. 'url': 'https://www.aol.com/video/play/991e6700-ac02-11ea-99ff-357400036f61/24bbc846-3e30-3c46-915e-fe8ccd7fcc46/',
  73. 'only_matching': True,
  74. }]
  75. def _real_extract(self, url):
  76. video_id = self._match_id(url)
  77. if '-' in video_id:
  78. return self._extract_yahoo_video(video_id, 'us')
  79. response = self._download_json(
  80. f'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/{video_id}/details',
  81. video_id)['response']
  82. if response['statusText'] != 'Ok':
  83. raise ExtractorError('{} said: {}'.format(self.IE_NAME, response['statusText']), expected=True)
  84. video_data = response['data']
  85. formats = []
  86. m3u8_url = url_or_none(video_data.get('videoMasterPlaylist'))
  87. if m3u8_url:
  88. formats.extend(self._extract_m3u8_formats(
  89. m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  90. for rendition in video_data.get('renditions', []):
  91. video_url = url_or_none(rendition.get('url'))
  92. if not video_url:
  93. continue
  94. ext = rendition.get('format')
  95. if ext == 'm3u8':
  96. formats.extend(self._extract_m3u8_formats(
  97. video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  98. else:
  99. f = {
  100. 'url': video_url,
  101. 'format_id': rendition.get('quality'),
  102. }
  103. mobj = re.search(r'(\d+)x(\d+)', video_url)
  104. if mobj:
  105. f.update({
  106. 'width': int(mobj.group(1)),
  107. 'height': int(mobj.group(2)),
  108. })
  109. else:
  110. qs = parse_qs(video_url)
  111. f.update({
  112. 'width': int_or_none(qs.get('w', [None])[0]),
  113. 'height': int_or_none(qs.get('h', [None])[0]),
  114. })
  115. formats.append(f)
  116. return {
  117. 'id': video_id,
  118. 'title': video_data['title'],
  119. 'duration': int_or_none(video_data.get('duration')),
  120. 'timestamp': int_or_none(video_data.get('publishDate')),
  121. 'view_count': int_or_none(video_data.get('views')),
  122. 'description': video_data.get('description'),
  123. 'uploader': video_data.get('videoOwner'),
  124. 'formats': formats,
  125. }