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