foxnews.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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?://(?P<host>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. mobj = re.match(self._VALID_URL, url)
  50. video_id = mobj.group('id')
  51. host = mobj.group('host')
  52. video = self._download_json(
  53. 'http://%s/v/feed/video/%s.js?template=fox' % (host, video_id), video_id)
  54. item = video['channel']['item']
  55. title = item['title']
  56. description = item['description']
  57. timestamp = parse_iso8601(item['dc-date'])
  58. media_group = item['media-group']
  59. duration = None
  60. formats = []
  61. for media in media_group['media-content']:
  62. attributes = media['@attributes']
  63. video_url = attributes['url']
  64. if video_url.endswith('.f4m'):
  65. formats.extend(self._extract_f4m_formats(video_url + '?hdcore=3.4.0&plugin=aasp-3.4.0.132.124', video_id))
  66. elif video_url.endswith('.m3u8'):
  67. formats.extend(self._extract_m3u8_formats(video_url, video_id, 'flv'))
  68. elif not video_url.endswith('.smil'):
  69. duration = int_or_none(attributes.get('duration'))
  70. formats.append({
  71. 'url': video_url,
  72. 'format_id': media['media-category']['@attributes']['label'],
  73. 'preference': 1,
  74. 'vbr': int_or_none(attributes.get('bitrate')),
  75. 'filesize': int_or_none(attributes.get('fileSize'))
  76. })
  77. self._sort_formats(formats)
  78. media_thumbnail = media_group['media-thumbnail']['@attributes']
  79. thumbnails = [{
  80. 'url': media_thumbnail['url'],
  81. 'width': int_or_none(media_thumbnail.get('width')),
  82. 'height': int_or_none(media_thumbnail.get('height')),
  83. }] if media_thumbnail else []
  84. return {
  85. 'id': video_id,
  86. 'title': title,
  87. 'description': description,
  88. 'duration': duration,
  89. 'timestamp': timestamp,
  90. 'formats': formats,
  91. 'thumbnails': thumbnails,
  92. }