]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/espn.py
8cc9bd165a96185b264e6e5976ae347fe02e2437
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from .once
import OnceIE
7 from ..compat
import compat_str
21 (?:(?:\w+\.)+)?espn\.go|
26 video/(?:clip|iframe/twitter)|
36 (?:www\.)espnfc\.(?:com|us)/(?:video/)?[^/]+/\d+/video/
42 'url': 'http://espn.go.com/video/clip?id=10365079',
46 'title': '30 for 30 Shorts: Judging Jewell',
47 'description': 'md5:39370c2e016cb4ecf498ffe75bef7f0f',
48 'timestamp': 1390936111,
49 'upload_date': '20140128',
52 'skip_download': True,
55 'url': 'https://broadband.espn.go.com/video/clip?id=18910086',
59 'title': 'Kyrie spins around defender for two',
60 'description': 'md5:2b0f5bae9616d26fba8808350f0d2b9b',
61 'timestamp': 1489539155,
62 'upload_date': '20170315',
65 'skip_download': True,
67 'expected_warnings': ['Unable to download f4m manifest'],
69 'url': 'http://nonredline.sports.espn.go.com/video/clip?id=19744672',
70 'only_matching': True,
72 'url': 'https://cdn.espn.go.com/video/clip/_/id/19771774',
73 'only_matching': True,
75 'url': 'http://www.espn.com/watch/player?id=19141491',
76 'only_matching': True,
78 'url': 'http://www.espn.com/watch/player?bucketId=257&id=19505875',
79 'only_matching': True,
81 'url': 'http://www.espn.com/watch/player/_/id/19141491',
82 'only_matching': True,
84 'url': 'http://www.espn.com/video/clip?id=10365079',
85 'only_matching': True,
87 'url': 'http://www.espn.com/video/clip/_/id/17989860',
88 'only_matching': True,
90 'url': 'https://espn.go.com/video/iframe/twitter/?cms=espn&id=10365079',
91 'only_matching': True,
93 'url': 'http://www.espnfc.us/video/espn-fc-tv/86/video/3319154/nashville-unveiled-as-the-newest-club-in-mls',
94 'only_matching': True,
96 'url': 'http://www.espnfc.com/english-premier-league/23/video/3324163/premier-league-in-90-seconds-golden-tweets',
97 'only_matching': True,
99 'url': 'http://www.espn.com/espnw/video/26066627/arkansas-gibson-completes-hr-cycle-four-innings',
100 'only_matching': True,
103 def _real_extract(self
, url
):
104 video_id
= self
._match
_id
(url
)
106 clip
= self
._download
_json
(
107 'http://api-app.espn.com/v1/video/clips/%s' % video_id
,
108 video_id
)['videos'][0]
110 title
= clip
['headline']
115 def traverse_source(source
, base_source_id
=None):
116 for source_id
, source
in source
.items():
117 if source_id
== 'alert':
119 elif isinstance(source
, compat_str
):
120 extract_source(source
, base_source_id
)
121 elif isinstance(source
, dict):
124 '%s-%s' % (base_source_id
, source_id
)
125 if base_source_id
else source_id
)
127 def extract_source(source_url
, source_id
=None):
128 if source_url
in format_urls
:
130 format_urls
.add(source_url
)
131 ext
= determine_ext(source_url
)
132 if OnceIE
.suitable(source_url
):
133 formats
.extend(self
._extract
_once
_formats
(source_url
))
135 formats
.extend(self
._extract
_smil
_formats
(
136 source_url
, video_id
, fatal
=False))
138 formats
.extend(self
._extract
_f
4m
_formats
(
139 source_url
, video_id
, f4m_id
=source_id
, fatal
=False))
141 formats
.extend(self
._extract
_m
3u8_formats
(
142 source_url
, video_id
, 'mp4', entry_protocol
='m3u8_native',
143 m3u8_id
=source_id
, fatal
=False))
147 'format_id': source_id
,
149 mobj
= re
.search(r
'(\d+)p(\d+)_(\d+)k\.', source_url
)
152 'height': int(mobj
.group(1)),
153 'fps': int(mobj
.group(2)),
154 'tbr': int(mobj
.group(3)),
156 if source_id
== 'mezzanine':
160 links
= clip
.get('links', {})
161 traverse_source(links
.get('source', {}))
162 traverse_source(links
.get('mobile', {}))
163 self
._sort
_formats
(formats
)
165 description
= clip
.get('caption') or clip
.get('description')
166 thumbnail
= clip
.get('thumbnail')
167 duration
= int_or_none(clip
.get('duration'))
168 timestamp
= unified_timestamp(clip
.get('originalPublishDate'))
173 'description': description
,
174 'thumbnail': thumbnail
,
175 'timestamp': timestamp
,
176 'duration': duration
,
181 class ESPNArticleIE(InfoExtractor
):
182 _VALID_URL
= r
'https?://(?:espn\.go|(?:www\.)?espn)\.com/(?:[^/]+/)*(?P<id>[^/]+)'
184 'url': 'http://espn.go.com/nba/recap?gameId=400793786',
185 'only_matching': True,
187 'url': 'http://espn.go.com/blog/golden-state-warriors/post/_/id/593/how-warriors-rapidly-regained-a-winning-edge',
188 'only_matching': True,
190 'url': 'http://espn.go.com/sports/endurance/story/_/id/12893522/dzhokhar-tsarnaev-sentenced-role-boston-marathon-bombings',
191 'only_matching': True,
193 'url': 'http://espn.go.com/nba/playoffs/2015/story/_/id/12887571/john-wall-washington-wizards-no-swelling-left-hand-wrist-game-5-return',
194 'only_matching': True,
198 def suitable(cls
, url
):
199 return False if ESPNIE
.suitable(url
) else super(ESPNArticleIE
, cls
).suitable(url
)
201 def _real_extract(self
, url
):
202 video_id
= self
._match
_id
(url
)
204 webpage
= self
._download
_webpage
(url
, video_id
)
206 video_id
= self
._search
_regex
(
207 r
'class=(["\']).*?video
-play
-button
.*?\
1[^
>]+data
-id=["\'](?P<id>\d+)',
208 webpage, 'video id', group='id')
210 return self.url_result(
211 'http://espn.go.com/video/clip?id=%s' % video_id, ESPNIE.ie_key())
214 class FiveThirtyEightIE(InfoExtractor):
215 _VALID_URL = r'https?://(?:www\.)?fivethirtyeight\.com/features/(?P<id>[^/?#]+)'
217 'url': 'http://fivethirtyeight.com/features/how-the-6-8-raiders-can-still-make-the-playoffs/',
221 'title': 'FiveThirtyEight: The Raiders can still make the playoffs',
222 'description': 'Neil Paine breaks down the simplest scenario that will put the Raiders into the playoffs at 8-8.',
223 'timestamp': 1513960621,
224 'upload_date': '20171222',
227 'skip_download': True,
229 'expected_warnings': ['Unable to download f4m manifest'],
232 def _real_extract(self, url):
233 video_id = self._match_id(url)
235 webpage = self._download_webpage(url, video_id)
237 video_id = self._search_regex(
238 r'data-video-id=["\'](?P
<id>\d
+)',
239 webpage, 'video
id', group='id')
241 return self.url_result(
242 'http
://espn
.go
.com
/video
/clip?
id=%s' % video_id, ESPNIE.ie_key())