]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/foxnews.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / foxnews.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .amp import AMPIE
6 from .common import InfoExtractor
7
8
9 class FoxNewsIE(AMPIE):
10 IE_NAME = 'foxnews'
11 IE_DESC = 'Fox News and Fox Business Video'
12 _VALID_URL = r'https?://(?P<host>video\.(?:insider\.)?fox(?:news|business)\.com)/v/(?:video-embed\.html\?video_id=)?(?P<id>\d+)'
13 _TESTS = [
14 {
15 'url': 'http://video.foxnews.com/v/3937480/frozen-in-time/#sp=show-clips',
16 'md5': '32aaded6ba3ef0d1c04e238d01031e5e',
17 'info_dict': {
18 'id': '3937480',
19 'ext': 'flv',
20 'title': 'Frozen in Time',
21 'description': '16-year-old girl is size of toddler',
22 'duration': 265,
23 'timestamp': 1304411491,
24 'upload_date': '20110503',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 },
27 },
28 {
29 'url': 'http://video.foxnews.com/v/3922535568001/rep-luis-gutierrez-on-if-obamas-immigration-plan-is-legal/#sp=show-clips',
30 'md5': '5846c64a1ea05ec78175421b8323e2df',
31 'info_dict': {
32 'id': '3922535568001',
33 'ext': 'mp4',
34 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
35 'description': "Congressman discusses president's plan",
36 'duration': 292,
37 'timestamp': 1417662047,
38 'upload_date': '20141204',
39 'thumbnail': r're:^https?://.*\.jpg$',
40 },
41 'params': {
42 # m3u8 download
43 'skip_download': True,
44 },
45 },
46 {
47 'url': 'http://video.foxnews.com/v/video-embed.html?video_id=3937480&d=video.foxnews.com',
48 'only_matching': True,
49 },
50 {
51 'url': 'http://video.foxbusiness.com/v/4442309889001',
52 'only_matching': True,
53 },
54 {
55 # From http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words
56 'url': 'http://video.insider.foxnews.com/v/video-embed.html?video_id=5099377331001&autoplay=true&share_url=http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words&share_title=Student%20Group:%20Saying%20%27Politically%20Correct,%27%20%27Trash%27%20and%20%27Lame%27%20Is%20Offensive&share=true',
57 'only_matching': True,
58 },
59 ]
60
61 @staticmethod
62 def _extract_urls(webpage):
63 return [
64 mobj.group('url')
65 for mobj in re.finditer(
66 r'<(?:amp-)?iframe[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?//video\.foxnews\.com/v/video-embed\.html?.*?\bvideo_id=\d+.*?)\1',
67 webpage)]
68
69 def _real_extract(self, url):
70 host, video_id = re.match(self._VALID_URL, url).groups()
71
72 info = self._extract_feed_info(
73 'http://%s/v/feed/video/%s.js?template=fox' % (host, video_id))
74 info['id'] = video_id
75 return info
76
77
78 class FoxNewsArticleIE(InfoExtractor):
79 _VALID_URL = r'https?://(?:www\.)?(?:insider\.)?foxnews\.com/(?!v)([^/]+/)+(?P<id>[a-z-]+)'
80 IE_NAME = 'foxnews:article'
81
82 _TESTS = [{
83 # data-video-id
84 'url': 'http://www.foxnews.com/politics/2016/09/08/buzz-about-bud-clinton-camp-denies-claims-wore-earpiece-at-forum.html',
85 'md5': '83d44e1aff1433e7a29a7b537d1700b5',
86 'info_dict': {
87 'id': '5116295019001',
88 'ext': 'mp4',
89 'title': 'Trump and Clinton asked to defend positions on Iraq War',
90 'description': 'Veterans react on \'The Kelly File\'',
91 'timestamp': 1473301045,
92 'upload_date': '20160908',
93 },
94 }, {
95 # iframe embed
96 'url': 'http://www.foxnews.com/us/2018/03/09/parkland-survivor-kyle-kashuv-on-meeting-trump-his-app-to-prevent-another-school-shooting.amp.html?__twitter_impression=true',
97 'info_dict': {
98 'id': '5748266721001',
99 'ext': 'flv',
100 'title': 'Kyle Kashuv has a positive message for the Trump White House',
101 'description': 'Marjory Stoneman Douglas student disagrees with classmates.',
102 'thumbnail': r're:^https?://.*\.jpg$',
103 'duration': 229,
104 'timestamp': 1520594670,
105 'upload_date': '20180309',
106 },
107 'params': {
108 'skip_download': True,
109 },
110 }, {
111 'url': 'http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words',
112 'only_matching': True,
113 }]
114
115 def _real_extract(self, url):
116 display_id = self._match_id(url)
117 webpage = self._download_webpage(url, display_id)
118
119 video_id = self._html_search_regex(
120 r'data-video-id=([\'"])(?P<id>[^\'"]+)\1',
121 webpage, 'video ID', group='id', default=None)
122 if video_id:
123 return self.url_result(
124 'http://video.foxnews.com/v/' + video_id, FoxNewsIE.ie_key())
125
126 return self.url_result(
127 FoxNewsIE._extract_urls(webpage)[0], FoxNewsIE.ie_key())