logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

wwe.py (4532B)


  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..compat import compat_str
  5. from ..utils import (
  6. try_get,
  7. unescapeHTML,
  8. url_or_none,
  9. urljoin,
  10. )
  11. class WWEBaseIE(InfoExtractor):
  12. _SUBTITLE_LANGS = {
  13. 'English': 'en',
  14. 'Deutsch': 'de',
  15. }
  16. def _extract_entry(self, data, url, video_id=None):
  17. video_id = compat_str(video_id or data['nid'])
  18. title = data['title']
  19. formats = self._extract_m3u8_formats(
  20. data['file'], video_id, 'mp4', entry_protocol='m3u8_native',
  21. m3u8_id='hls')
  22. description = data.get('description')
  23. thumbnail = urljoin(url, data.get('image'))
  24. series = data.get('show_name')
  25. episode = data.get('episode_name')
  26. subtitles = {}
  27. tracks = data.get('tracks')
  28. if isinstance(tracks, list):
  29. for track in tracks:
  30. if not isinstance(track, dict):
  31. continue
  32. if track.get('kind') != 'captions':
  33. continue
  34. track_file = url_or_none(track.get('file'))
  35. if not track_file:
  36. continue
  37. label = track.get('label')
  38. lang = self._SUBTITLE_LANGS.get(label, label) or 'en'
  39. subtitles.setdefault(lang, []).append({
  40. 'url': track_file,
  41. })
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'description': description,
  46. 'thumbnail': thumbnail,
  47. 'series': series,
  48. 'episode': episode,
  49. 'formats': formats,
  50. 'subtitles': subtitles,
  51. }
  52. class WWEIE(WWEBaseIE):
  53. _VALID_URL = r'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*videos/(?P<id>[^/?#&]+)'
  54. _TESTS = [{
  55. 'url': 'https://www.wwe.com/videos/daniel-bryan-vs-andrade-cien-almas-smackdown-live-sept-4-2018',
  56. 'md5': '92811c6a14bfc206f7a6a9c5d9140184',
  57. 'info_dict': {
  58. 'id': '40048199',
  59. 'ext': 'mp4',
  60. 'title': 'Daniel Bryan vs. Andrade "Cien" Almas: SmackDown LIVE, Sept. 4, 2018',
  61. 'description': 'md5:2d7424dbc6755c61a0e649d2a8677f67',
  62. 'thumbnail': r're:^https?://.*\.jpg$',
  63. }
  64. }, {
  65. 'url': 'https://de.wwe.com/videos/gran-metalik-vs-tony-nese-wwe-205-live-sept-4-2018',
  66. 'only_matching': True,
  67. }]
  68. def _real_extract(self, url):
  69. display_id = self._match_id(url)
  70. webpage = self._download_webpage(url, display_id)
  71. landing = self._parse_json(
  72. self._html_search_regex(
  73. r'(?s)Drupal\.settings\s*,\s*({.+?})\s*\)\s*;',
  74. webpage, 'drupal settings'),
  75. display_id)['WWEVideoLanding']
  76. data = landing['initialVideo']['playlist'][0]
  77. video_id = landing.get('initialVideoId')
  78. info = self._extract_entry(data, url, video_id)
  79. info['display_id'] = display_id
  80. return info
  81. class WWEPlaylistIE(WWEBaseIE):
  82. _VALID_URL = r'https?://(?:[^/]+\.)?wwe\.com/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  83. _TESTS = [{
  84. 'url': 'https://www.wwe.com/shows/raw/2018-11-12',
  85. 'info_dict': {
  86. 'id': '2018-11-12',
  87. },
  88. 'playlist_mincount': 11,
  89. }, {
  90. 'url': 'http://www.wwe.com/article/walk-the-prank-wwe-edition',
  91. 'only_matching': True,
  92. }, {
  93. 'url': 'https://www.wwe.com/shows/wwenxt/article/matt-riddle-interview',
  94. 'only_matching': True,
  95. }]
  96. @classmethod
  97. def suitable(cls, url):
  98. return False if WWEIE.suitable(url) else super(WWEPlaylistIE, cls).suitable(url)
  99. def _real_extract(self, url):
  100. display_id = self._match_id(url)
  101. webpage = self._download_webpage(url, display_id)
  102. entries = []
  103. for mobj in re.finditer(
  104. r'data-video\s*=\s*(["\'])(?P<data>{.+?})\1', webpage):
  105. video = self._parse_json(
  106. mobj.group('data'), display_id, transform_source=unescapeHTML,
  107. fatal=False)
  108. if not video:
  109. continue
  110. data = try_get(video, lambda x: x['playlist'][0], dict)
  111. if not data:
  112. continue
  113. try:
  114. entry = self._extract_entry(data, url)
  115. except Exception:
  116. continue
  117. entry['extractor_key'] = WWEIE.ie_key()
  118. entries.append(entry)
  119. return self.playlist_result(entries, display_id)