You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
5.0 KiB

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