logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

aol.py (5648B)


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