[aol] add support for videos with vidible IDs(closes #9124)
[youtube-dl] / youtube_dl / extractor / aol.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     ExtractorError,
8     int_or_none,
9 )
10
11
12 class AolIE(InfoExtractor):
13     IE_NAME = 'on.aol.com'
14     _VALID_URL = r'(?:aol-video:|https?://on\.aol\.com/video/.*-)(?P<id>[^/?-]+)'
15
16     _TESTS = [{
17         'url': 'http://on.aol.com/video/u-s--official-warns-of-largest-ever-irs-phone-scam-518167793?icid=OnHomepageC2Wide_MustSee_Img',
18         'md5': '18ef68f48740e86ae94b98da815eec42',
19         'info_dict': {
20             'id': '518167793',
21             'ext': 'mp4',
22             'title': 'U.S. Official Warns Of \'Largest Ever\' IRS Phone Scam',
23             '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.',
24             'timestamp': 1395405060,
25             'upload_date': '20140321',
26             'uploader': 'Newsy Studio',
27         },
28         'params': {
29             # m3u8 download
30             'skip_download': True,
31         }
32     }, {
33         'url': 'http://on.aol.com/video/netflix-is-raising-rates-5707d6b8e4b090497b04f706?context=PC:homepage:PL1944:1460189336183',
34         'info_dict': {
35             'id': '5707d6b8e4b090497b04f706',
36             'ext': 'mp4',
37             'title': 'Netflix is Raising Rates',
38             'description': 'Netflix is rewarding millions of it’s long-standing members with an increase in cost. Veuer’s Carly Figueroa has more.',
39             'upload_date': '20160408',
40             'timestamp': 1460123280,
41             'uploader': 'Veuer',
42         },
43         'params': {
44             # m3u8 download
45             'skip_download': True,
46         }
47     }]
48
49     def _real_extract(self, url):
50         video_id = self._match_id(url)
51
52         response = self._download_json(
53             'https://feedapi.b2c.on.aol.com/v1.0/app/videos/aolon/%s/details' % video_id,
54             video_id)['response']
55         if response['statusText'] != 'Ok':
56             raise ExtractorError('%s said: %s' % (self.IE_NAME, response['statusText']), expected=True)
57
58         video_data = response['data']
59         formats = []
60         m3u8_url = video_data.get('videoMasterPlaylist')
61         if m3u8_url:
62             formats.extend(self._extract_m3u8_formats(
63                 m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
64         for rendition in video_data.get('renditions', []):
65             video_url = rendition.get('url')
66             if not video_url:
67                 continue
68             ext = rendition.get('format')
69             if ext == 'm3u8':
70                 formats.extend(self._extract_m3u8_formats(
71                     video_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
72             else:
73                 f = {
74                     'url': video_url,
75                     'format_id': rendition.get('quality'),
76                 }
77                 mobj = re.search(r'(\d+)x(\d+)', video_url)
78                 if mobj:
79                     f.update({
80                         'width': int(mobj.group(1)),
81                         'height': int(mobj.group(2)),
82                     })
83                 formats.append(f)
84         self._sort_formats(formats, ('width', 'height', 'tbr', 'format_id'))
85
86         return {
87             'id': video_id,
88             'title': video_data['title'],
89             'duration': int_or_none(video_data.get('duration')),
90             'timestamp': int_or_none(video_data.get('publishDate')),
91             'view_count': int_or_none(video_data.get('views')),
92             'description': video_data.get('description'),
93             'uploader': video_data.get('videoOwner'),
94             'formats': formats,
95         }
96
97
98 class AolFeaturesIE(InfoExtractor):
99     IE_NAME = 'features.aol.com'
100     _VALID_URL = r'https?://features\.aol\.com/video/(?P<id>[^/?#]+)'
101
102     _TESTS = [{
103         'url': 'http://features.aol.com/video/behind-secret-second-careers-late-night-talk-show-hosts',
104         'md5': '7db483bb0c09c85e241f84a34238cc75',
105         'info_dict': {
106             'id': '519507715',
107             'ext': 'mp4',
108             'title': 'What To Watch - February 17, 2016',
109         },
110         'add_ie': ['FiveMin'],
111     }]
112
113     def _real_extract(self, url):
114         display_id = self._match_id(url)
115         webpage = self._download_webpage(url, display_id)
116         return self.url_result(self._search_regex(
117             r'<script type="text/javascript" src="(https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js[^"]+)"',
118             webpage, '5min embed url'), 'FiveMin')