]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/espn.py
   1 from __future__ 
import unicode_literals
 
   3 from .common 
import InfoExtractor
 
   4 from ..compat 
import compat_str
 
  12 class ESPNIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://(?:espn\.go|(?:www\.)?espn)\.com/video/clip(?:\?.*?\bid=|/_/id/)(?P<id>\d+)' 
  15         'url': 'http://espn.go.com/video/clip?id=10365079', 
  19             'title': '30 for 30 Shorts: Judging Jewell', 
  20             'description': 'md5:39370c2e016cb4ecf498ffe75bef7f0f', 
  21             'timestamp': 1390936111, 
  22             'upload_date': '20140128', 
  25             'skip_download': True, 
  28         # intl video, from http://www.espnfc.us/video/mls-highlights/150/video/2743663/must-see-moments-best-of-the-mls-season 
  29         'url': 'http://espn.go.com/video/clip?id=2743663', 
  33             'title': 'Must-See Moments: Best of the MLS season', 
  34             'description': 'md5:4c2d7232beaea572632bec41004f0aeb', 
  35             'timestamp': 1449446454, 
  36             'upload_date': '20151207', 
  39             'skip_download': True, 
  41         'expected_warnings': ['Unable to download f4m manifest'], 
  43         'url': 'http://www.espn.com/video/clip?id=10365079', 
  44         'only_matching': True, 
  46         'url': 'http://www.espn.com/video/clip/_/id/17989860', 
  47         'only_matching': True, 
  50     def _real_extract(self
, url
): 
  51         video_id 
= self
._match
_id
(url
) 
  53         clip 
= self
._download
_json
( 
  54             'http://api-app.espn.com/v1/video/clips/%s' % video_id
, 
  55             video_id
)['videos'][0] 
  57         title 
= clip
['headline'] 
  62         def traverse_source(source
, base_source_id
=None): 
  63             for source_id
, source 
in source
.items(): 
  64                 if isinstance(source
, compat_str
): 
  65                     extract_source(source
, base_source_id
) 
  66                 elif isinstance(source
, dict): 
  69                         '%s-%s' % (base_source_id
, source_id
) 
  70                         if base_source_id 
else source_id
) 
  72         def extract_source(source_url
, source_id
=None): 
  73             if source_url 
in format_urls
: 
  75             format_urls
.add(source_url
) 
  76             ext 
= determine_ext(source_url
) 
  78                 formats
.extend(self
._extract
_smil
_formats
( 
  79                     source_url
, video_id
, fatal
=False)) 
  81                 formats
.extend(self
._extract
_f
4m
_formats
( 
  82                     source_url
, video_id
, f4m_id
=source_id
, fatal
=False)) 
  84                 formats
.extend(self
._extract
_m
3u8_formats
( 
  85                     source_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
  86                     m3u8_id
=source_id
, fatal
=False)) 
  90                     'format_id': source_id
, 
  93         traverse_source(clip
['links']['source']) 
  94         self
._sort
_formats
(formats
) 
  96         description 
= clip
.get('caption') or clip
.get('description') 
  97         thumbnail 
= clip
.get('thumbnail') 
  98         duration 
= int_or_none(clip
.get('duration')) 
  99         timestamp 
= unified_timestamp(clip
.get('originalPublishDate')) 
 104             'description': description
, 
 105             'thumbnail': thumbnail
, 
 106             'timestamp': timestamp
, 
 107             'duration': duration
, 
 112 class ESPNArticleIE(InfoExtractor
): 
 113     _VALID_URL 
= r
'https?://(?:espn\.go|(?:www\.)?espn)\.com/(?:[^/]+/)*(?P<id>[^/]+)' 
 115         'url': 'https://espn.go.com/video/iframe/twitter/?cms=espn&id=10365079', 
 116         'only_matching': True, 
 118         'url': 'http://espn.go.com/nba/recap?gameId=400793786', 
 119         'only_matching': True, 
 121         'url': 'http://espn.go.com/blog/golden-state-warriors/post/_/id/593/how-warriors-rapidly-regained-a-winning-edge', 
 122         'only_matching': True, 
 124         'url': 'http://espn.go.com/sports/endurance/story/_/id/12893522/dzhokhar-tsarnaev-sentenced-role-boston-marathon-bombings', 
 125         'only_matching': True, 
 127         'url': 'http://espn.go.com/nba/playoffs/2015/story/_/id/12887571/john-wall-washington-wizards-no-swelling-left-hand-wrist-game-5-return', 
 128         'only_matching': True, 
 132     def suitable(cls
, url
): 
 133         return False if ESPNIE
.suitable(url
) else super(ESPNArticleIE
, cls
).suitable(url
) 
 135     def _real_extract(self
, url
): 
 136         video_id 
= self
._match
_id
(url
) 
 138         webpage 
= self
._download
_webpage
(url
, video_id
) 
 140         video_id 
= self
._search
_regex
( 
 141             r
'class=(["\']).*?video
-play
-button
.*?\
1[^
>]+data
-id=["\'](?P<id>\d+)', 
 142             webpage, 'video id', group='id') 
 144         return self.url_result( 
 145             'http://espn.go.com/video/clip?id=%s' % video_id, ESPNIE.ie_key())