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