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