2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
12 compat_urllib_parse_unquote
,
27 class CDAIE(InfoExtractor
):
28 _VALID_URL
= r
'https?://(?:(?:www\.)?cda\.pl/video|ebd\.cda\.pl/[0-9]+x[0-9]+)/(?P<id>[0-9a-z]+)'
29 _BASE_URL
= 'http://www.cda.pl/'
31 'url': 'http://www.cda.pl/video/5749950c',
32 'md5': '6f844bf51b15f31fae165365707ae970',
37 'title': 'Oto dlaczego przed zakrętem należy zwolnić.',
38 'description': 'md5:269ccd135d550da90d1662651fcb9772',
39 'thumbnail': r
're:^https?://.*\.jpg$',
40 'average_rating': float,
43 'upload_date': '20160221',
44 'timestamp': 1456078244,
47 'url': 'http://www.cda.pl/video/57413289',
48 'md5': 'a88828770a8310fc00be6c95faf7f4d5',
52 'title': 'Lądowanie na lotnisku na Maderze',
53 'description': 'md5:60d76b71186dcce4e0ba6d4bbdb13e1a',
54 'thumbnail': r
're:^https?://.*\.jpg$',
55 'uploader': 'crash404',
57 'average_rating': float,
63 'url': 'http://www.cda.pl/video/1273454c4',
67 'title': 'Bronson (2008) napisy HD 1080p',
68 'description': 'md5:1b6cb18508daf2dc4e0fa4db77fec24c',
70 'uploader': 'boniek61',
71 'thumbnail': r
're:^https?://.*\.jpg$',
75 'average_rating': float,
78 'url': 'http://ebd.cda.pl/0x0/5749950c',
79 'only_matching': True,
82 def _download_age_confirm_page(self
, url
, video_id
, *args
, **kwargs
):
83 form_data
= random_birthday('rok', 'miesiac', 'dzien')
84 form_data
.update({'return': url, 'module': 'video', 'module_id': video_id}
)
85 data
, content_type
= multipart_encode(form_data
)
86 return self
._download
_webpage
(
87 urljoin(url
, '/a/validatebirth'), video_id
, *args
,
90 'Content-Type': content_type
,
93 def _real_extract(self
, url
):
94 video_id
= self
._match
_id
(url
)
95 self
._set
_cookie
('cda.pl', 'cda.player', 'html5')
96 webpage
= self
._download
_webpage
(
97 self
._BASE
_URL
+ '/video/' + video_id
, video_id
)
99 if 'Ten film jest dostępny dla użytkowników premium' in webpage
:
100 raise ExtractorError('This video is only available for premium users.', expected
=True)
102 if re
.search(r
'niedostępn[ey] w(?: |\s+)Twoim kraju\s*<', webpage
):
103 self
.raise_geo_restricted()
105 need_confirm_age
= False
106 if self
._html
_search
_regex
(r
'(<form[^>]+action="[^"]*/a/validatebirth[^"]*")',
107 webpage
, 'birthday validate form', default
=None):
108 webpage
= self
._download
_age
_confirm
_page
(
109 url
, video_id
, note
='Confirming age')
110 need_confirm_age
= True
114 uploader
= self
._search
_regex
(r
'''(?x)
115 <(span|meta)[^>]+itemprop=(["\'])author\
2[^
>]*>
116 (?
:<\
1[^
>]*>[^
<]*</\
1>|
(?
!</\
1>)(?
:.|
\n))*?
117 <(span|meta
)[^
>]+itemprop
=(["\'])name\4[^>]*>(?P<uploader>[^<]+)</\3>
118 ''', webpage, 'uploader', default=None, group='uploader')
119 view_count = self._search_regex(
120 r'Odsłony:(?:\s| )*([0-9]+)', webpage,
121 'view_count', default=None)
122 average_rating = self._search_regex(
123 (r'<(?:span|meta)[^>]+itemprop=(["\'])ratingValue\
1[^
>]*>(?P
<rating_value
>[0-9.]+)',
124 r'<span
[^
>]+\bclass
=["\']rating["\'][^
>]*>(?P
<rating_value
>[0-9.]+)'), webpage, 'rating
', fatal=False,
125 group='rating_value
')
129 'title
': self._og_search_title(webpage),
130 'description
': self._og_search_description(webpage),
131 'uploader
': uploader,
132 'view_count
': int_or_none(view_count),
133 'average_rating
': float_or_none(average_rating),
134 'thumbnail
': self._og_search_thumbnail(webpage),
137 'age_limit
': 18 if need_confirm_age else 0,
140 info = self._search_json_ld(webpage, video_id, default={})
142 # Source: https://www.cda.pl/js/player.js?t=1606154898
144 for p in ('_XDDD
', '_CDA
', '_ADC
', '_CXD
', '_QWE
', '_Q5
', '_IKSDE
'):
146 a = compat_urllib_parse_unquote(a)
150 b.append(compat_chr(33 + (f + 14) % 94) if 33 <= f <= 126 else compat_chr(f))
152 a = a.replace('.cda
.mp4
', '')
153 for p in ('.2cda
.pl
', '.3cda
.pl
'):
154 a = a.replace(p, '.cda
.pl
')
156 a = a.replace('/upstream
', '.mp4
/upstream
')
157 return 'https
://' + a
158 return 'https
://' + a + '.mp4
'
160 def extract_format(page, version):
161 json_str = self._html_search_regex(
162 r'player_data
=(\\?
["\'])(?P<player_data>.+?)\1', page,
163 '%s player_json' % version, fatal=False, group='player_data')
166 player_data = self._parse_json(
167 json_str, '%s player_data' % version, fatal=False)
170 video = player_data.get('video')
171 if not video or 'file' not in video:
172 self.report_warning('Unable to extract %s version information' % version)
174 if video['file'].startswith('uggc'):
175 video['file'] = codecs.decode(video['file'], 'rot_13')
176 if video['file'].endswith('adc.mp4'):
177 video['file'] = video['file'].replace('adc.mp4', '.mp4')
178 elif not video['file'].startswith('http'):
179 video['file'] = decrypt_file(video['file'])
180 video_quality = video.get('quality')
181 qualities = video.get('qualities', {})
182 video_quality = next((k for k, v in qualities.items() if v == video_quality), video_quality)
183 info_dict['formats'].append({
184 'url': video['file'],
185 'format_id': video_quality,
186 'height': int_or_none(video_quality[:-1]),
188 for quality, cda_quality in qualities.items():
189 if quality == video_quality:
191 data = {'jsonrpc': '2.0', 'method': 'videoGetLink', 'id': 2,
192 'params': [video_id, cda_quality, video.get('ts'), video.get('hash2'), {}]}
193 data = json.dumps(data).encode('utf-8')
194 video_url = self._download_json(
195 f'https://www.cda.pl/video/{video_id}', video_id, headers={
196 'Content-Type': 'application/json',
197 'X-Requested-With': 'XMLHttpRequest'
198 }, data=data, note=f'Fetching {quality} url',
199 errnote=f'Failed to fetch {quality} url', fatal=False)
200 if try_get(video_url, lambda x: x['result']['status']) == 'ok':
201 video_url = try_get(video_url, lambda x: x['result']['resp'])
202 info_dict['formats'].append({
204 'format_id': quality,
205 'height': int_or_none(quality[:-1])
208 if not info_dict['duration']:
209 info_dict['duration'] = parse_duration(video.get('duration'))
211 extract_format(webpage, 'default')
213 for href, resolution in re.findall(
214 r'<a[^>]+data-quality="[^
"]+"[^
>]+href
="([^"]+)"[^>]+class="quality
-btn
"[^>]*>([0-9]+p)',
217 handler = self._download_age_confirm_page
219 handler = self._download_webpage
222 urljoin(self._BASE_URL, href), video_id,
223 'Downloading %s version information' % resolution, fatal=False)
225 # Manually report warning because empty page is returned when
226 # invalid version is requested.
227 self.report_warning('Unable to download %s version information' % resolution)
230 extract_format(webpage, resolution)
232 self._sort_formats(formats)
234 return merge_dicts(info_dict, info)