servus.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. float_or_none,
  7. int_or_none,
  8. unified_timestamp,
  9. urlencode_postdata,
  10. url_or_none,
  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\.com/videos
  19. )
  20. /(?P<id>[aA]{2}-\w+|\d+-\d+)
  21. '''
  22. _TESTS = [{
  23. # new URL schema
  24. 'url': 'https://www.servustv.com/videos/aa-1t6vbu5pw1w12/',
  25. 'md5': '60474d4c21f3eb148838f215c37f02b9',
  26. 'info_dict': {
  27. 'id': 'AA-1T6VBU5PW1W12',
  28. 'ext': 'mp4',
  29. 'title': 'Die Grünen aus Sicht des Volkes',
  30. 'alt_title': 'Talk im Hangar-7 Voxpops Gruene',
  31. 'description': 'md5:1247204d85783afe3682644398ff2ec4',
  32. 'thumbnail': r're:^https?://.*\.jpg',
  33. 'duration': 62.442,
  34. 'timestamp': 1605193976,
  35. 'upload_date': '20201112',
  36. 'series': 'Talk im Hangar-7',
  37. 'season': 'Season 9',
  38. 'season_number': 9,
  39. 'episode': 'Episode 31 - September 14',
  40. 'episode_number': 31,
  41. }
  42. }, {
  43. # old URL schema
  44. 'url': 'https://www.servus.com/de/p/Die-Gr%C3%BCnen-aus-Sicht-des-Volkes/AA-1T6VBU5PW1W12/',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'https://www.servus.com/at/p/Wie-das-Leben-beginnt/1309984137314-381415152/',
  48. 'only_matching': True,
  49. }, {
  50. 'url': 'https://www.servus.com/tv/videos/aa-1t6vbu5pw1w12/',
  51. 'only_matching': True,
  52. }, {
  53. 'url': 'https://www.servus.com/tv/videos/1380889096408-1235196658/',
  54. 'only_matching': True,
  55. }]
  56. def _real_extract(self, url):
  57. video_id = self._match_id(url).upper()
  58. token = self._download_json(
  59. 'https://auth.redbullmediahouse.com/token', video_id,
  60. 'Downloading token', data=urlencode_postdata({
  61. 'grant_type': 'client_credentials',
  62. }), headers={
  63. 'Authorization': 'Basic SVgtMjJYNEhBNFdEM1cxMTpEdDRVSkFLd2ZOMG5IMjB1NGFBWTBmUFpDNlpoQ1EzNA==',
  64. })
  65. access_token = token['access_token']
  66. token_type = token.get('token_type', 'Bearer')
  67. video = self._download_json(
  68. 'https://sparkle-api.liiift.io/api/v1/stv/channels/international/assets/%s' % video_id,
  69. video_id, 'Downloading video JSON', headers={
  70. 'Authorization': '%s %s' % (token_type, access_token),
  71. })
  72. formats = []
  73. thumbnail = None
  74. for resource in video['resources']:
  75. if not isinstance(resource, dict):
  76. continue
  77. format_url = url_or_none(resource.get('url'))
  78. if not format_url:
  79. continue
  80. extension = resource.get('extension')
  81. type_ = resource.get('type')
  82. if extension == 'jpg' or type_ == 'reference_keyframe':
  83. thumbnail = format_url
  84. continue
  85. ext = determine_ext(format_url)
  86. if type_ == 'dash' or ext == 'mpd':
  87. formats.extend(self._extract_mpd_formats(
  88. format_url, video_id, mpd_id='dash', fatal=False))
  89. elif type_ == 'hls' or ext == 'm3u8':
  90. formats.extend(self._extract_m3u8_formats(
  91. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  92. m3u8_id='hls', fatal=False))
  93. elif extension == 'mp4' or ext == 'mp4':
  94. formats.append({
  95. 'url': format_url,
  96. 'format_id': type_,
  97. 'width': int_or_none(resource.get('width')),
  98. 'height': int_or_none(resource.get('height')),
  99. })
  100. self._sort_formats(formats)
  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. }