]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/foxnews.py
[extractor/youtube] Extract uploader metadata for feed/playlist items
[yt-dlp.git] / yt_dlp / extractor / foxnews.py
1 import re
2
3 from .amp import AMPIE
4 from .common import InfoExtractor
5
6
7 class FoxNewsIE(AMPIE):
8 IE_NAME = 'foxnews'
9 IE_DESC = 'Fox News and Fox Business Video'
10 _VALID_URL = r'https?://(?P<host>video\.(?:insider\.)?fox(?:news|business)\.com)/v/(?:video-embed\.html\?video_id=)?(?P<id>\d+)'
11 _TESTS = [
12 {
13 'url': 'http://video.foxnews.com/v/3937480/frozen-in-time/#sp=show-clips',
14 'md5': '32aaded6ba3ef0d1c04e238d01031e5e',
15 'info_dict': {
16 'id': '3937480',
17 'ext': 'flv',
18 'title': 'Frozen in Time',
19 'description': '16-year-old girl is size of toddler',
20 'duration': 265,
21 'timestamp': 1304411491,
22 'upload_date': '20110503',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 },
25 },
26 {
27 'url': 'http://video.foxnews.com/v/3922535568001/rep-luis-gutierrez-on-if-obamas-immigration-plan-is-legal/#sp=show-clips',
28 'md5': '5846c64a1ea05ec78175421b8323e2df',
29 'info_dict': {
30 'id': '3922535568001',
31 'ext': 'mp4',
32 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
33 'description': "Congressman discusses president's plan",
34 'duration': 292,
35 'timestamp': 1417662047,
36 'upload_date': '20141204',
37 'thumbnail': r're:^https?://.*\.jpg$',
38 },
39 'params': {
40 # m3u8 download
41 'skip_download': True,
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 # From http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words
54 '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',
55 'only_matching': True,
56 },
57 ]
58
59 @classmethod
60 def _extract_embed_urls(cls, url, webpage):
61 for mobj in re.finditer(
62 r'''(?x)
63 <(?:script|(?:amp-)?iframe)[^>]+\bsrc=["\']
64 (?:https?:)?//video\.foxnews\.com/v/(?:video-embed\.html|embed\.js)\?
65 (?:[^>"\']+&)?(?:video_)?id=(?P<video_id>\d+)
66 ''', webpage):
67 yield f'https://video.foxnews.com/v/video-embed.html?video_id={mobj.group("video_id")}'
68
69 def _real_extract(self, url):
70 host, video_id = self._match_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 FoxNewsVideoIE(InfoExtractor):
79 _VALID_URL = r'https?://(?:www\.)?foxnews\.com/video/(?P<id>\d+)'
80 _TESTS = [{
81 'url': 'https://www.foxnews.com/video/6313058664112',
82 'info_dict': {
83 'id': '6313058664112',
84 'ext': 'mp4',
85 'thumbnail': r're:https://.+/1280x720/match/image\.jpg',
86 'upload_date': '20220930',
87 'description': 'New York City, Kids Therapy, Biden',
88 'duration': 2415,
89 'title': 'Gutfeld! - Thursday, September 29',
90 'timestamp': 1664527538,
91 },
92 'expected_warnings': ['Ignoring subtitle tracks'],
93 'params': {'skip_download': 'm3u8'},
94 }]
95
96 def _real_extract(self, url):
97 video_id = self._match_id(url)
98 return self.url_result(f'https://video.foxnews.com/v/{video_id}', FoxNewsIE, video_id)
99
100
101 class FoxNewsArticleIE(InfoExtractor):
102 _VALID_URL = r'https?://(?:www\.)?(?:insider\.)?foxnews\.com/(?!v)([^/]+/)+(?P<id>[a-z-]+)'
103 IE_NAME = 'foxnews:article'
104
105 _TESTS = [{
106 # data-video-id
107 'url': 'http://www.foxnews.com/politics/2016/09/08/buzz-about-bud-clinton-camp-denies-claims-wore-earpiece-at-forum.html',
108 'md5': '83d44e1aff1433e7a29a7b537d1700b5',
109 'info_dict': {
110 'id': '5116295019001',
111 'ext': 'mp4',
112 'title': 'Trump and Clinton asked to defend positions on Iraq War',
113 'description': 'Veterans react on \'The Kelly File\'',
114 'timestamp': 1473301045,
115 'upload_date': '20160908',
116 },
117 }, {
118 # iframe embed
119 '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',
120 'info_dict': {
121 'id': '5748266721001',
122 'ext': 'flv',
123 'title': 'Kyle Kashuv has a positive message for the Trump White House',
124 'description': 'Marjory Stoneman Douglas student disagrees with classmates.',
125 'thumbnail': r're:^https?://.*\.jpg$',
126 'duration': 229,
127 'timestamp': 1520594670,
128 'upload_date': '20180309',
129 },
130 'params': {
131 'skip_download': True,
132 },
133 }, {
134 'url': 'http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words',
135 'only_matching': True,
136 }]
137
138 def _real_extract(self, url):
139 display_id = self._match_id(url)
140 webpage = self._download_webpage(url, display_id)
141
142 video_id = self._html_search_regex(
143 r'data-video-id=([\'"])(?P<id>[^\'"]+)\1',
144 webpage, 'video ID', group='id', default=None)
145 if video_id:
146 return self.url_result(
147 'http://video.foxnews.com/v/' + video_id, FoxNewsIE.ie_key())
148
149 return self.url_result(
150 next(FoxNewsIE._extract_embed_urls(url, webpage)), FoxNewsIE.ie_key())