logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

servus.py (5793B)


  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. float_or_none,
  5. format_field,
  6. int_or_none,
  7. join_nonempty,
  8. traverse_obj,
  9. unescapeHTML,
  10. unified_timestamp,
  11. )
  12. class ServusIE(InfoExtractor):
  13. _VALID_URL = r'''(?x)
  14. https?://
  15. (?:www\.)?
  16. (?:
  17. servus\.com/(?:(?:at|de)/p/[^/]+|tv/videos)|
  18. (?:servustv|pm-wissen)\.com/(?:[^/]+/)?v(?:ideos)?
  19. )
  20. /(?P<id>[aA]{2}-?\w+|\d+-\d+)
  21. '''
  22. _TESTS = [{
  23. # URL schema v3
  24. 'url': 'https://www.servustv.com/natur/v/aa-28bycqnh92111/',
  25. 'info_dict': {
  26. 'id': 'AA-28BYCQNH92111',
  27. 'ext': 'mp4',
  28. 'title': 'Vie Ferrate - Klettersteige in den Alpen',
  29. 'description': 'md5:25e47ddd83a009a0f9789ba18f2850ce',
  30. 'thumbnail': r're:^https?://.*\.jpg',
  31. 'duration': 2823,
  32. 'timestamp': 1655752333,
  33. 'upload_date': '20220620',
  34. 'series': 'Bergwelten',
  35. 'season': 'Season 11',
  36. 'season_number': 11,
  37. 'episode': 'Episode 8 - Vie Ferrate – Klettersteige in den Alpen',
  38. 'episode_number': 8,
  39. 'categories': ['Bergwelten'],
  40. },
  41. 'params': {'skip_download': 'm3u8'},
  42. }, {
  43. 'url': 'https://www.servustv.com/natur/v/aa-1xg5xwmgw2112/',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'https://www.servustv.com/natur/v/aansszcx3yi9jmlmhdc1/',
  47. 'only_matching': True,
  48. }, {
  49. # URL schema v2
  50. 'url': 'https://www.servustv.com/videos/aa-1t6vbu5pw1w12/',
  51. 'only_matching': True,
  52. }, {
  53. # URL schema v1
  54. 'url': 'https://www.servus.com/de/p/Die-Gr%C3%BCnen-aus-Sicht-des-Volkes/AA-1T6VBU5PW1W12/',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'https://www.servus.com/at/p/Wie-das-Leben-beginnt/1309984137314-381415152/',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'https://www.servus.com/tv/videos/aa-1t6vbu5pw1w12/',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'https://www.servus.com/tv/videos/1380889096408-1235196658/',
  64. 'only_matching': True,
  65. }, {
  66. 'url': 'https://www.pm-wissen.com/videos/aa-24mus4g2w2112/',
  67. 'only_matching': True,
  68. }]
  69. def _real_extract(self, url):
  70. video_id = self._match_id(url).upper()
  71. webpage = self._download_webpage(url, video_id)
  72. next_data = self._search_nextjs_data(webpage, video_id, fatal=False)
  73. video = self._download_json(
  74. 'https://api-player.redbull.com/stv/servus-tv-playnet',
  75. video_id, 'Downloading video JSON', query={'videoId': video_id})
  76. if not video.get('videoUrl'):
  77. self._report_errors(video)
  78. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  79. video['videoUrl'], video_id, 'mp4', m3u8_id='hls')
  80. season = video.get('season')
  81. season_number = int_or_none(self._search_regex(
  82. r'Season (\d+)', season or '', 'season number', default=None))
  83. episode = video.get('chapter')
  84. episode_number = int_or_none(self._search_regex(
  85. r'Episode (\d+)', episode or '', 'episode number', default=None))
  86. return {
  87. 'id': video_id,
  88. 'title': video.get('title'),
  89. 'description': self._get_description(next_data) or video.get('description'),
  90. 'thumbnail': video.get('poster'),
  91. 'duration': float_or_none(video.get('duration')),
  92. 'timestamp': unified_timestamp(video.get('currentSunrise')),
  93. 'series': video.get('label'),
  94. 'season': season,
  95. 'season_number': season_number,
  96. 'episode': episode,
  97. 'episode_number': episode_number,
  98. 'formats': formats,
  99. 'subtitles': subtitles,
  100. **traverse_obj(next_data, ('props', 'pageProps', 'data', {
  101. 'title': ('title', 'rendered', {str}),
  102. 'timestamp': ('stv_date', 'raw', {int}),
  103. 'duration': ('stv_duration', {float_or_none}),
  104. 'categories': ('category_names', ..., {str}),
  105. })),
  106. }
  107. def _get_description(self, next_data):
  108. return join_nonempty(*traverse_obj(next_data, (
  109. 'props', 'pageProps', 'data',
  110. ('stv_short_description', 'stv_long_description'), {str},
  111. {lambda x: x.replace('\n\n', '\n')}, {unescapeHTML})), delim='\n\n')
  112. def _report_errors(self, video):
  113. playability_errors = traverse_obj(video, ('playabilityErrors', ...))
  114. if not playability_errors:
  115. raise ExtractorError('No videoUrl and no information about errors')
  116. elif 'FSK_BLOCKED' in playability_errors:
  117. details = traverse_obj(video, ('playabilityErrorDetails', 'FSK_BLOCKED'), expected_type=dict)
  118. message = format_field(''.join((
  119. format_field(details, 'minEveningHour', ' from %02d:00'),
  120. format_field(details, 'maxMorningHour', ' to %02d:00'),
  121. format_field(details, 'minAge', ' (Minimum age %d)'),
  122. )), None, 'Only available%s') or 'Blocked by FSK with unknown availability'
  123. elif 'NOT_YET_AVAILABLE' in playability_errors:
  124. message = format_field(
  125. video, (('playabilityErrorDetails', 'NOT_YET_AVAILABLE', 'availableFrom'), 'currentSunrise'),
  126. 'Only available from %s') or 'Video not yet available with unknown availability'
  127. else:
  128. message = f'Video unavailable: {", ".join(playability_errors)}'
  129. raise ExtractorError(message, expected=True)