logo

youtube-dl

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

servus.py (5663B)


  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|pm-wissen)\.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. 'url': 'https://www.pm-wissen.com/videos/aa-24mus4g2w2112/',
  57. 'only_matching': True,
  58. }]
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url).upper()
  61. token = self._download_json(
  62. 'https://auth.redbullmediahouse.com/token', video_id,
  63. 'Downloading token', data=urlencode_postdata({
  64. 'grant_type': 'client_credentials',
  65. }), headers={
  66. 'Authorization': 'Basic SVgtMjJYNEhBNFdEM1cxMTpEdDRVSkFLd2ZOMG5IMjB1NGFBWTBmUFpDNlpoQ1EzNA==',
  67. })
  68. access_token = token['access_token']
  69. token_type = token.get('token_type', 'Bearer')
  70. video = self._download_json(
  71. 'https://sparkle-api.liiift.io/api/v1/stv/channels/international/assets/%s' % video_id,
  72. video_id, 'Downloading video JSON', headers={
  73. 'Authorization': '%s %s' % (token_type, access_token),
  74. })
  75. formats = []
  76. thumbnail = None
  77. for resource in video['resources']:
  78. if not isinstance(resource, dict):
  79. continue
  80. format_url = url_or_none(resource.get('url'))
  81. if not format_url:
  82. continue
  83. extension = resource.get('extension')
  84. type_ = resource.get('type')
  85. if extension == 'jpg' or type_ == 'reference_keyframe':
  86. thumbnail = format_url
  87. continue
  88. ext = determine_ext(format_url)
  89. if type_ == 'dash' or ext == 'mpd':
  90. formats.extend(self._extract_mpd_formats(
  91. format_url, video_id, mpd_id='dash', fatal=False))
  92. elif type_ == 'hls' or ext == 'm3u8':
  93. formats.extend(self._extract_m3u8_formats(
  94. format_url, video_id, 'mp4', entry_protocol='m3u8_native',
  95. m3u8_id='hls', fatal=False))
  96. elif extension == 'mp4' or ext == 'mp4':
  97. formats.append({
  98. 'url': format_url,
  99. 'format_id': type_,
  100. 'width': int_or_none(resource.get('width')),
  101. 'height': int_or_none(resource.get('height')),
  102. })
  103. self._sort_formats(formats)
  104. attrs = {}
  105. for attribute in video['attributes']:
  106. if not isinstance(attribute, dict):
  107. continue
  108. key = attribute.get('fieldKey')
  109. value = attribute.get('fieldValue')
  110. if not key or not value:
  111. continue
  112. attrs[key] = value
  113. title = attrs.get('title_stv') or video_id
  114. alt_title = attrs.get('title')
  115. description = attrs.get('long_description') or attrs.get('short_description')
  116. series = attrs.get('label')
  117. season = attrs.get('season')
  118. episode = attrs.get('chapter')
  119. duration = float_or_none(attrs.get('duration'), scale=1000)
  120. season_number = int_or_none(self._search_regex(
  121. r'Season (\d+)', season or '', 'season number', default=None))
  122. episode_number = int_or_none(self._search_regex(
  123. r'Episode (\d+)', episode or '', 'episode number', default=None))
  124. return {
  125. 'id': video_id,
  126. 'title': title,
  127. 'alt_title': alt_title,
  128. 'description': description,
  129. 'thumbnail': thumbnail,
  130. 'duration': duration,
  131. 'timestamp': unified_timestamp(video.get('lastPublished')),
  132. 'series': series,
  133. 'season': season,
  134. 'season_number': season_number,
  135. 'episode': episode,
  136. 'episode_number': episode_number,
  137. 'formats': formats,
  138. }