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. IE_NAME = 'aol.com'
  11. _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})'
  12. _TESTS = [{
  13. # video with 5min ID
  14. 'url': 'https://www.aol.com/video/view/u-s--official-warns-of-largest-ever-irs-phone-scam/518167793/',
  15. 'md5': '18ef68f48740e86ae94b98da815eec42',
  16. 'info_dict': {
  17. 'id': '518167793',
  18. 'ext': 'mp4',
  19. 'title': 'U.S. Official Warns Of \'Largest Ever\' IRS Phone Scam',
  20. '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.',
  21. 'timestamp': 1395405060,
  22. 'upload_date': '20140321',
  23. 'uploader': 'Newsy Studio',
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. }
  29. }, {
  30. # video with vidible ID
  31. 'url': 'https://www.aol.com/video/view/netflix-is-raising-rates/5707d6b8e4b090497b04f706/',
  32. 'info_dict': {
  33. 'id': '5707d6b8e4b090497b04f706',
  34. 'ext': 'mp4',
  35. 'title': 'Netflix is Raising Rates',
  36. 'description': 'Netflix is rewarding millions of it’s long-standing members with an increase in cost. Veuer’s Carly Figueroa has more.',
  37. 'upload_date': '20160408',
  38. 'timestamp': 1460123280,
  39. 'uploader': 'Veuer',
  40. },
  41. 'params': {
  42. # m3u8 download
  43. 'skip_download': True,
  44. }
  45. }, {
  46. 'url': 'https://www.aol.com/video/view/park-bench-season-2-trailer/559a1b9be4b0c3bfad3357a7/',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://www.aol.com/video/view/donald-trump-spokeswoman-tones-down-megyn-kelly-attacks/519442220/',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'aol-video:5707d6b8e4b090497b04f706',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'https://www.aol.com/video/playlist/PL8245/5ca79d19d21f1a04035db606/',
  56. 'only_matching': True,
  57. }, {
  58. 'url': 'https://www.aol.ca/video/view/u-s-woman-s-family-arrested-for-murder-first-pinned-on-panhandler-police/5c7ccf45bc03931fa04b2fe1/',
  59. 'only_matching': True,
  60. }, {
  61. 'url': 'https://www.aol.co.uk/video/view/-one-dead-and-22-hurt-in-bus-crash-/5cb3a6f3d21f1a072b457347/',
  62. 'only_matching': True,
  63. }, {
  64. 'url': 'https://www.aol.de/video/view/eva-braun-privataufnahmen-von-hitlers-geliebter-werden-digitalisiert/5cb2d49de98ab54c113d3d5d/',
  65. 'only_matching': True,
  66. }, {
  67. 'url': 'https://www.aol.jp/video/playlist/5a28e936a1334d000137da0c/5a28f3151e642219fde19831/',
  68. 'only_matching': True,
  69. }, {
  70. # Yahoo video
  71. 'url': 'https://www.aol.com/video/play/991e6700-ac02-11ea-99ff-357400036f61/24bbc846-3e30-3c46-915e-fe8ccd7fcc46/',
  72. 'only_matching': True,
  73. }]
  74. def _real_extract(self, url):
  75. video_id = self._match_id(url)
  76. if '-' in video_id:
  77. return self._extract_yahoo_video(video_id, 'us')
  78. response = self._download_json(
  79. 'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
  80. video_id)['response']
  81. if response['statusText'] != 'Ok':
  82. raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusText']), expected=True)
  83. video_data = response['data']
  84. formats = []
  85. m3u8_url = url_or_none(video_data.get('videoMasterPlaylist'))
  86. if m3u8_url:
  87. formats.extend(self._extract_m3u8_formats(
  88. m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  89. for rendition in video_data.get('renditions', []):
  90. video_url = url_or_none(rendition.get('url'))
  91. if not video_url:
  92. continue
  93. ext = rendition.get('format')
  94. if ext == 'm3u8':
  95. formats.extend(self._extract_m3u8_formats(
  96. video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  97. else:
  98. f = {
  99. 'url': video_url,
  100. 'format_id': rendition.get('quality'),
  101. }
  102. mobj = re.search(r'(\d+)x(\d+)', video_url)
  103. if mobj:
  104. f.update({
  105. 'width': int(mobj.group(1)),
  106. 'height': int(mobj.group(2)),
  107. })
  108. else:
  109. qs = parse_qs(video_url)
  110. f.update({
  111. 'width': int_or_none(qs.get('w', [None])[0]),
  112. 'height': int_or_none(qs.get('h', [None])[0]),
  113. })
  114. formats.append(f)
  115. return {
  116. 'id': video_id,
  117. 'title': video_data['title'],
  118. 'duration': int_or_none(video_data.get('duration')),
  119. 'timestamp': int_or_none(video_data.get('publishDate')),
  120. 'view_count': int_or_none(video_data.get('views')),
  121. 'description': video_data.get('description'),
  122. 'uploader': video_data.get('videoOwner'),
  123. 'formats': formats,
  124. }