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.

102 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. _VALID_URL = r'https?://video\.fox(?:news|business)\.com/v/(?:video-embed\.html\?video_id=)?(?P<id>\d+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://video.foxnews.com/v/3937480/frozen-in-time/#sp=show-clips',
  13. 'md5': '32aaded6ba3ef0d1c04e238d01031e5e',
  14. 'info_dict': {
  15. 'id': '3937480',
  16. 'ext': 'flv',
  17. 'title': 'Frozen in Time',
  18. 'description': 'Doctors baffled by 16-year-old girl that is the size of a toddler',
  19. 'duration': 265,
  20. 'timestamp': 1304411491,
  21. 'upload_date': '20110503',
  22. 'thumbnail': 're:^https?://.*\.jpg$',
  23. },
  24. },
  25. {
  26. 'url': 'http://video.foxnews.com/v/3922535568001/rep-luis-gutierrez-on-if-obamas-immigration-plan-is-legal/#sp=show-clips',
  27. 'md5': '5846c64a1ea05ec78175421b8323e2df',
  28. 'info_dict': {
  29. 'id': '3922535568001',
  30. 'ext': 'mp4',
  31. 'title': "Rep. Luis Gutierrez on if Obama's immigration plan is legal",
  32. 'description': "Congressman discusses the president's executive action",
  33. 'duration': 292,
  34. 'timestamp': 1417662047,
  35. 'upload_date': '20141204',
  36. 'thumbnail': 're:^https?://.*\.jpg$',
  37. },
  38. },
  39. {
  40. 'url': 'http://video.foxnews.com/v/video-embed.html?video_id=3937480&d=video.foxnews.com',
  41. 'only_matching': True,
  42. },
  43. {
  44. 'url': 'http://video.foxbusiness.com/v/4442309889001',
  45. 'only_matching': True,
  46. },
  47. ]
  48. def _real_extract(self, url):
  49. video_id = self._match_id(url)
  50. m = re.match(r'^https?://video\.fox(news|business)', url)
  51. video = self._download_json(
  52. 'http://video.fox' + m.group(1) + '.com/v/feed/video/%s.js?template=fox' % video_id, video_id)
  53. item = video['channel']['item']
  54. title = item['title']
  55. description = item['description']
  56. timestamp = parse_iso8601(item['dc-date'])
  57. media_group = item['media-group']
  58. duration = None
  59. formats = []
  60. for media in media_group['media-content']:
  61. attributes = media['@attributes']
  62. video_url = attributes['url']
  63. if video_url.endswith('.f4m'):
  64. formats.extend(self._extract_f4m_formats(video_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', video_id))
  65. elif video_url.endswith('.m3u8'):
  66. formats.extend(self._extract_m3u8_formats(video_url, video_id, 'flv'))
  67. elif not video_url.endswith('.smil'):
  68. duration = int_or_none(attributes.get('duration'))
  69. formats.append({
  70. 'url': video_url,
  71. 'format_id': media['media-category']['@attributes']['label'],
  72. 'preference': 1,
  73. 'vbr': int_or_none(attributes.get('bitrate')),
  74. 'filesize': int_or_none(attributes.get('fileSize'))
  75. })
  76. self._sort_formats(formats)
  77. media_thumbnail = media_group['media-thumbnail']['@attributes']
  78. thumbnails = [{
  79. 'url': media_thumbnail['url'],
  80. 'width': int_or_none(media_thumbnail.get('width')),
  81. 'height': int_or_none(media_thumbnail.get('height')),
  82. }] if media_thumbnail else []
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description,
  87. 'duration': duration,
  88. 'timestamp': timestamp,
  89. 'formats': formats,
  90. 'thumbnails': thumbnails,
  91. }