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