sportdeutschland.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. join_nonempty,
  4. strip_or_none,
  5. traverse_obj,
  6. unified_timestamp,
  7. )
  8. class SportDeutschlandIE(InfoExtractor):
  9. _VALID_URL = r'https?://sportdeutschland\.tv/(?P<id>(?:[^/]+/)?[^?#/&]+)'
  10. _TESTS = [{
  11. 'url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
  12. 'info_dict': {
  13. 'id': '9839a5c7-0dbb-48a8-ab63-3b408adc7b54',
  14. 'ext': 'mp4',
  15. 'title': 'Buchholzer Formationswochenende 2023 - Samstag - 1. Bundesliga / Landesliga',
  16. 'display_id': 'blauweissbuchholztanzsport/buchholzer-formationswochenende-2023-samstag-1-bundesliga-landesliga',
  17. 'description': 'md5:a288c794a5ee69e200d8f12982f81a87',
  18. 'live_status': 'was_live',
  19. 'channel': 'Blau-Weiss Buchholz Tanzsport',
  20. 'channel_url': 'https://sportdeutschland.tv/blauweissbuchholztanzsport',
  21. 'channel_id': '93ec33c9-48be-43b6-b404-e016b64fdfa3',
  22. 'duration': 32447,
  23. 'upload_date': '20230114',
  24. 'timestamp': 1673733618,
  25. },
  26. }, {
  27. 'url': 'https://sportdeutschland.tv/deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
  28. 'info_dict': {
  29. 'id': '95c80c52-6b9a-4ae9-9197-984145adfced',
  30. 'ext': 'mp4',
  31. 'title': 'BWF Tour: 1. Runde Feld 1 - YONEX GAINWARD German Open 2022',
  32. 'display_id': 'deutscherbadmintonverband/bwf-tour-1-runde-feld-1-yonex-gainward-german-open-2022-0',
  33. 'description': 'md5:2afb5996ceb9ac0b2ac81f563d3a883e',
  34. 'live_status': 'was_live',
  35. 'channel': 'Deutscher Badminton Verband',
  36. 'channel_url': 'https://sportdeutschland.tv/deutscherbadmintonverband',
  37. 'channel_id': '93ca5866-2551-49fc-8424-6db35af58920',
  38. 'duration': 41097,
  39. 'upload_date': '20220309',
  40. 'timestamp': 1646860727.0,
  41. },
  42. }, {
  43. 'url': 'https://sportdeutschland.tv/ggcbremen/formationswochenende-latein-2023',
  44. 'info_dict': {
  45. 'id': '9889785e-55b0-4d97-a72a-ce9a9f157cce',
  46. 'title': 'Formationswochenende Latein 2023 - Samstag',
  47. 'display_id': 'ggcbremen/formationswochenende-latein-2023',
  48. 'description': 'md5:6e4060d40ff6a8f8eeb471b51a8f08b2',
  49. 'live_status': 'was_live',
  50. 'channel': 'Grün-Gold-Club Bremen e.V.',
  51. 'channel_id': '9888f04e-bb46-4c7f-be47-df960a4167bb',
  52. 'channel_url': 'https://sportdeutschland.tv/ggcbremen',
  53. },
  54. 'playlist_count': 3,
  55. 'playlist': [{
  56. 'info_dict': {
  57. 'id': '988e1fea-9d44-4fab-8c72-3085fb667547',
  58. 'ext': 'mp4',
  59. 'channel_url': 'https://sportdeutschland.tv/ggcbremen',
  60. 'channel_id': '9888f04e-bb46-4c7f-be47-df960a4167bb',
  61. 'channel': 'Grün-Gold-Club Bremen e.V.',
  62. 'duration': 86,
  63. 'title': 'Formationswochenende Latein 2023 - Samstag Part 1',
  64. 'upload_date': '20230225',
  65. 'timestamp': 1677349909,
  66. 'live_status': 'was_live',
  67. },
  68. }],
  69. }, {
  70. 'url': 'https://sportdeutschland.tv/dtb/gymnastik-international-tag-1',
  71. 'info_dict': {
  72. 'id': '95d71b8a-370a-4b87-ad16-94680da18528',
  73. 'ext': 'mp4',
  74. 'title': r're:Gymnastik International - Tag 1 .+',
  75. 'display_id': 'dtb/gymnastik-international-tag-1',
  76. 'channel_id': '936ecef1-2f4a-4e08-be2f-68073cb7ecab',
  77. 'channel': 'Deutscher Turner-Bund',
  78. 'channel_url': 'https://sportdeutschland.tv/dtb',
  79. 'description': 'md5:07a885dde5838a6f0796ee21dc3b0c52',
  80. 'live_status': 'is_live',
  81. },
  82. 'skip': 'live',
  83. }]
  84. def _process_video(self, asset_id, video):
  85. is_live = video['type'] == 'mux_live'
  86. token = self._download_json(
  87. f'https://api.sportdeutschland.tv/api/frontend/asset-token/{asset_id}',
  88. video['id'], query={'type': video['type'], 'playback_id': video['src']})['token']
  89. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  90. f'https://stream.mux.com/{video["src"]}.m3u8?token={token}', video['id'], live=is_live)
  91. return {
  92. 'is_live': is_live,
  93. 'formats': formats,
  94. 'subtitles': subtitles,
  95. **traverse_obj(video, {
  96. 'id': 'id',
  97. 'duration': ('duration', {lambda x: float(x) > 0 and float(x)}),
  98. 'timestamp': ('created_at', {unified_timestamp}),
  99. }),
  100. }
  101. def _real_extract(self, url):
  102. display_id = self._match_id(url)
  103. meta = self._download_json(
  104. f'https://api.sportdeutschland.tv/api/stateless/frontend/assets/{display_id}',
  105. display_id, query={'access_token': 'true'})
  106. info = {
  107. 'display_id': display_id,
  108. **traverse_obj(meta, {
  109. 'id': (('id', 'uuid'), ),
  110. 'title': (('title', 'name'), {strip_or_none}),
  111. 'description': 'description',
  112. 'channel': ('profile', 'name'),
  113. 'channel_id': ('profile', 'id'),
  114. 'is_live': 'currently_live',
  115. 'was_live': 'was_live',
  116. 'channel_url': ('profile', 'slug', {lambda x: f'https://sportdeutschland.tv/{x}'}),
  117. }, get_all=False),
  118. }
  119. parts = traverse_obj(meta, (('livestream', ('videos', ...)), ))
  120. entries = [{
  121. 'title': join_nonempty(info.get('title'), f'Part {i}', delim=' '),
  122. **traverse_obj(info, {'channel': 'channel', 'channel_id': 'channel_id',
  123. 'channel_url': 'channel_url', 'was_live': 'was_live'}),
  124. **self._process_video(info['id'], video),
  125. } for i, video in enumerate(parts, 1)]
  126. return {
  127. '_type': 'multi_video',
  128. **info,
  129. 'entries': entries,
  130. } if len(entries) > 1 else {
  131. **info,
  132. **entries[0],
  133. 'title': info.get('title'),
  134. }