]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/aol.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / aol.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 ExtractorError,
9 int_or_none,
10 url_or_none,
11 )
12
13
14 class AolIE(InfoExtractor):
15 IE_NAME = 'on.aol.com'
16 _VALID_URL = r'(?:aol-video:|https?://(?:(?:www|on)\.)?aol\.com/(?:[^/]+/)*(?:[^/?#&]+-)?)(?P<id>[^/?#&]+)'
17
18 _TESTS = [{
19 # video with 5min ID
20 'url': 'http://on.aol.com/video/u-s--official-warns-of-largest-ever-irs-phone-scam-518167793?icid=OnHomepageC2Wide_MustSee_Img',
21 'md5': '18ef68f48740e86ae94b98da815eec42',
22 'info_dict': {
23 'id': '518167793',
24 'ext': 'mp4',
25 'title': 'U.S. Official Warns Of \'Largest Ever\' IRS Phone Scam',
26 '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.',
27 'timestamp': 1395405060,
28 'upload_date': '20140321',
29 'uploader': 'Newsy Studio',
30 },
31 'params': {
32 # m3u8 download
33 'skip_download': True,
34 }
35 }, {
36 # video with vidible ID
37 'url': 'http://www.aol.com/video/view/netflix-is-raising-rates/5707d6b8e4b090497b04f706/',
38 'info_dict': {
39 'id': '5707d6b8e4b090497b04f706',
40 'ext': 'mp4',
41 'title': 'Netflix is Raising Rates',
42 'description': 'Netflix is rewarding millions of it’s long-standing members with an increase in cost. Veuer’s Carly Figueroa has more.',
43 'upload_date': '20160408',
44 'timestamp': 1460123280,
45 'uploader': 'Veuer',
46 },
47 'params': {
48 # m3u8 download
49 'skip_download': True,
50 }
51 }, {
52 'url': 'http://on.aol.com/partners/abc-551438d309eab105804dbfe8/sneak-peek-was-haley-really-framed-570eaebee4b0448640a5c944',
53 'only_matching': True,
54 }, {
55 'url': 'http://on.aol.com/shows/park-bench-shw518173474-559a1b9be4b0c3bfad3357a7?context=SH:SHW518173474:PL4327:1460619712763',
56 'only_matching': True,
57 }, {
58 'url': 'http://on.aol.com/video/519442220',
59 'only_matching': True,
60 }, {
61 'url': 'aol-video:5707d6b8e4b090497b04f706',
62 'only_matching': True,
63 }]
64
65 def _real_extract(self, url):
66 video_id = self._match_id(url)
67
68 response = self._download_json(
69 'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
70 video_id)['response']
71 if response['statusText'] != 'Ok':
72 raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusText']), expected=True)
73
74 video_data = response['data']
75 formats = []
76 m3u8_url = video_data.get('videoMasterPlaylist')
77 if m3u8_url:
78 formats.extend(self._extract_m3u8_formats(
79 m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
80 for rendition in video_data.get('renditions', []):
81 video_url = url_or_none(rendition.get('url'))
82 if not video_url:
83 continue
84 ext = rendition.get('format')
85 if ext == 'm3u8':
86 formats.extend(self._extract_m3u8_formats(
87 video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
88 else:
89 f = {
90 'url': video_url,
91 'format_id': rendition.get('quality'),
92 }
93 mobj = re.search(r'(\d+)x(\d+)', video_url)
94 if mobj:
95 f.update({
96 'width': int(mobj.group(1)),
97 'height': int(mobj.group(2)),
98 })
99 formats.append(f)
100 self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
101
102 return {
103 'id': video_id,
104 'title': video_data['title'],
105 'duration': int_or_none(video_data.get('duration')),
106 'timestamp': int_or_none(video_data.get('publishDate')),
107 'view_count': int_or_none(video_data.get('views')),
108 'description': video_data.get('description'),
109 'uploader': video_data.get('videoOwner'),
110 'formats': formats,
111 }