logo

youtube-dl

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

rtl2.py (7406B)


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