rtl2.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class RTL2IE(InfoExtractor):
  6. _VALID_URL = r'http?://(?:www\.)?rtl2\.de/[^?#]*?/(?P<id>[^?#/]*?)(?:$|/(?:$|[?#]))'
  7. _TESTS = [{
  8. 'url': 'http://www.rtl2.de/sendung/grip-das-motormagazin/folge/folge-203-0',
  9. 'md5': 'bfcc179030535b08dc2b36b469b5adc7',
  10. 'info_dict': {
  11. 'id': 'folge-203-0',
  12. 'ext': 'f4v',
  13. 'title': 'GRIP sucht den Sommerkönig',
  14. 'description': 'Matthias, Det und Helge treten gegeneinander an.'
  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. 'md5': 'ffcd517d2805b57ce11a58a2980c2b02',
  23. 'info_dict': {
  24. 'id': '21040-anna-erwischt-alex',
  25. 'ext': 'mp4',
  26. 'title': 'Anna erwischt Alex!',
  27. 'description': 'Anna ist Alex\' Tochter bei Köln 50667.'
  28. },
  29. 'params': {
  30. # rtmp download
  31. 'skip_download': True,
  32. },
  33. }]
  34. def _real_extract(self, url):
  35. # Some rtl2 urls have no slash at the end, so append it.
  36. if not url.endswith('/'):
  37. url += '/'
  38. video_id = self._match_id(url)
  39. webpage = self._download_webpage(url, video_id)
  40. mobj = re.search(
  41. r'<div[^>]+data-collection="(?P<vico_id>\d+)"[^>]+data-video="(?P<vivi_id>\d+)"',
  42. webpage)
  43. if mobj:
  44. vico_id = mobj.group('vico_id')
  45. vivi_id = mobj.group('vivi_id')
  46. else:
  47. vico_id = self._html_search_regex(
  48. r'vico_id\s*:\s*([0-9]+)', webpage, 'vico_id')
  49. vivi_id = self._html_search_regex(
  50. r'vivi_id\s*:\s*([0-9]+)', webpage, 'vivi_id')
  51. info_url = 'http://www.rtl2.de/video/php/get_video.php?vico_id=' + vico_id + '&vivi_id=' + vivi_id
  52. info = self._download_json(info_url, video_id)
  53. video_info = info['video']
  54. title = video_info['titel']
  55. description = video_info.get('beschreibung')
  56. thumbnail = video_info.get('image')
  57. download_url = video_info['streamurl']
  58. download_url = download_url.replace('\\', '')
  59. stream_url = 'mp4:' + self._html_search_regex(r'ondemand/(.*)', download_url, 'stream URL')
  60. rtmp_conn = ["S:connect", "O:1", "NS:pageUrl:" + url, "NB:fpad:0", "NN:videoFunction:1", "O:0"]
  61. formats = [{
  62. 'url': download_url,
  63. 'play_path': stream_url,
  64. 'player_url': 'http://www.rtl2.de/flashplayer/vipo_player.swf',
  65. 'page_url': url,
  66. 'flash_version': 'LNX 11,2,202,429',
  67. 'rtmp_conn': rtmp_conn,
  68. 'no_resume': True,
  69. }]
  70. self._sort_formats(formats)
  71. return {
  72. 'id': video_id,
  73. 'title': title,
  74. 'thumbnail': thumbnail,
  75. 'description': description,
  76. 'formats': formats,
  77. }