You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import int_or_none
  6. class RTL2IE(InfoExtractor):
  7. _VALID_URL = r'http?://(?:www\.)?rtl2\.de/[^?#]*?/(?P<id>[^?#/]*?)(?:$|/(?:$|[?#]))'
  8. _TESTS = [{
  9. 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
  10. 'info_dict': {
  11. 'id': 'folge-203-0',
  12. 'ext': 'f4v',
  13. 'title': 'GRIP sucht den Sommerkönig',
  14. 'description': 'md5:e3adbb940fd3c6e76fa341b8748b562f'
  15. },
  16. 'params': {
  17. # rtmp download
  18. 'skip_download': True,
  19. },
  20. }, {
  21. 'url': 'http://www.rtl2.de/sendung/koeln-50667/video/5512-anna/21040-anna-erwischt-alex/',
  22. 'info_dict': {
  23. 'id': '21040-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. }]
  33. def _real_extract(self, url):
  34. # Some rtl2 urls have no slash at the end, so append it.
  35. if not url.endswith('/'):
  36. url += '/'
  37. video_id = self._match_id(url)
  38. webpage = self._download_webpage(url, video_id)
  39. mobj = re.search(
  40. r'<div[^>]+data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
  41. webpage)
  42. if mobj:
  43. vico_id = mobj.group('vico_id')
  44. vivi_id = mobj.group('vivi_id')
  45. else:
  46. vico_id = self._html_search_regex(
  47. r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
  48. vivi_id = self._html_search_regex(
  49. r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
  50. info = self._download_json(
  51. 'http://www.rtl2.de/sites/default/modules/rtl2/mediathek/php/get_video_jw.php',
  52. video_id, query={
  53. 'vico_id': vico_id,
  54. 'vivi_id': vivi_id,
  55. })
  56. video_info = info['video']
  57. title = video_info['titel']
  58. formats = []
  59. rtmp_url = video_info.get('streamurl')
  60. if rtmp_url:
  61. rtmp_url = rtmp_url.replace('\\', '')
  62. stream_url = 'mp4:' + self._html_search_regex(r'/ondemand/(.+)', rtmp_url, 'stream URL')
  63. rtmp_conn = ['S:connect', 'O:1', 'NS:pageUrl:' + url, 'NB:fpad:0', 'NN:videoFunction:1', 'O:0']
  64. formats.append({
  65. 'format_id': 'rtmp',
  66. 'url': rtmp_url,
  67. 'play_path': stream_url,
  68. 'player_url': 'http://www.rtl2.de/flashplayer/vipo_player.swf',
  69. 'page_url': url,
  70. 'flash_version': 'LNX 11,2,202,429',
  71. 'rtmp_conn': rtmp_conn,
  72. 'no_resume': True,
  73. 'preference': 1,
  74. })
  75. m3u8_url = video_info.get('streamurl_hls')
  76. if m3u8_url:
  77. formats.extend(self._extract_akamai_formats(m3u8_url, video_id))
  78. self._sort_formats(formats)
  79. return {
  80. 'id': video_id,
  81. 'title': title,
  82. 'thumbnail': video_info.get('image'),
  83. 'description': video_info.get('beschreibung'),
  84. 'duration': int_or_none(video_info.get('duration')),
  85. 'formats': formats,
  86. }