]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wwe.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from ..compat 
import compat_str
 
  15 class WWEBaseIE(InfoExtractor
): 
  21     def _extract_entry(self
, data
, url
, video_id
=None): 
  22         video_id 
= compat_str(video_id 
or data
['nid']) 
  25         formats 
= self
._extract
_m
3u8_formats
( 
  26             data
['file'], video_id
, 'mp4', entry_protocol
='m3u8_native', 
  29         description 
= data
.get('description') 
  30         thumbnail 
= urljoin(url
, data
.get('image')) 
  31         series 
= data
.get('show_name') 
  32         episode 
= data
.get('episode_name') 
  35         tracks 
= data
.get('tracks') 
  36         if isinstance(tracks
, list): 
  38                 if not isinstance(track
, dict): 
  40                 if track
.get('kind') != 'captions': 
  42                 track_file 
= url_or_none(track
.get('file')) 
  45                 label 
= track
.get('label') 
  46                 lang 
= self
._SUBTITLE
_LANGS
.get(label
, label
) or 'en' 
  47                 subtitles
.setdefault(lang
, []).append({ 
  54             'description': description
, 
  55             'thumbnail': thumbnail
, 
  59             'subtitles': subtitles
, 
  63 class WWEIE(WWEBaseIE
): 
  64     _VALID_URL 
= r
'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*videos/(?P<id>[^/?#&]+)' 
  66         'url': 'https://www.wwe.com/videos/daniel-bryan-vs-andrade-cien-almas-smackdown-live-sept-4-2018', 
  67         'md5': '92811c6a14bfc206f7a6a9c5d9140184', 
  71             'title': 'Daniel Bryan vs. Andrade "Cien" Almas: SmackDown LIVE, Sept. 4, 2018', 
  72             'description': 'md5:2d7424dbc6755c61a0e649d2a8677f67', 
  73             'thumbnail': r
're:^https?://.*\.jpg$', 
  76         'url': 'https://de.wwe.com/videos/gran-metalik-vs-tony-nese-wwe-205-live-sept-4-2018', 
  77         'only_matching': True, 
  80     def _real_extract(self
, url
): 
  81         display_id 
= self
._match
_id
(url
) 
  82         webpage 
= self
._download
_webpage
(url
, display_id
) 
  84         landing 
= self
._parse
_json
( 
  85             self
._html
_search
_regex
( 
  86                 r
'(?s)Drupal\.settings\s*,\s*({.+?})\s*\)\s*;', 
  87                 webpage
, 'drupal settings'), 
  88             display_id
)['WWEVideoLanding'] 
  90         data 
= landing
['initialVideo']['playlist'][0] 
  91         video_id 
= landing
.get('initialVideoId') 
  93         info 
= self
._extract
_entry
(data
, url
, video_id
) 
  94         info
['display_id'] = display_id
 
  98 class WWEPlaylistIE(WWEBaseIE
): 
  99     _VALID_URL 
= r
'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)' 
 101         'url': 'https://www.wwe.com/shows/raw/2018-11-12', 
 105         'playlist_mincount': 11, 
 107         'url': 'http://www.wwe.com/article/walk-the-prank-wwe-edition', 
 108         'only_matching': True, 
 110         'url': 'https://www.wwe.com/shows/wwenxt/article/matt-riddle-interview', 
 111         'only_matching': True, 
 115     def suitable(cls
, url
): 
 116         return False if WWEIE
.suitable(url
) else super(WWEPlaylistIE
, cls
).suitable(url
) 
 118     def _real_extract(self
, url
): 
 119         display_id 
= self
._match
_id
(url
) 
 120         webpage 
= self
._download
_webpage
(url
, display_id
) 
 123         for mobj 
in re
.finditer( 
 124                 r
'data-video\s*=\s*(["\'])(?P
<data
>{.+?
})\
1', webpage): 
 125             video = self._parse_json( 
 126                 mobj.group('data
'), display_id, transform_source=unescapeHTML, 
 130             data = try_get(video, lambda x: x['playlist
'][0], dict) 
 134                 entry = self._extract_entry(data, url) 
 137             entry['extractor_key
'] = WWEIE.ie_key() 
 138             entries.append(entry) 
 140         return self.playlist_result(entries, display_id)