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.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. remove_end,
  9. )
  10. class NFLIE(InfoExtractor):
  11. IE_NAME = 'nfl.com'
  12. _VALID_URL = r'(?x)https?://(?:www\.)?nfl\.com/(?:videos/(?:.+)/|.*?\#video=)(?P<id>\d..[0-9]+)'
  13. _PLAYER_CONFIG_URL = 'http://www.nfl.com/static/content/static/config/video/config.json'
  14. _TEST = {
  15. 'url': 'http://www.nfl.com/videos/nfl-game-highlights/0ap3000000398478/Week-3-Redskins-vs-Eagles-highlights',
  16. # 'md5': '5eb8c40a727dda106d510e5d6ffa79e5', # md5 checksum fluctuates
  17. 'info_dict': {
  18. 'id': '0ap3000000398478',
  19. 'ext': 'mp4',
  20. 'title': 'Week 3: Washington Redskins vs. Philadelphia Eagles highlights',
  21. 'description': 'md5:56323bfb0ac4ee5ab24bd05fdf3bf478',
  22. 'upload_date': '20140921',
  23. 'timestamp': 1411337580,
  24. 'thumbnail': 're:^https?://.*\.jpg$',
  25. }
  26. }
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. config = self._download_json(self._PLAYER_CONFIG_URL, video_id,
  31. note='Downloading player config')
  32. url_template = 'http://nfl.com{contentURLTemplate:s}'.format(**config)
  33. video_data = self._download_json(url_template.format(id=video_id), video_id)
  34. cdns = config.get('cdns')
  35. if not cdns:
  36. raise ExtractorError('Failed to get CDN data', expected=True)
  37. formats = []
  38. streams = video_data.get('cdnData', {}).get('bitrateInfo', [])
  39. for name, cdn in cdns.items():
  40. # LimeLight streams don't seem to work
  41. if cdn.get('name') == 'LIMELIGHT':
  42. continue
  43. protocol = cdn.get('protocol')
  44. host = remove_end(cdn.get('host', ''), '/')
  45. if not (protocol and host):
  46. continue
  47. path_prefix = cdn.get('pathprefix', '')
  48. if path_prefix and not path_prefix.endswith('/'):
  49. path_prefix = '%s/' % path_prefix
  50. get_url = lambda p: '{protocol:s}://{host:s}/{prefix:s}{path:}'.format(
  51. protocol=protocol,
  52. host=host,
  53. prefix=path_prefix,
  54. path=p,
  55. )
  56. if protocol == 'rtmp':
  57. preference = -2
  58. elif 'prog' in name.lower():
  59. preference = -1
  60. else:
  61. preference = 0
  62. for stream in streams:
  63. path = stream.get('path')
  64. if not path:
  65. continue
  66. formats.append({
  67. 'url': get_url(path),
  68. 'vbr': int_or_none(stream.get('rate', 0), 1000),
  69. 'preference': preference,
  70. 'format_note': name,
  71. })
  72. self._sort_formats(formats)
  73. thumbnail = None
  74. for q in ('xl', 'l', 'm', 's', 'xs'):
  75. thumbnail = video_data.get('imagePaths', {}).get(q)
  76. if thumbnail:
  77. break
  78. return {
  79. 'id': video_id,
  80. 'title': video_data.get('storyHeadline'),
  81. 'formats': formats,
  82. 'description': video_data.get('caption'),
  83. 'duration': video_data.get('duration'),
  84. 'thumbnail': thumbnail,
  85. 'timestamp': int_or_none(video_data.get('posted'), 1000),
  86. }