2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
8 compat_urllib_parse_urlparse
,
17 class NFLIE(InfoExtractor
):
19 _VALID_URL
= r
'''(?x)https?://
20 (?P<host>(?:www\.)?(?:nfl\.com|.*?\.clubs\.nfl\.com))/
22 (?P<id>(?:\d[a-z]{2}\d{13}|\w{8}\-(?:\w{4}\-){3}\w{12}))'''
25 'url': 'http://www.nfl.com/videos/nfl-game-highlights/0ap3000000398478/Week-3-Redskins-vs-Eagles-highlights',
26 'md5': '394ef771ddcd1354f665b471d78ec4c6',
28 'id': '0ap3000000398478',
30 'title': 'Week 3: Redskins vs. Eagles highlights',
31 'description': 'md5:56323bfb0ac4ee5ab24bd05fdf3bf478',
32 'upload_date': '20140921',
33 'timestamp': 1411337580,
34 'thumbnail': 're:^https?://.*\.jpg$',
38 'url': 'http://prod.www.steelers.clubs.nfl.com/video-and-audio/videos/LIVE_Post_Game_vs_Browns/9d72f26a-9e2b-4718-84d3-09fb4046c266',
39 'md5': 'cf85bdb4bc49f6e9d3816d130c78279c',
41 'id': '9d72f26a-9e2b-4718-84d3-09fb4046c266',
43 'title': 'LIVE: Post Game vs. Browns',
44 'description': 'md5:6a97f7e5ebeb4c0e69a418a89e0636e8',
45 'upload_date': '20131229',
46 'timestamp': 1388354455,
47 'thumbnail': 're:^https?://.*\.jpg$',
51 'url': 'http://www.nfl.com/news/story/0ap3000000467586/article/patriots-seahawks-involved-in-lategame-skirmish',
53 'id': '0ap3000000467607',
55 'title': 'Frustrations flare on the field',
56 'description': 'Emotions ran high at the end of the Super Bowl on both sides of the ball after a dramatic finish.',
57 'timestamp': 1422850320,
58 'upload_date': '20150202',
64 def prepend_host(host
, url
):
65 if not url
.startswith('http'):
66 if not url
.startswith('/'):
68 url
= 'http://{0:}{1:}'.format(host
, url
)
72 def format_from_stream(stream
, protocol
, host
, path_prefix
='',
73 preference
=0, note
=None):
74 url
= '{protocol:}://{host:}/{prefix:}{path:}'.format(
78 path
=stream
.get('path'),
82 'vbr': int_or_none(stream
.get('rate', 0), 1000),
83 'preference': preference
,
87 def _real_extract(self
, url
):
88 mobj
= re
.match(self
._VALID
_URL
, url
)
89 video_id
, host
= mobj
.group('id'), mobj
.group('host')
91 webpage
= self
._download
_webpage
(url
, video_id
)
93 config_url
= NFLIE
.prepend_host(host
, self
._search
_regex
(
94 r
'(?:config|configURL)\s*:\s*"([^"]+)"', webpage
, 'config URL',
95 default
='static/content/static/config/video/config.json'))
96 # For articles, the id in the url is not the video id
97 video_id
= self
._search
_regex
(
98 r
'contentId\s*:\s*"([^"]+)"', webpage
, 'video id', default
=video_id
)
99 config
= self
._download
_json
(config_url
, video_id
,
100 note
='Downloading player config')
101 url_template
= NFLIE
.prepend_host(
102 host
, '{contentURLTemplate:}'.format(**config
))
103 video_data
= self
._download
_json
(
104 url_template
.format(id=video_id
), video_id
)
107 cdn_data
= video_data
.get('cdnData', {})
108 streams
= cdn_data
.get('bitrateInfo', [])
109 if cdn_data
.get('format') == 'EXTERNAL_HTTP_STREAM':
110 parts
= compat_urllib_parse_urlparse(cdn_data
.get('uri'))
111 protocol
, host
= parts
.scheme
, parts
.netloc
112 for stream
in streams
:
114 NFLIE
.format_from_stream(stream
, protocol
, host
))
116 cdns
= config
.get('cdns')
118 raise ExtractorError('Failed to get CDN data', expected
=True)
120 for name
, cdn
in cdns
.items():
121 # LimeLight streams don't seem to work
122 if cdn
.get('name') == 'LIMELIGHT':
125 protocol
= cdn
.get('protocol')
126 host
= remove_end(cdn
.get('host', ''), '/')
127 if not (protocol
and host
):
130 prefix
= cdn
.get('pathprefix', '')
131 if prefix
and not prefix
.endswith('/'):
132 prefix
= '%s/' % prefix
135 if protocol
== 'rtmp':
137 elif 'prog' in name
.lower():
140 for stream
in streams
:
142 NFLIE
.format_from_stream(stream
, protocol
, host
,
143 prefix
, preference
, name
))
145 self
._sort
_formats
(formats
)
148 for q
in ('xl', 'l', 'm', 's', 'xs'):
149 thumbnail
= video_data
.get('imagePaths', {}).get(q
)
155 'title': video_data
.get('headline'),
157 'description': video_data
.get('caption'),
158 'duration': video_data
.get('duration'),
159 'thumbnail': thumbnail
,
160 'timestamp': int_or_none(video_data
.get('posted'), 1000),