rtl2.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. import re
  2. from .common import InfoExtractor
  3. from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
  4. from ..compat import (
  5. compat_b64decode,
  6. compat_str,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. int_or_none,
  11. strip_or_none,
  12. )
  13. class RTL2IE(InfoExtractor):
  14. IE_NAME = 'rtl2'
  15. _VALID_URL = r'https?://(?:www\.)?rtl2\.de/sendung/[^/]+/(?:video/(?P<vico_id>\d+)[^/]+/(?P<vivi_id>\d+)-|folge/)(?P<id>[^/?#]+)'
  16. _TESTS = [{
  17. 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
  18. 'info_dict': {
  19. 'id': 'folge-203-0',
  20. 'ext': 'f4v',
  21. 'title': 'GRIP sucht den Sommerkönig',
  22. 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
  23. },
  24. 'params': {
  25. # rtmp download
  26. 'skip_download': True,
  27. },
  28. 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
  29. }, {
  30. 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
  31. 'info_dict': {
  32. 'id': 'anna-erwischt-alex',
  33. 'ext': 'mp4',
  34. 'title': 'Anna erwischt Alex!',
  35. 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.'
  36. },
  37. 'params': {
  38. # rtmp download
  39. 'skip_download': True,
  40. },
  41. 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
  42. }]
  43. def _real_extract(self, url):
  44. vico_id, vivi_id, display_id = self._match_valid_url(url).groups()
  45. if not vico_id:
  46. webpage = self._download_webpage(url, display_id)
  47. mobj = re.search(
  48. r'data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
  49. webpage)
  50. if mobj:
  51. vico_id = mobj.group('vico_id')
  52. vivi_id = mobj.group('vivi_id')
  53. else:
  54. vico_id = self._html_search_regex(
  55. r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
  56. vivi_id = self._html_search_regex(
  57. r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
  58. info = self._download_json(
  59. 'https://service.rtl2.de/api-player-vipo/video.php',
  60. display_id, query={
  61. 'vico_id': vico_id,
  62. 'vivi_id': vivi_id,
  63. })
  64. video_info = info['video']
  65. title = video_info['titel']
  66. formats = []
  67. rtmp_url = video_info.get('streamurl')
  68. if rtmp_url:
  69. rtmp_url = rtmp_url.replace('\\', '')
  70. stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
  71. rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
  72. formats.append({
  73. 'format_id': 'rtmp',
  74. 'url': rtmp_url,
  75. 'play_path': stream_url,
  76. 'player_url': 'https://www.rtl2.de/sites/default/modules/rtl2/jwplayer/jwplayer-7.6.0/jwplayer.flash.swf',
  77. 'page_url': url,
  78. 'flash_version': 'LNX 11,2,202,429',
  79. 'rtmp_conn': rtmp_conn,
  80. 'no_resume': True,
  81. 'quality': 1,
  82. })
  83. m3u8_url = video_info.get('streamurl_hls')
  84. if m3u8_url:
  85. formats.extend(self._extract_akamai_formats(m3u8_url, display_id))
  86. return {
  87. 'id': display_id,
  88. 'title': title,
  89. 'thumbnail': video_info.get('image'),
  90. 'description': video_info.get('beschreibung'),
  91. 'duration': int_or_none(video_info.get('duration')),
  92. 'formats': formats,
  93. }
  94. class RTL2YouBaseIE(InfoExtractor):
  95. _BACKWERK_BASE_URL = 'https://p-you-backwerk.rtl2apps.de/'
  96. class RTL2YouIE(RTL2YouBaseIE):
  97. IE_NAME = 'rtl2:you'
  98. _VALID_URL = r'http?://you\.rtl2\.de/(?:video/\d+/|youplayer/index\.html\?.*?\bvid=)(?P<id>\d+)'
  99. _TESTS = [{
  100. 'url': 'http://you.rtl2.de/video/3002/15740/MJUNIK%20%E2%80%93%20Home%20of%20YOU/307-hirn-wo-bist-du',
  101. 'info_dict': {
  102. 'id': '15740',
  103. 'ext': 'mp4',
  104. 'title': 'MJUNIK – Home of YOU - #307 Hirn, wo bist du?!',
  105. 'description': 'md5:ddaa95c61b372b12b66e115b2772fe01',
  106. 'age_limit': 12,
  107. },
  108. }, {
  109. 'url': 'http://you.rtl2.de/youplayer/index.html?vid=15712',
  110. 'only_matching': True,
  111. }]
  112. _AES_KEY = b'\xe9W\xe4.<*\xb8\x1a\xd2\xb6\x92\xf3C\xd3\xefL\x1b\x03*\xbbbH\xc0\x03\xffo\xc2\xf2(\xaa\xaa!'
  113. _GEO_COUNTRIES = ['DE']
  114. def _real_extract(self, url):
  115. video_id = self._match_id(url)
  116. stream_data = self._download_json(
  117. self._BACKWERK_BASE_URL + 'stream/video/' + video_id, video_id)
  118. data, iv = compat_b64decode(stream_data['streamUrl']).decode().split(':')
  119. stream_url = unpad_pkcs7(aes_cbc_decrypt_bytes(
  120. compat_b64decode(data), self._AES_KEY, compat_b64decode(iv)))
  121. if b'rtl2_you_video_not_found' in stream_url:
  122. raise ExtractorError('video not found', expected=True)
  123. formats = self._extract_m3u8_formats(stream_url.decode(), video_id, 'mp4', 'm3u8_native')
  124. video_data = self._download_json(
  125. self._BACKWERK_BASE_URL + 'video/' + video_id, video_id)
  126. series = video_data.get('formatTitle')
  127. title = episode = video_data.get('title') or series
  128. if series and series != title:
  129. title = '%s - %s' % (series, title)
  130. return {
  131. 'id': video_id,
  132. 'title': title,
  133. 'formats': formats,
  134. 'description': strip_or_none(video_data.get('description')),
  135. 'thumbnail': video_data.get('image'),
  136. 'duration': int_or_none(stream_data.get('duration') or video_data.get('duration'), 1000),
  137. 'series': series,
  138. 'episode': episode,
  139. 'age_limit': int_or_none(video_data.get('minimumAge')),
  140. }
  141. class RTL2YouSeriesIE(RTL2YouBaseIE):
  142. IE_NAME = 'rtl2:you:series'
  143. _VALID_URL = r'http?://you\.rtl2\.de/videos/(?P<id>\d+)'
  144. _TEST = {
  145. 'url': 'http://you.rtl2.de/videos/115/dragon-ball',
  146. 'info_dict': {
  147. 'id': '115',
  148. },
  149. 'playlist_mincount': 5,
  150. }
  151. def _real_extract(self, url):
  152. series_id = self._match_id(url)
  153. stream_data = self._download_json(
  154. self._BACKWERK_BASE_URL + 'videos',
  155. series_id, query={
  156. 'formatId': series_id,
  157. 'limit': 1000000000,
  158. })
  159. entries = []
  160. for video in stream_data.get('videos', []):
  161. video_id = compat_str(video['videoId'])
  162. if not video_id:
  163. continue
  164. entries.append(self.url_result(
  165. 'http://you.rtl2.de/video/%s/%s' % (series_id, video_id),
  166. 'RTL2You', video_id))
  167. return self.playlist_result(entries, series_id)