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