]>
Commit | Line | Data |
---|---|---|
8b0d7a66 KM |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
fdeea726 | 4 | import codecs |
8b0d7a66 KM |
5 | import re |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..utils import ( | |
8b0d7a66 | 9 | ExtractorError, |
577281b0 KM |
10 | float_or_none, |
11 | int_or_none, | |
12 | parse_duration, | |
8b0d7a66 KM |
13 | ) |
14 | ||
15 | ||
16 | class CDAIE(InfoExtractor): | |
f1ced6df | 17 | _VALID_URL = r'https?://(?:(?:www\.)?cda\.pl/video|ebd\.cda\.pl/[0-9]+x[0-9]+)/(?P<id>[0-9a-z]+)' |
577281b0 | 18 | _BASE_URL = 'http://www.cda.pl/' |
f1ced6df S |
19 | _TESTS = [{ |
20 | 'url': 'http://www.cda.pl/video/5749950c', | |
21 | 'md5': '6f844bf51b15f31fae165365707ae970', | |
22 | 'info_dict': { | |
23 | 'id': '5749950c', | |
24 | 'ext': 'mp4', | |
25 | 'height': 720, | |
26 | 'title': 'Oto dlaczego przed zakrętem należy zwolnić.', | |
577281b0 | 27 | 'description': 'md5:269ccd135d550da90d1662651fcb9772', |
ec85ded8 | 28 | 'thumbnail': r're:^https?://.*\.jpg$', |
577281b0 | 29 | 'average_rating': float, |
f1ced6df S |
30 | 'duration': 39 |
31 | } | |
32 | }, { | |
33 | 'url': 'http://www.cda.pl/video/57413289', | |
34 | 'md5': 'a88828770a8310fc00be6c95faf7f4d5', | |
35 | 'info_dict': { | |
36 | 'id': '57413289', | |
37 | 'ext': 'mp4', | |
38 | 'title': 'Lądowanie na lotnisku na Maderze', | |
577281b0 | 39 | 'description': 'md5:60d76b71186dcce4e0ba6d4bbdb13e1a', |
ec85ded8 | 40 | 'thumbnail': r're:^https?://.*\.jpg$', |
577281b0 KM |
41 | 'uploader': 'crash404', |
42 | 'view_count': int, | |
43 | 'average_rating': float, | |
f1ced6df | 44 | 'duration': 137 |
8b0d7a66 | 45 | } |
f1ced6df S |
46 | }, { |
47 | 'url': 'http://ebd.cda.pl/0x0/5749950c', | |
48 | 'only_matching': True, | |
49 | }] | |
8b0d7a66 KM |
50 | |
51 | def _real_extract(self, url): | |
52 | video_id = self._match_id(url) | |
577281b0 KM |
53 | self._set_cookie('cda.pl', 'cda.player', 'html5') |
54 | webpage = self._download_webpage( | |
55 | self._BASE_URL + '/video/' + video_id, video_id) | |
8b0d7a66 KM |
56 | |
57 | if 'Ten film jest dostępny dla użytkowników premium' in webpage: | |
58 | raise ExtractorError('This video is only available for premium users.', expected=True) | |
59 | ||
8b0d7a66 KM |
60 | formats = [] |
61 | ||
577281b0 KM |
62 | uploader = self._search_regex(r'''(?x) |
63 | <(span|meta)[^>]+itemprop=(["\'])author\2[^>]*> | |
64 | (?:<\1[^>]*>[^<]*</\1>|(?!</\1>)(?:.|\n))*? | |
65 | <(span|meta)[^>]+itemprop=(["\'])name\4[^>]*>(?P<uploader>[^<]+)</\3> | |
66 | ''', webpage, 'uploader', default=None, group='uploader') | |
67 | view_count = self._search_regex( | |
68 | r'Odsłony:(?:\s| )*([0-9]+)', webpage, | |
69 | 'view_count', default=None) | |
70 | average_rating = self._search_regex( | |
71 | r'<(?:span|meta)[^>]+itemprop=(["\'])ratingValue\1[^>]*>(?P<rating_value>[0-9.]+)', | |
72 | webpage, 'rating', fatal=False, group='rating_value') | |
73 | ||
f1ced6df S |
74 | info_dict = { |
75 | 'id': video_id, | |
577281b0 KM |
76 | 'title': self._og_search_title(webpage), |
77 | 'description': self._og_search_description(webpage), | |
78 | 'uploader': uploader, | |
79 | 'view_count': int_or_none(view_count), | |
80 | 'average_rating': float_or_none(average_rating), | |
81 | 'thumbnail': self._og_search_thumbnail(webpage), | |
f1ced6df S |
82 | 'formats': formats, |
83 | 'duration': None, | |
84 | } | |
8b0d7a66 | 85 | |
f1ced6df | 86 | def extract_format(page, version): |
577281b0 KM |
87 | json_str = self._search_regex( |
88 | r'player_data=(\\?["\'])(?P<player_data>.+?)\1', page, | |
89 | '%s player_json' % version, fatal=False, group='player_data') | |
90 | if not json_str: | |
91 | return | |
92 | player_data = self._parse_json( | |
93 | json_str, '%s player_data' % version, fatal=False) | |
94 | if not player_data: | |
95 | return | |
96 | video = player_data.get('video') | |
97 | if not video or 'file' not in video: | |
98 | self.report_warning('Unable to extract %s version information' % version) | |
f1ced6df | 99 | return |
fdeea726 AS |
100 | if video['file'].startswith('uggc'): |
101 | video['file'] = codecs.decode(video['file'], 'rot_13') | |
102 | if video['file'].endswith('adc.mp4'): | |
103 | video['file'] = video['file'].replace('adc.mp4', '.mp4') | |
f1ced6df | 104 | f = { |
577281b0 | 105 | 'url': video['file'], |
f1ced6df S |
106 | } |
107 | m = re.search( | |
108 | r'<a[^>]+data-quality="(?P<format_id>[^"]+)"[^>]+href="[^"]+"[^>]+class="[^"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p', | |
109 | page) | |
110 | if m: | |
111 | f.update({ | |
112 | 'format_id': m.group('format_id'), | |
113 | 'height': int(m.group('height')), | |
114 | }) | |
115 | info_dict['formats'].append(f) | |
116 | if not info_dict['duration']: | |
577281b0 | 117 | info_dict['duration'] = parse_duration(video.get('duration')) |
f1ced6df S |
118 | |
119 | extract_format(webpage, 'default') | |
120 | ||
121 | for href, resolution in re.findall( | |
122 | r'<a[^>]+data-quality="[^"]+"[^>]+href="([^"]+)"[^>]+class="quality-btn"[^>]*>([0-9]+p)', | |
123 | webpage): | |
124 | webpage = self._download_webpage( | |
577281b0 KM |
125 | self._BASE_URL + href, video_id, |
126 | 'Downloading %s version information' % resolution, fatal=False) | |
8b0d7a66 | 127 | if not webpage: |
f1ced6df S |
128 | # Manually report warning because empty page is returned when |
129 | # invalid version is requested. | |
130 | self.report_warning('Unable to download %s version information' % resolution) | |
8b0d7a66 | 131 | continue |
f1ced6df | 132 | extract_format(webpage, resolution) |
8b0d7a66 KM |
133 | |
134 | self._sort_formats(formats) | |
135 | ||
f1ced6df | 136 | return info_dict |