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.

103 lines
3.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. parse_iso8601,
  6. int_or_none,
  7. )
  8. class FoxNewsIE(InfoExtractor):
  9. IE_DESC = 'Fox News and Fox Business Video'
  10. _VALID_URL = r'https?://(?P<host>video\.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': 'Doctors baffled by 16-year-old girl that is the size of a toddler',
  20. 'duration': 265,
  21. 'timestamp': 1304411491,
  22. 'upload_date': '20110503',
  23. 'thumbnail': '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 the president's executive action",
  34. 'duration': 292,
  35. 'timestamp': 1417662047,
  36. 'upload_date': '20141204',
  37. 'thumbnail': 're:^https?://.*\.jpg$',
  38. },
  39. },
  40. {
  41. 'url': 'http://video.foxnews.com/v/video-embed.html?video_id=3937480&d=video.foxnews.com',
  42. 'only_matching': True,
  43. },
  44. {
  45. 'url': 'http://video.foxbusiness.com/v/4442309889001',
  46. 'only_matching': True,
  47. },
  48. ]
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. host = mobj.group('host')
  53. video = self._download_json(
  54. 'http://%s/v/feed/video/%s.js?template=fox' % (host, video_id), video_id)
  55. item = video['channel']['item']
  56. title = item['title']
  57. description = item['description']
  58. timestamp = parse_iso8601(item['dc-date'])
  59. media_group = item['media-group']
  60. duration = None
  61. formats = []
  62. for media in media_group['media-content']:
  63. attributes = media['@attributes']
  64. video_url = attributes['url']
  65. if video_url.endswith('.f4m'):
  66. formats.extend(self._extract_f4m_formats(video_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', video_id))
  67. elif video_url.endswith('.m3u8'):
  68. formats.extend(self._extract_m3u8_formats(video_url, video_id, 'flv'))
  69. elif not video_url.endswith('.smil'):
  70. duration = int_or_none(attributes.get('duration'))
  71. formats.append({
  72. 'url': video_url,
  73. 'format_id': media['media-category']['@attributes']['label'],
  74. 'preference': 1,
  75. 'vbr': int_or_none(attributes.get('bitrate')),
  76. 'filesize': int_or_none(attributes.get('fileSize'))
  77. })
  78. self._sort_formats(formats)
  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. return {
  86. 'id': video_id,
  87. 'title': title,
  88. 'description': description,
  89. 'duration': duration,
  90. 'timestamp': timestamp,
  91. 'formats': formats,
  92. 'thumbnails': thumbnails,
  93. }