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.

94 lines
3.6 KiB

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