]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cda.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
16 class CDAIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:(?:www\.)?cda\.pl/video|ebd\.cda\.pl/[0-9]+x[0-9]+)/(?P<id>[0-9a-z]+)'
18 _BASE_URL
= 'http://www.cda.pl/'
20 'url': 'http://www.cda.pl/video/5749950c',
21 'md5': '6f844bf51b15f31fae165365707ae970',
26 'title': 'Oto dlaczego przed zakrętem należy zwolnić.',
27 'description': 'md5:269ccd135d550da90d1662651fcb9772',
28 'thumbnail': r
're:^https?://.*\.jpg$',
29 'average_rating': float,
33 'url': 'http://www.cda.pl/video/57413289',
34 'md5': 'a88828770a8310fc00be6c95faf7f4d5',
38 'title': 'Lądowanie na lotnisku na Maderze',
39 'description': 'md5:60d76b71186dcce4e0ba6d4bbdb13e1a',
40 'thumbnail': r
're:^https?://.*\.jpg$',
41 'uploader': 'crash404',
43 'average_rating': float,
47 'url': 'http://ebd.cda.pl/0x0/5749950c',
48 'only_matching': True,
51 def _real_extract(self
, url
):
52 video_id
= self
._match
_id
(url
)
53 self
._set
_cookie
('cda.pl', 'cda.player', 'html5')
54 webpage
= self
._download
_webpage
(
55 self
._BASE
_URL
+ '/video/' + video_id
, video_id
)
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)
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
')
76 'title
': self._og_search_title(webpage),
77 'description
': self._og_search_description(webpage),
79 'view_count
': int_or_none(view_count),
80 'average_rating
': float_or_none(average_rating),
81 'thumbnail
': self._og_search_thumbnail(webpage),
86 def extract_format(page, version):
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')
92 player_data = self._parse_json(
93 json_str, '%s player_data' % version, fatal=False)
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)
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')
105 'url': video['file'],
108 r'<a[^>]+data-quality="(?P
<format_id
>[^
"]+)"[^
>]+href
="[^"]+"[^>]+class="[^
"]*quality-btn-active[^"]*">(?P<height>[0-9]+)p',
112 'format_id': m.group('format_id'),
113 'height': int(m.group('height')),
115 info_dict['formats'].append(f)
116 if not info_dict['duration']:
117 info_dict['duration'] = parse_duration(video.get('duration'))
119 extract_format(webpage, 'default')
121 for href, resolution in re.findall(
122 r'<a[^>]+data-quality="[^
"]+"[^
>]+href
="([^"]+)"[^>]+class="quality
-btn
"[^>]*>([0-9]+p)',
124 webpage = self._download_webpage(
125 self._BASE_URL + href, video_id,
126 'Downloading %s version information' % resolution, fatal=False)
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)
132 extract_format(webpage, resolution)
134 self._sort_formats(formats)