servus.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. float_or_none,
  5. int_or_none,
  6. unified_timestamp,
  7. urlencode_postdata,
  8. url_or_none,
  9. )
  10. class ServusIE(InfoExtractor):
  11. _VALID_URL = r'''(?x)
  12. https?://
  13. (?:www\.)?
  14. (?:
  15. servus\.com/(?:(?:at|de)/p/[^/]+|tv/videos)|
  16. (?:servustv|pm-wissen)\.com/videos
  17. )
  18. /(?P<id>[aA]{2}-\w+|\d+-\d+)
  19. '''
  20. _TESTS = [{
  21. # new URL schema
  22. 'url': 'https://www.servustv.com/videos/aa-1t6vbu5pw1w12/',
  23. 'md5': '60474d4c21f3eb148838f215c37f02b9',
  24. 'info_dict': {
  25. 'id': 'AA-1T6VBU5PW1W12',
  26. 'ext': 'mp4',
  27. 'title': 'Die Grünen aus Sicht des Volkes',
  28. 'alt_title': 'Talk im Hangar-7 Voxpops Gruene',
  29. 'description': 'md5:1247204d85783afe3682644398ff2ec4',
  30. 'thumbnail': r're:^https?://.*\.jpg',
  31. 'duration': 62.442,
  32. 'timestamp': 1605193976,
  33. 'upload_date': '20201112',
  34. 'series': 'Talk im Hangar-7',
  35. 'season': 'Season 9',
  36. 'season_number': 9,
  37. 'episode': 'Episode 31 - September 14',
  38. 'episode_number': 31,
  39. }
  40. }, {
  41. # old URL schema
  42. 'url': 'https://www.servus.com/de/p/Die-Gr%C3%BCnen-aus-Sicht-des-Volkes/AA-1T6VBU5PW1W12/',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://www.servus.com/at/p/Wie-das-Leben-beginnt/1309984137314-381415152/',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'https://www.servus.com/tv/videos/aa-1t6vbu5pw1w12/',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'https://www.servus.com/tv/videos/1380889096408-1235196658/',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'https://www.pm-wissen.com/videos/aa-24mus4g2w2112/',
  55. 'only_matching': True,
  56. }]
  57. def _real_extract(self, url):
  58. video_id = self._match_id(url).upper()
  59. token = self._download_json(
  60. 'https://auth.redbullmediahouse.com/token', video_id,
  61. 'Downloading token', data=urlencode_postdata({
  62. 'grant_type': 'client_credentials',
  63. }), headers={
  64. 'Authorization': 'Basic SVgtMjJYNEhBNFdEM1cxMTpEdDRVSkFLd2ZOMG5IMjB1NGFBWTBmUFpDNlpoQ1EzNA==',
  65. })
  66. access_token = token['access_token']
  67. token_type = token.get('token_type', 'Bearer')
  68. video = self._download_json(
  69. 'https://sparkle-api.liiift.io/api/v1/stv/channels/international/assets/%s' % video_id,
  70. video_id, 'Downloading video JSON', headers={
  71. 'Authorization': '%s %s' % (token_type, access_token),
  72. })
  73. formats = []
  74. thumbnail = None
  75. for resource in video['resources']:
  76. if not isinstance(resource, dict):
  77. continue
  78. format_url = url_or_none(resource.get('url'))
  79. if not format_url:
  80. continue
  81. extension = resource.get('extension')
  82. type_ = resource.get('type')
  83. if extension == 'jpg' or type_ == 'reference_keyframe':
  84. thumbnail = format_url
  85. continue
  86. ext = determine_ext(format_url)
  87. if type_ == 'dash' or ext == 'mpd':
  88. formats.extend(self._extract_mpd_formats(
  89. format_url, video_id, mpd_id='dash', fatal=False))
  90. elif type_ == 'hls' or ext == 'm3u8':
  91. formats.extend(self._extract_m3u8_formats(
  92. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  93. m3u8_id='hls', fatal=False))
  94. elif extension == 'mp4' or ext == 'mp4':
  95. formats.append({
  96. 'url': format_url,
  97. 'format_id': type_,
  98. 'width': int_or_none(resource.get('width')),
  99. 'height': int_or_none(resource.get('height')),
  100. })
  101. attrs = {}
  102. for attribute in video['attributes']:
  103. if not isinstance(attribute, dict):
  104. continue
  105. key = attribute.get('fieldKey')
  106. value = attribute.get('fieldValue')
  107. if not key or not value:
  108. continue
  109. attrs[key] = value
  110. title = attrs.get('title_stv') or video_id
  111. alt_title = attrs.get('title')
  112. description = attrs.get('long_description') or attrs.get('short_description')
  113. series = attrs.get('label')
  114. season = attrs.get('season')
  115. episode = attrs.get('chapter')
  116. duration = float_or_none(attrs.get('duration'), scale=1000)
  117. season_number = int_or_none(self._search_regex(
  118. r'Season (\d+)', season or '', 'season number', default=None))
  119. episode_number = int_or_none(self._search_regex(
  120. r'Episode (\d+)', episode or '', 'episode number', default=None))
  121. return {
  122. 'id': video_id,
  123. 'title': title,
  124. 'alt_title': alt_title,
  125. 'description': description,
  126. 'thumbnail': thumbnail,
  127. 'duration': duration,
  128. 'timestamp': unified_timestamp(video.get('lastPublished')),
  129. 'series': series,
  130. 'season': season,
  131. 'season_number': season_number,
  132. 'episode': episode,
  133. 'episode_number': episode_number,
  134. 'formats': formats,
  135. }