2 from __future__ import unicode_literals
6 from .common import InfoExtractor
8 compat_urllib_parse_urlparse,
17 class NFLIE(InfoExtractor):
63 (?P<id>(?:[a-z0-9]{16}|\w{8}\-(?:\w{4}\-){3}\w{12}))
66 'url': 'http://www.nfl.com/videos/nfl-game-highlights/0ap3000000398478/Week-3-Redskins-vs-Eagles-highlights',
67 'md5': '394ef771ddcd1354f665b471d78ec4c6',
69 'id': '0ap3000000398478',
71 'title': 'Week 3: Redskins vs. Eagles highlights',
72 'description': 'md5:56323bfb0ac4ee5ab24bd05fdf3bf478',
73 'upload_date': '20140921',
74 'timestamp': 1411337580,
75 'thumbnail': 're:^https?://.*\.jpg$',
78 'url': 'http://prod.www.steelers.clubs.nfl.com/video-and-audio/videos/LIVE_Post_Game_vs_Browns/9d72f26a-9e2b-4718-84d3-09fb4046c266',
79 'md5': 'cf85bdb4bc49f6e9d3816d130c78279c',
81 'id': '9d72f26a-9e2b-4718-84d3-09fb4046c266',
83 'title': 'LIVE: Post Game vs. Browns',
84 'description': 'md5:6a97f7e5ebeb4c0e69a418a89e0636e8',
85 'upload_date': '20131229',
86 'timestamp': 1388354455,
87 'thumbnail': 're:^https?://.*\.jpg$',
90 'url': 'http://www.nfl.com/news/story/0ap3000000467586/article/patriots-seahawks-involved-in-lategame-skirmish',
92 'id': '0ap3000000467607',
94 'title': 'Frustrations flare on the field',
95 'description': 'Emotions ran high at the end of the Super Bowl on both sides of the ball after a dramatic finish.',
96 'timestamp': 1422850320,
97 'upload_date': '20150202',
100 'url': 'http://www.nfl.com/videos/nfl-network-top-ten/09000d5d810a6bd4/Top-10-Gutsiest-Performances-Jack-Youngblood',
101 'only_matching': True,
103 'url': 'http://www.buffalobills.com/video/videos/Rex_Ryan_Show_World_Wide_Rex/b1dcfab2-3190-4bb1-bfc0-d6e603d6601a',
104 'only_matching': True,
108 def prepend_host(host, url):
109 if not url.startswith('http'):
110 if not url.startswith('/'):
112 url = 'http://{0:}{1:}'.format(host, url)
116 def format_from_stream(stream, protocol, host, path_prefix='',
117 preference=0, note=None):
118 url = '{protocol:}://{host:}/{prefix:}{path:}'.format(
122 path=stream.get('path'),
126 'vbr': int_or_none(stream.get('rate', 0), 1000),
127 'preference': preference,
131 def _real_extract(self, url):
132 mobj = re.match(self._VALID_URL, url)
133 video_id, host = mobj.group('id'), mobj.group('host')
135 webpage = self._download_webpage(url, video_id)
137 config_url = NFLIE.prepend_host(host, self._search_regex(
138 r'(?:config|configURL)\s*:\s*"([^"]+)"', webpage, 'config URL',
139 default='static/content/static/config/video/config.json'))
140 # For articles, the id in the url is not the video id
141 video_id = self._search_regex(
142 r'contentId\s*:\s*"([^"]+)"', webpage, 'video id', default=video_id)
143 config = self._download_json(config_url, video_id,
144 note='Downloading player config')
145 url_template = NFLIE.prepend_host(
146 host, '{contentURLTemplate:}'.format(**config))
147 video_data = self._download_json(
148 url_template.format(id=video_id), video_id)
151 cdn_data = video_data.get('cdnData', {})
152 streams = cdn_data.get('bitrateInfo', [])
153 if cdn_data.get('format') == 'EXTERNAL_HTTP_STREAM':
154 parts = compat_urllib_parse_urlparse(cdn_data.get('uri'))
155 protocol, host = parts.scheme, parts.netloc
156 for stream in streams:
158 NFLIE.format_from_stream(stream, protocol, host))
160 cdns = config.get('cdns')
162 raise ExtractorError('Failed to get CDN data', expected=True)
164 for name, cdn in cdns.items():
165 # LimeLight streams don't seem to work
166 if cdn.get('name') == 'LIMELIGHT':
169 protocol = cdn.get('protocol')
170 host = remove_end(cdn.get('host', ''), '/')
171 if not (protocol and host):
174 prefix = cdn.get('pathprefix', '')
175 if prefix and not prefix.endswith('/'):
176 prefix = '%s/' % prefix
179 if protocol == 'rtmp':
181 elif 'prog' in name.lower():
184 for stream in streams:
186 NFLIE.format_from_stream(stream, protocol, host,
187 prefix, preference, name))
189 self._sort_formats(formats)
192 for q in ('xl', 'l', 'm', 's', 'xs'):
193 thumbnail = video_data.get('imagePaths', {}).get(q)
199 'title': video_data.get('headline'),
201 'description': video_data.get('caption'),
202 'duration': video_data.get('duration'),
203 'thumbnail': thumbnail,
204 'timestamp': int_or_none(video_data.get('posted'), 1000),