rtl2.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import int_or_none
  4. class RTL2IE(InfoExtractor):
  5. IE_NAME = 'rtl2'
  6. _VALID_URL = r'https?://(?:www\.)?rtl2\.de/sendung/[^/]+/(?:video/(?P<vico_id>\d+)[^/]+/(?P<vivi_id>\d+)-|folge/)(?P<id>[^/?#]+)'
  7. _TESTS = [{
  8. 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
  9. 'info_dict': {
  10. 'id': 'folge-203-0',
  11. 'ext': 'f4v',
  12. 'title': 'GRIP sucht den Sommerkönig',
  13. 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f',
  14. },
  15. 'params': {
  16. # rtmp download
  17. 'skip_download': True,
  18. },
  19. 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
  20. }, {
  21. 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
  22. 'info_dict': {
  23. 'id': 'anna-erwischt-alex',
  24. 'ext': 'mp4',
  25. 'title': 'Anna erwischt Alex!',
  26. 'description': 'Anna nimmt ihrem Vater nicht ab, dass er nicht spielt. Und tatsächlich erwischt sie ihn auf frischer Tat.',
  27. },
  28. 'params': {
  29. # rtmp download
  30. 'skip_download': True,
  31. },
  32. 'expected_warnings': ['Unable to download f4m manifest', 'Failed to download m3u8 information'],
  33. }]
  34. def _real_extract(self, url):
  35. vico_id, vivi_id, display_id = self._match_valid_url(url).groups()
  36. if not vico_id:
  37. webpage = self._download_webpage(url, display_id)
  38. mobj = re.search(
  39. r'data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
  40. webpage)
  41. if mobj:
  42. vico_id = mobj.group('vico_id')
  43. vivi_id = mobj.group('vivi_id')
  44. else:
  45. vico_id = self._html_search_regex(
  46. r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
  47. vivi_id = self._html_search_regex(
  48. r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
  49. info = self._download_json(
  50. 'https://service.rtl2.de/api-player-vipo/video.php',
  51. display_id, query={
  52. 'vico_id': vico_id,
  53. 'vivi_id': vivi_id,
  54. })
  55. video_info = info['video']
  56. title = video_info['titel']
  57. formats = []
  58. rtmp_url = video_info.get('streamurl')
  59. if rtmp_url:
  60. rtmp_url = rtmp_url.replace('\\', '')
  61. stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
  62. rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
  63. formats.append({
  64. 'format_id': 'rtmp',
  65. 'url': rtmp_url,
  66. 'play_path': stream_url,
  67. 'player_url': 'https://www.rtl2.de/sites/default/modules/rtl2/jwplayer/jwplayer-7.6.0/jwplayer.flash.swf',
  68. 'page_url': url,
  69. 'flash_version': 'LNX 11,2,202,429',
  70. 'rtmp_conn': rtmp_conn,
  71. 'no_resume': True,
  72. 'quality': 1,
  73. })
  74. m3u8_url = video_info.get('streamurl_hls')
  75. if m3u8_url:
  76. formats.extend(self._extract_akamai_formats(m3u8_url, display_id))
  77. return {
  78. 'id': display_id,
  79. 'title': title,
  80. 'thumbnail': video_info.get('image'),
  81. 'description': video_info.get('beschreibung'),
  82. 'duration': int_or_none(video_info.get('duration')),
  83. 'formats': formats,
  84. }