]>
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
): 
  16                             (?:(?:\w+\.)+)?espn\.go| 
  33         'url': 'http://espn.go.com/video/clip?id=10365079', 
  37             'title': '30 for 30 Shorts: Judging Jewell', 
  38             'description': 'md5:39370c2e016cb4ecf498ffe75bef7f0f', 
  39             'timestamp': 1390936111, 
  40             'upload_date': '20140128', 
  43             'skip_download': True, 
  46         'url': 'https://broadband.espn.go.com/video/clip?id=18910086', 
  50             'title': 'Kyrie spins around defender for two', 
  51             'description': 'md5:2b0f5bae9616d26fba8808350f0d2b9b', 
  52             'timestamp': 1489539155, 
  53             'upload_date': '20170315', 
  56             'skip_download': True, 
  58         'expected_warnings': ['Unable to download f4m manifest'], 
  60         'url': 'http://nonredline.sports.espn.go.com/video/clip?id=19744672', 
  61         'only_matching': True, 
  63         'url': 'https://cdn.espn.go.com/video/clip/_/id/19771774', 
  64         'only_matching': True, 
  66         'url': 'http://www.espn.com/watch/player?id=19141491', 
  67         'only_matching': True, 
  69         'url': 'http://www.espn.com/watch/player?bucketId=257&id=19505875', 
  70         'only_matching': True, 
  72         'url': 'http://www.espn.com/watch/player/_/id/19141491', 
  73         'only_matching': True, 
  75         'url': 'http://www.espn.com/video/clip?id=10365079', 
  76         'only_matching': True, 
  78         'url': 'http://www.espn.com/video/clip/_/id/17989860', 
  79         'only_matching': True, 
  82     def _real_extract(self
, url
): 
  83         video_id 
= self
._match
_id
(url
) 
  85         clip 
= self
._download
_json
( 
  86             'http://api-app.espn.com/v1/video/clips/%s' % video_id
, 
  87             video_id
)['videos'][0] 
  89         title 
= clip
['headline'] 
  94         def traverse_source(source
, base_source_id
=None): 
  95             for source_id
, source 
in source
.items(): 
  96                 if isinstance(source
, compat_str
): 
  97                     extract_source(source
, base_source_id
) 
  98                 elif isinstance(source
, dict): 
 101                         '%s-%s' % (base_source_id
, source_id
) 
 102                         if base_source_id 
else source_id
) 
 104         def extract_source(source_url
, source_id
=None): 
 105             if source_url 
in format_urls
: 
 107             format_urls
.add(source_url
) 
 108             ext 
= determine_ext(source_url
) 
 110                 formats
.extend(self
._extract
_smil
_formats
( 
 111                     source_url
, video_id
, fatal
=False)) 
 113                 formats
.extend(self
._extract
_f
4m
_formats
( 
 114                     source_url
, video_id
, f4m_id
=source_id
, fatal
=False)) 
 116                 formats
.extend(self
._extract
_m
3u8_formats
( 
 117                     source_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
 118                     m3u8_id
=source_id
, fatal
=False)) 
 122                     'format_id': source_id
, 
 125         traverse_source(clip
['links']['source']) 
 126         self
._sort
_formats
(formats
) 
 128         description 
= clip
.get('caption') or clip
.get('description') 
 129         thumbnail 
= clip
.get('thumbnail') 
 130         duration 
= int_or_none(clip
.get('duration')) 
 131         timestamp 
= unified_timestamp(clip
.get('originalPublishDate')) 
 136             'description': description
, 
 137             'thumbnail': thumbnail
, 
 138             'timestamp': timestamp
, 
 139             'duration': duration
, 
 144 class ESPNArticleIE(InfoExtractor
): 
 145     _VALID_URL 
= r
'https?://(?:espn\.go|(?:www\.)?espn)\.com/(?:[^/]+/)*(?P<id>[^/]+)' 
 147         'url': 'https://espn.go.com/video/iframe/twitter/?cms=espn&id=10365079', 
 148         'only_matching': True, 
 150         'url': 'http://espn.go.com/nba/recap?gameId=400793786', 
 151         'only_matching': True, 
 153         'url': 'http://espn.go.com/blog/golden-state-warriors/post/_/id/593/how-warriors-rapidly-regained-a-winning-edge', 
 154         'only_matching': True, 
 156         'url': 'http://espn.go.com/sports/endurance/story/_/id/12893522/dzhokhar-tsarnaev-sentenced-role-boston-marathon-bombings', 
 157         'only_matching': True, 
 159         'url': 'http://espn.go.com/nba/playoffs/2015/story/_/id/12887571/john-wall-washington-wizards-no-swelling-left-hand-wrist-game-5-return', 
 160         'only_matching': True, 
 164     def suitable(cls
, url
): 
 165         return False if ESPNIE
.suitable(url
) else super(ESPNArticleIE
, cls
).suitable(url
) 
 167     def _real_extract(self
, url
): 
 168         video_id 
= self
._match
_id
(url
) 
 170         webpage 
= self
._download
_webpage
(url
, video_id
) 
 172         video_id 
= self
._search
_regex
( 
 173             r
'class=(["\']).*?video
-play
-button
.*?\
1[^
>]+data
-id=["\'](?P<id>\d+)', 
 174             webpage, 'video id', group='id') 
 176         return self.url_result( 
 177             'http://espn.go.com/video/clip?id=%s' % video_id, ESPNIE.ie_key())