foxnews.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import re
  2. from .amp import AMPIE
  3. from .common import InfoExtractor
  4. class FoxNewsIE(AMPIE):
  5. IE_NAME = 'foxnews'
  6. IE_DESC = 'Fox News and Fox Business Video'
  7. _VALID_URL = r'https?://video\.(?:insider\.)?fox(?:news|business)\.com/v/(?:video-embed\.html\?video_id=)?(?P<id>\d+)'
  8. _TESTS = [
  9. {
  10. 'url': 'https://video.foxnews.com/v/6320653836112',
  11. 'info_dict': {
  12. 'id': '6320653836112',
  13. 'ext': 'mp4',
  14. 'title': 'Tucker Carlson joins \'Gutfeld!\' to discuss his new documentary',
  15. 'thumbnail': r're:^https?://.*\.jpg$',
  16. 'duration': 404,
  17. 'upload_date': '20230217',
  18. 'description': 'md5:858a8a36f59e9ca897d758855bcdfa02',
  19. 'timestamp': 1676611344.0,
  20. },
  21. 'params': {'skip_download': 'm3u8'},
  22. },
  23. {
  24. # From http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words
  25. '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',
  26. 'info_dict': {
  27. 'id': '5099377331001',
  28. 'ext': 'mp4',
  29. 'title': '82416_censoring',
  30. 'description': '82416_censoring',
  31. 'upload_date': '20160826',
  32. 'timestamp': 1472169708.0,
  33. 'thumbnail': r're:^https?://.*\.jpg$',
  34. 'duration': 521,
  35. },
  36. 'params': {'skip_download': 'm3u8'},
  37. },
  38. {
  39. 'url': 'http://video.foxnews.com/v/3937480/frozen-in-time/#sp=show-clips',
  40. 'md5': '32aaded6ba3ef0d1c04e238d01031e5e',
  41. 'info_dict': {
  42. 'id': '3937480',
  43. 'ext': 'flv',
  44. 'title': 'Frozen in Time',
  45. 'description': '16-year-old girl is size of toddler',
  46. 'duration': 265,
  47. 'timestamp': 1304411491,
  48. 'upload_date': '20110503',
  49. 'thumbnail': r're:^https?://.*\.jpg$',
  50. },
  51. 'skip': '404 page',
  52. },
  53. {
  54. 'url': 'http://video.foxnews.com/v/3922535568001/rep-luis-gutierrez-on-if-obamas-immigration-plan-is-legal/#sp=show-clips',
  55. 'md5': '5846c64a1ea05ec78175421b8323e2df',
  56. 'info_dict': {
  57. 'id': '3922535568001',
  58. 'ext': 'mp4',
  59. 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
  60. 'description': "Congressman discusses president's plan",
  61. 'duration': 292,
  62. 'timestamp': 1417662047,
  63. 'upload_date': '20141204',
  64. 'thumbnail': r're:^https?://.*\.jpg$',
  65. },
  66. 'skip': 'm3u8 HTTP error 400 in web browser',
  67. },
  68. {
  69. 'url': 'http://video.foxnews.com/v/video-embed.html?video_id=3937480&d=video.foxnews.com',
  70. 'only_matching': True,
  71. },
  72. {
  73. 'url': 'http://video.foxbusiness.com/v/4442309889001',
  74. 'only_matching': True,
  75. },
  76. ]
  77. @classmethod
  78. def _extract_embed_urls(cls, url, webpage):
  79. for mobj in re.finditer(
  80. r'''(?x)
  81. <(?:script|(?:amp-)?iframe)[^>]+\bsrc=["\']
  82. (?:https?:)?//video\.foxnews\.com/v/(?:video-embed\.html|embed\.js)\?
  83. (?:[^>"\']+&)?(?:video_)?id=(?P<video_id>\d+)
  84. ''', webpage):
  85. yield f'https://video.foxnews.com/v/video-embed.html?video_id={mobj.group("video_id")}'
  86. def _real_extract(self, url):
  87. video_id = self._match_id(url)
  88. info = self._extract_feed_info(
  89. f'https://api.foxnews.com/v3/video-player/{video_id}?callback=uid_{video_id}')
  90. info['id'] = video_id
  91. return info
  92. class FoxNewsVideoIE(InfoExtractor):
  93. _VALID_URL = r'https?://(?:www\.)?foxnews\.com/video/(?P<id>\d+)'
  94. _TESTS = [{
  95. 'url': 'https://www.foxnews.com/video/6328632286112',
  96. 'info_dict': {
  97. 'id': '6328632286112',
  98. 'ext': 'mp4',
  99. 'title': 'Review: 2023 Toyota Prius Prime',
  100. 'duration': 155,
  101. 'thumbnail': r're:^https://.+\.jpg$',
  102. 'timestamp': 1685720177.0,
  103. 'upload_date': '20230602',
  104. 'description': 'md5:b69aafb125b41c1402e9744f53d6edc4',
  105. },
  106. 'params': {'skip_download': 'm3u8'},
  107. }, {
  108. 'url': 'https://www.foxnews.com/video/6313058664112',
  109. 'info_dict': {
  110. 'id': '6313058664112',
  111. 'ext': 'mp4',
  112. 'thumbnail': r're:https://.+/1280x720/match/image\.jpg',
  113. 'upload_date': '20220930',
  114. 'description': 'New York City, Kids Therapy, Biden',
  115. 'duration': 2415,
  116. 'title': 'Gutfeld! - Thursday, September 29',
  117. 'timestamp': 1664527538,
  118. },
  119. 'skip': '404 page',
  120. }]
  121. def _real_extract(self, url):
  122. video_id = self._match_id(url)
  123. return self.url_result(f'https://video.foxnews.com/v/{video_id}', FoxNewsIE, video_id)
  124. class FoxNewsArticleIE(InfoExtractor):
  125. _VALID_URL = r'https?://(?:www\.)?(?:insider\.)?foxnews\.com/(?!v)([^/]+/)+(?P<id>[a-z-]+)'
  126. IE_NAME = 'foxnews:article'
  127. _TESTS = [{
  128. # data-video-id
  129. 'url': 'https://www.foxnews.com/politics/2016/09/08/buzz-about-bud-clinton-camp-denies-claims-wore-earpiece-at-forum.html',
  130. 'md5': 'd2dd6ce809cedeefa96460e964821437',
  131. 'info_dict': {
  132. 'id': '5116295019001',
  133. 'ext': 'mp4',
  134. 'title': 'Trump and Clinton asked to defend positions on Iraq War',
  135. 'description': 'Veterans and Fox News host Dana Perino react on \'The Kelly File\' to NBC\'s presidential forum',
  136. 'timestamp': 1473301045,
  137. 'upload_date': '20160908',
  138. 'thumbnail': r're:^https?://.*\.jpg$',
  139. 'duration': 426,
  140. },
  141. 'params': {'skip_download': 'm3u8'},
  142. }, {
  143. # iframe embed
  144. 'url': 'https://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',
  145. 'info_dict': {
  146. 'id': '5748266721001',
  147. 'ext': 'flv',
  148. 'title': 'Kyle Kashuv has a positive message for the Trump White House',
  149. 'description': 'Marjory Stoneman Douglas student disagrees with classmates.',
  150. 'thumbnail': r're:^https?://.*\.jpg$',
  151. 'duration': 229,
  152. 'timestamp': 1520594670,
  153. 'upload_date': '20180309',
  154. },
  155. 'skip': '404 page',
  156. }, {
  157. 'url': 'http://insider.foxnews.com/2016/08/25/univ-wisconsin-student-group-pushing-silence-certain-words',
  158. 'only_matching': True,
  159. }]
  160. def _real_extract(self, url):
  161. display_id = self._match_id(url)
  162. webpage = self._download_webpage(url, display_id)
  163. video_id = self._html_search_regex(
  164. r'data-video-id=([\'"])(?P<id>[^\'"]+)\1',
  165. webpage, 'video ID', group='id', default=None)
  166. if video_id:
  167. return self.url_result(
  168. 'http://video.foxnews.com/v/' + video_id, FoxNewsIE.ie_key())
  169. return self.url_result(
  170. next(FoxNewsIE._extract_embed_urls(url, webpage)), FoxNewsIE.ie_key())