logo

youtube-dl

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

sportdeutschland.py (4320B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_parse_qs,
  6. compat_urllib_parse_urlparse,
  7. )
  8. from ..utils import (
  9. clean_html,
  10. float_or_none,
  11. int_or_none,
  12. parse_iso8601,
  13. strip_or_none,
  14. try_get,
  15. )
  16. class SportDeutschlandIE(InfoExtractor):
  17. _VALID_URL = r'https?://sportdeutschland\.tv/(?P<id>(?:[^/]+/)?[^?#/&]+)'
  18. _TESTS = [{
  19. 'url': 'https://sportdeutschland.tv/badminton/re-live-deutsche-meisterschaften-2020-halbfinals?playlistId=0',
  20. 'info_dict': {
  21. 'id': '5318cac0275701382770543d7edaf0a0',
  22. 'ext': 'mp4',
  23. 'title': 'Re-live: Deutsche Meisterschaften 2020 - Halbfinals - Teil 1',
  24. 'duration': 16106.36,
  25. },
  26. 'params': {
  27. 'noplaylist': True,
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. }, {
  32. 'url': 'https://sportdeutschland.tv/badminton/re-live-deutsche-meisterschaften-2020-halbfinals?playlistId=0',
  33. 'info_dict': {
  34. 'id': 'c6e2fdd01f63013854c47054d2ab776f',
  35. 'title': 'Re-live: Deutsche Meisterschaften 2020 - Halbfinals',
  36. 'description': 'md5:5263ff4c31c04bb780c9f91130b48530',
  37. 'duration': 31397,
  38. },
  39. 'playlist_count': 2,
  40. }, {
  41. 'url': 'https://sportdeutschland.tv/freeride-world-tour-2021-fieberbrunn-oesterreich',
  42. 'only_matching': True,
  43. }]
  44. def _real_extract(self, url):
  45. display_id = self._match_id(url)
  46. data = self._download_json(
  47. 'https://backend.sportdeutschland.tv/api/permalinks/' + display_id,
  48. display_id, query={'access_token': 'true'})
  49. asset = data['asset']
  50. title = (asset.get('title') or asset['label']).strip()
  51. asset_id = asset.get('id') or asset.get('uuid')
  52. info = {
  53. 'id': asset_id,
  54. 'title': title,
  55. 'description': clean_html(asset.get('body') or asset.get('description')) or asset.get('teaser'),
  56. 'duration': int_or_none(asset.get('seconds')),
  57. }
  58. videos = asset.get('videos') or []
  59. if len(videos) > 1:
  60. playlist_id = compat_parse_qs(compat_urllib_parse_urlparse(url).query).get('playlistId', [None])[0]
  61. if playlist_id:
  62. if self._downloader.params.get('noplaylist'):
  63. videos = [videos[int(playlist_id)]]
  64. self.to_screen('Downloading just a single video because of --no-playlist')
  65. else:
  66. self.to_screen('Downloading playlist %s - add --no-playlist to just download video' % asset_id)
  67. def entries():
  68. for i, video in enumerate(videos, 1):
  69. video_id = video.get('uuid')
  70. video_url = video.get('url')
  71. if not (video_id and video_url):
  72. continue
  73. formats = self._extract_m3u8_formats(
  74. video_url.replace('.smil', '.m3u8'), video_id, 'mp4', fatal=False)
  75. if not formats:
  76. continue
  77. yield {
  78. 'id': video_id,
  79. 'formats': formats,
  80. 'title': title + ' - ' + (video.get('label') or 'Teil %d' % i),
  81. 'duration': float_or_none(video.get('duration')),
  82. }
  83. info.update({
  84. '_type': 'multi_video',
  85. 'entries': entries(),
  86. })
  87. else:
  88. formats = self._extract_m3u8_formats(
  89. videos[0]['url'].replace('.smil', '.m3u8'), asset_id, 'mp4')
  90. section_title = strip_or_none(try_get(data, lambda x: x['section']['title']))
  91. info.update({
  92. 'formats': formats,
  93. 'display_id': asset.get('permalink'),
  94. 'thumbnail': try_get(asset, lambda x: x['images'][0]),
  95. 'categories': [section_title] if section_title else None,
  96. 'view_count': int_or_none(asset.get('views')),
  97. 'is_live': asset.get('is_live') is True,
  98. 'timestamp': parse_iso8601(asset.get('date') or asset.get('published_at')),
  99. })
  100. return info