2 from __future__ import unicode_literals
7 from .common import InfoExtractor
19 class CDAIE(InfoExtractor):
20 _VALID_URL = r'https?://(?:(?:www\.)?cda\.pl/video|ebd\.cda\.pl/[0-9]+x[0-9]+)/(?P<id>[0-9a-z]+)'
21 _BASE_URL = 'http://www.cda.pl/'
23 'url': 'http://www.cda.pl/video/5749950c',
24 'md5': '6f844bf51b15f31fae165365707ae970',
29 'title': 'Oto dlaczego przed zakrętem należy zwolnić.',
30 'description': 'md5:269ccd135d550da90d1662651fcb9772',
31 'thumbnail': r're:^https?://.*\.jpg$',
32 'average_rating': float,
37 'url': 'http://www.cda.pl/video/57413289',
38 'md5': 'a88828770a8310fc00be6c95faf7f4d5',
42 'title': 'Lądowanie na lotnisku na Maderze',
43 'description': 'md5:60d76b71186dcce4e0ba6d4bbdb13e1a',
44 'thumbnail': r're:^https?://.*\.jpg$',
45 'uploader': 'crash404',
47 'average_rating': float,
53 'url': 'http://www.cda.pl/video/1273454c4',
57 'title': 'Bronson (2008) napisy HD 1080p',
58 'description': 'md5:1b6cb18508daf2dc4e0fa4db77fec24c',
60 'uploader': 'boniek61',
61 'thumbnail': r're:^https?://.*\.jpg$',
65 'average_rating': float,
68 'url': 'http://ebd.cda.pl/0x0/5749950c',
69 'only_matching': True,
72 def _download_age_confirm_page(self, url, video_id, *args, **kwargs):
73 form_data = random_birthday('rok', 'miesiac', 'dzien')
74 form_data.update({'return': url, 'module': 'video', 'module_id': video_id})
75 data, content_type = multipart_encode(form_data)
76 return self._download_webpage(
77 urljoin(url, '/a/validatebirth'), video_id, *args,
80 'Content-Type': content_type,
83 def _real_extract(self, url):
84 video_id = self._match_id(url)
85 self._set_cookie('cda.pl', 'cda.player', 'html5')
86 webpage = self._download_webpage(
87 self._BASE_URL + '/video/' + video_id, video_id)
89 if 'Ten film jest dostępny dla użytkowników premium' in webpage:
90 raise ExtractorError('This video is only available for premium users.', expected=True)
92 need_confirm_age = False
93 if self._html_search_regex(r'(<form[^>]+action="/a/validatebirth")',
94 webpage, 'birthday validate form', default=None):
95 webpage = self._download_age_confirm_page(
96 url, video_id, note='Confirming age')
97 need_confirm_age = True
101 uploader = self._search_regex(r'''(?x)
102 <(span|meta)[^>]+itemprop=(["\'])author\2[^>]*>
103 (?:<\1[^>]*>[^<]*</\1>|(?!</\1>)(?:.|\n))*?
104 <(span|meta)[^>]+itemprop=(["\'])name\4[^>]*>(?P<uploader>[^<]+)</\3>
105 ''', webpage, 'uploader', default=None, group='uploader')
106 view_count = self._search_regex(
107 r'Odsłony:(?:\s| )*([0-9]+)', webpage,
108 'view_count', default=None)
109 average_rating = self._search_regex(
110 r'<(?:span|meta)[^>]+itemprop=(["\'])ratingValue\1[^>]*>(?P<rating_value>[0-9.]+)',
111 webpage, 'rating', fatal=False, group='rating_value')
115 'title': self._og_search_title(webpage),
116 'description': self._og_search_description(webpage),
117 'uploader': uploader,
118 'view_count': int_or_none(view_count),
119 'average_rating': float_or_none(average_rating),
120 'thumbnail': self._og_search_thumbnail(webpage),
123 'age_limit': 18 if need_confirm_age else 0,
126 def extract_format(page, version):
127 json_str = self._html_search_regex(
128 r'player_data=(\\?["\'])(?P<player_data>.+?)\1', page,
129 '%s player_json' % version, fatal=False, group='player_data')
132 player_data = self._parse_json(
133 json_str, '%s player_data' % version, fatal=False)
136 video = player_data.get('video')
137 if not video or 'file' not in video:
138 self.report_warning('Unable to extract %s version information' % version)
140 if video['file'].startswith('uggc'):
141 video['file'] = codecs.decode(video['file'], 'rot_13')
142 if video['file'].endswith('adc.mp4'):
143 video['file'] = video['file'].replace('adc.mp4', '.mp4')
145 'url': video['file'],
148 r'<a[^>]+data-quality="(?P<format_id>[^"]+)"[^>]+href="[^"]+"[^>]+class="[^"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p',
152 'format_id': m.group('format_id'),
153 'height': int(m.group('height')),
155 info_dict['formats'].append(f)
156 if not info_dict['duration']:
157 info_dict['duration'] = parse_duration(video.get('duration'))
159 extract_format(webpage, 'default')
161 for href, resolution in re.findall(
162 r'<a[^>]+data-quality="[^"]+"[^>]+href="([^"]+)"[^>]+class="quality-btn"[^>]*>([0-9]+p)',
165 handler = self._download_age_confirm_page
167 handler = self._download_webpage
170 self._BASE_URL + href, video_id,
171 'Downloading %s version information' % resolution, fatal=False)
173 # Manually report warning because empty page is returned when
174 # invalid version is requested.
175 self.report_warning('Unable to download %s version information' % resolution)
178 extract_format(webpage, resolution)
180 self._sort_formats(formats)