2 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 compat_urllib_parse_urlparse,
15 class NFLIE(InfoExtractor):
17 _VALID_URL = r'''(?x)https?://
18 (?P<host>(?:www\.)?(?:nfl\.com|.*?\.clubs\.nfl\.com))/
20 (?P<id>(?:\d[a-z]{2}\d{13}|\w{8}\-(?:\w{4}\-){3}\w{12}))'''
23 'url': 'http://www.nfl.com/videos/nfl-game-highlights/0ap3000000398478/Week-3-Redskins-vs-Eagles-highlights',
24 'md5': '394ef771ddcd1354f665b471d78ec4c6',
26 'id': '0ap3000000398478',
28 'title': 'Week 3: Redskins vs. Eagles highlights',
29 'description': 'md5:56323bfb0ac4ee5ab24bd05fdf3bf478',
30 'upload_date': '20140921',
31 'timestamp': 1411337580,
32 'thumbnail': 're:^https?://.*\.jpg$',
36 'url': 'http://prod.www.steelers.clubs.nfl.com/video-and-audio/videos/LIVE_Post_Game_vs_Browns/9d72f26a-9e2b-4718-84d3-09fb4046c266',
37 'md5': 'cf85bdb4bc49f6e9d3816d130c78279c',
39 'id': '9d72f26a-9e2b-4718-84d3-09fb4046c266',
41 'title': 'LIVE: Post Game vs. Browns',
42 'description': 'md5:6a97f7e5ebeb4c0e69a418a89e0636e8',
43 'upload_date': '20131229',
44 'timestamp': 1388354455,
45 'thumbnail': 're:^https?://.*\.jpg$',
51 def prepend_host(host, url):
52 if not url.startswith('http'):
53 if not url.startswith('/'):
55 url = 'http://{0:}{1:}'.format(host, url)
59 def format_from_stream(stream, protocol, host, path_prefix='',
60 preference=0, note=None):
61 url = '{protocol:}://{host:}/{prefix:}{path:}'.format(
65 path=stream.get('path'),
69 'vbr': int_or_none(stream.get('rate', 0), 1000),
70 'preference': preference,
74 def _real_extract(self, url):
75 mobj = re.match(self._VALID_URL, url)
76 video_id, host = mobj.group('id'), mobj.group('host')
78 webpage = self._download_webpage(url, video_id)
80 config_url = NFLIE.prepend_host(host, self._search_regex(
81 r'(?:config|configURL)\s*:\s*"([^"]+)"', webpage, 'config URL'))
82 config = self._download_json(config_url, video_id,
83 note='Downloading player config')
84 url_template = NFLIE.prepend_host(
85 host, '{contentURLTemplate:}'.format(**config))
86 video_data = self._download_json(
87 url_template.format(id=video_id), video_id)
90 cdn_data = video_data.get('cdnData', {})
91 streams = cdn_data.get('bitrateInfo', [])
92 if cdn_data.get('format') == 'EXTERNAL_HTTP_STREAM':
93 parts = compat_urllib_parse_urlparse(cdn_data.get('uri'))
94 protocol, host = parts.scheme, parts.netloc
95 for stream in streams:
97 NFLIE.format_from_stream(stream, protocol, host))
99 cdns = config.get('cdns')
101 raise ExtractorError('Failed to get CDN data', expected=True)
103 for name, cdn in cdns.items():
104 # LimeLight streams don't seem to work
105 if cdn.get('name') == 'LIMELIGHT':
108 protocol = cdn.get('protocol')
109 host = remove_end(cdn.get('host', ''), '/')
110 if not (protocol and host):
113 prefix = cdn.get('pathprefix', '')
114 if prefix and not prefix.endswith('/'):
115 prefix = '%s/' % prefix
118 if protocol == 'rtmp':
120 elif 'prog' in name.lower():
123 for stream in streams:
125 NFLIE.format_from_stream(stream, protocol, host,
126 prefix, preference, name))
128 self._sort_formats(formats)
131 for q in ('xl', 'l', 'm', 's', 'xs'):
132 thumbnail = video_data.get('imagePaths', {}).get(q)
138 'title': video_data.get('headline'),
140 'description': video_data.get('caption'),
141 'duration': video_data.get('duration'),
142 'thumbnail': thumbnail,
143 'timestamp': int_or_none(video_data.get('posted'), 1000),