]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/foxnews.py
[dailymotion] Error spelling
[youtube-dl] / youtube_dl / extractor / foxnews.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7     parse_iso8601,
8     int_or_none,
9 )
10
11
12 class FoxNewsIE(InfoExtractor):
13     IE_DESC = 'Fox News and Fox Business Video'
14     _VALID_URL = r'https?://(?P<host>video\.fox(?:news|business)\.com)/v/(?:video-embed\.html\?video_id=)?(?P<id>\d+)'
15     _TESTS = [
16         {
17             'url': 'http://video.foxnews.com/v/3937480/frozen-in-time/#sp=show-clips',
18             'md5': '32aaded6ba3ef0d1c04e238d01031e5e',
19             'info_dict': {
20                 'id': '3937480',
21                 'ext': 'flv',
22                 'title': 'Frozen in Time',
23                 'description': 'Doctors baffled by 16-year-old girl that is the size of a toddler',
24                 'duration': 265,
25                 'timestamp': 1304411491,
26                 'upload_date': '20110503',
27                 'thumbnail': 're:^https?://.*\.jpg$',
28             },
29         },
30         {
31             'url': 'http://video.foxnews.com/v/3922535568001/rep-luis-gutierrez-on-if-obamas-immigration-plan-is-legal/#sp=show-clips',
32             'md5': '5846c64a1ea05ec78175421b8323e2df',
33             'info_dict': {
34                 'id': '3922535568001',
35                 'ext': 'mp4',
36                 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
37                 'description': "Congressman discusses the president's executive action",
38                 'duration': 292,
39                 'timestamp': 1417662047,
40                 'upload_date': '20141204',
41                 'thumbnail': 're:^https?://.*\.jpg$',
42             },
43         },
44         {
45             'url': 'http://video.foxnews.com/v/video-embed.html?video_id=3937480&d=video.foxnews.com',
46             'only_matching': True,
47         },
48         {
49             'url': 'http://video.foxbusiness.com/v/4442309889001',
50             'only_matching': True,
51         },
52     ]
53
54     def _real_extract(self, url):
55         mobj = re.match(self._VALID_URL, url)
56         video_id = mobj.group('id')
57         host = mobj.group('host')
58
59         video = self._download_json(
60             'http://%s/v/feed/video/%s.js?template=fox' % (host, video_id), video_id)
61
62         item = video['channel']['item']
63         title = item['title']
64         description = item['description']
65         timestamp = parse_iso8601(item['dc-date'])
66
67         media_group = item['media-group']
68         duration = None
69         formats = []
70         for media in media_group['media-content']:
71             attributes = media['@attributes']
72             video_url = attributes['url']
73             if video_url.endswith('.f4m'):
74                 formats.extend(self._extract_f4m_formats(video_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', video_id))
75             elif video_url.endswith('.m3u8'):
76                 formats.extend(self._extract_m3u8_formats(video_url, video_id, 'flv'))
77             elif not video_url.endswith('.smil'):
78                 duration = int_or_none(attributes.get('duration'))
79                 formats.append({
80                     'url': video_url,
81                     'format_id': media['media-category']['@attributes']['label'],
82                     'preference': 1,
83                     'vbr': int_or_none(attributes.get('bitrate')),
84                     'filesize': int_or_none(attributes.get('fileSize'))
85                 })
86         self._sort_formats(formats)
87
88         media_thumbnail = media_group['media-thumbnail']['@attributes']
89         thumbnails = [{
90             'url': media_thumbnail['url'],
91             'width': int_or_none(media_thumbnail.get('width')),
92             'height': int_or_none(media_thumbnail.get('height')),
93         }] if media_thumbnail else []
94
95         return {
96             'id': video_id,
97             'title': title,
98             'description': description,
99             'duration': duration,
100             'timestamp': timestamp,
101             'formats': formats,
102             'thumbnails': thumbnails,
103         }