logo

youtube-dl

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

nhl.py (5004B)


  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. determine_ext,
  7. int_or_none,
  8. parse_iso8601,
  9. parse_duration,
  10. )
  11. class NHLBaseIE(InfoExtractor):
  12. def _real_extract(self, url):
  13. site, tmp_id = re.match(self._VALID_URL, url).groups()
  14. video_data = self._download_json(
  15. 'https://%s/%s/%sid/v1/%s/details/web-v1.json'
  16. % (self._CONTENT_DOMAIN, site[:3], 'item/' if site == 'mlb' else '', tmp_id), tmp_id)
  17. if video_data.get('type') != 'video':
  18. video_data = video_data['media']
  19. video = video_data.get('video')
  20. if video:
  21. video_data = video
  22. else:
  23. videos = video_data.get('videos')
  24. if videos:
  25. video_data = videos[0]
  26. video_id = compat_str(video_data['id'])
  27. title = video_data['title']
  28. formats = []
  29. for playback in video_data.get('playbacks', []):
  30. playback_url = playback.get('url')
  31. if not playback_url:
  32. continue
  33. ext = determine_ext(playback_url)
  34. if ext == 'm3u8':
  35. m3u8_formats = self._extract_m3u8_formats(
  36. playback_url, video_id, 'mp4', 'm3u8_native',
  37. m3u8_id=playback.get('name', 'hls'), fatal=False)
  38. self._check_formats(m3u8_formats, video_id)
  39. formats.extend(m3u8_formats)
  40. else:
  41. height = int_or_none(playback.get('height'))
  42. formats.append({
  43. 'format_id': playback.get('name', 'http' + ('-%dp' % height if height else '')),
  44. 'url': playback_url,
  45. 'width': int_or_none(playback.get('width')),
  46. 'height': height,
  47. 'tbr': int_or_none(self._search_regex(r'_(\d+)[kK]', playback_url, 'bitrate', default=None)),
  48. })
  49. self._sort_formats(formats)
  50. thumbnails = []
  51. cuts = video_data.get('image', {}).get('cuts') or []
  52. if isinstance(cuts, dict):
  53. cuts = cuts.values()
  54. for thumbnail_data in cuts:
  55. thumbnail_url = thumbnail_data.get('src')
  56. if not thumbnail_url:
  57. continue
  58. thumbnails.append({
  59. 'url': thumbnail_url,
  60. 'width': int_or_none(thumbnail_data.get('width')),
  61. 'height': int_or_none(thumbnail_data.get('height')),
  62. })
  63. return {
  64. 'id': video_id,
  65. 'title': title,
  66. 'description': video_data.get('description'),
  67. 'timestamp': parse_iso8601(video_data.get('date')),
  68. 'duration': parse_duration(video_data.get('duration')),
  69. 'thumbnails': thumbnails,
  70. 'formats': formats,
  71. }
  72. class NHLIE(NHLBaseIE):
  73. IE_NAME = 'nhl.com'
  74. _VALID_URL = r'https?://(?:www\.)?(?P<site>nhl|wch2016)\.com/(?:[^/]+/)*c-(?P<id>\d+)'
  75. _CONTENT_DOMAIN = 'nhl.bamcontent.com'
  76. _TESTS = [{
  77. # type=video
  78. 'url': 'https://www.nhl.com/video/anisimov-cleans-up-mess/t-277752844/c-43663503',
  79. 'md5': '0f7b9a8f986fb4b4eeeece9a56416eaf',
  80. 'info_dict': {
  81. 'id': '43663503',
  82. 'ext': 'mp4',
  83. 'title': 'Anisimov cleans up mess',
  84. 'description': 'md5:a02354acdfe900e940ce40706939ca63',
  85. 'timestamp': 1461288600,
  86. 'upload_date': '20160422',
  87. },
  88. }, {
  89. # type=article
  90. 'url': 'https://www.nhl.com/news/dennis-wideman-suspended/c-278258934',
  91. 'md5': '1f39f4ea74c1394dea110699a25b366c',
  92. 'info_dict': {
  93. 'id': '40784403',
  94. 'ext': 'mp4',
  95. 'title': 'Wideman suspended by NHL',
  96. 'description': 'Flames defenseman Dennis Wideman was banned 20 games for violation of Rule 40 (Physical Abuse of Officials)',
  97. 'upload_date': '20160204',
  98. 'timestamp': 1454544904,
  99. },
  100. }, {
  101. # Some m3u8 URLs are invalid (https://github.com/ytdl-org/youtube-dl/issues/10713)
  102. 'url': 'https://www.nhl.com/predators/video/poile-laviolette-on-subban-trade/t-277437416/c-44315003',
  103. 'md5': '50b2bb47f405121484dda3ccbea25459',
  104. 'info_dict': {
  105. 'id': '44315003',
  106. 'ext': 'mp4',
  107. 'title': 'Poile, Laviolette on Subban trade',
  108. 'description': 'General manager David Poile and head coach Peter Laviolette share their thoughts on acquiring P.K. Subban from Montreal (06/29/16)',
  109. 'timestamp': 1467242866,
  110. 'upload_date': '20160629',
  111. },
  112. }, {
  113. 'url': 'https://www.wch2016.com/video/caneur-best-of-game-2-micd-up/t-281230378/c-44983703',
  114. 'only_matching': True,
  115. }, {
  116. 'url': 'https://www.wch2016.com/news/3-stars-team-europe-vs-team-canada/c-282195068',
  117. 'only_matching': True,
  118. }]