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