]>
Commit | Line | Data |
---|---|---|
a2b6f946 RA |
1 | import base64 |
2 | import hashlib | |
b8b01bb9 S |
3 | |
4 | from .common import InfoExtractor | |
1d3586d0 | 5 | from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7 |
e962ae15 | 6 | from ..utils import ( |
e962ae15 | 7 | int_or_none, |
a2b6f946 RA |
8 | parse_codecs, |
9 | parse_duration, | |
e962ae15 | 10 | ) |
b8b01bb9 S |
11 | |
12 | ||
13 | class NewstubeIE(InfoExtractor): | |
14 | _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)' | |
15 | _TEST = { | |
1fd01551 | 16 | 'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym', |
a2b6f946 | 17 | 'md5': '9d10320ad473444352f72f746ccb8b8c', |
b8b01bb9 | 18 | 'info_dict': { |
1fd01551 | 19 | 'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6', |
e962ae15 | 20 | 'ext': 'mp4', |
1fd01551 S |
21 | 'title': 'Телеканал CNN переместил город Славянск в Крым', |
22 | 'description': 'md5:419a8c9f03442bc0b0a794d689360335', | |
23 | 'duration': 31.05, | |
b8b01bb9 | 24 | }, |
b8b01bb9 S |
25 | } |
26 | ||
27 | def _real_extract(self, url): | |
a2b6f946 | 28 | video_id = self._match_id(url) |
b8b01bb9 | 29 | |
a2b6f946 RA |
30 | page = self._download_webpage(url, video_id) |
31 | title = self._html_search_meta(['og:title', 'twitter:title'], page, fatal=True) | |
b8b01bb9 S |
32 | |
33 | video_guid = self._html_search_regex( | |
a2b6f946 | 34 | r'<meta\s+property="og:video(?::(?:(?:secure_)?url|iframe))?"\s+content="https?://(?:www\.)?newstube\.ru/embed/(?P<guid>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})', |
b8b01bb9 S |
35 | page, 'video GUID') |
36 | ||
a2b6f946 RA |
37 | enc_data = base64.b64decode(self._download_webpage( |
38 | 'https://www.newstube.ru/embed/api/player/getsources2', | |
39 | video_guid, query={ | |
40 | 'guid': video_guid, | |
41 | 'ff': 3, | |
42 | })) | |
43 | key = hashlib.pbkdf2_hmac( | |
44 | 'sha1', video_guid.replace('-', '').encode(), enc_data[:16], 1)[:16] | |
1d3586d0 | 45 | dec_data = unpad_pkcs7(aes_cbc_decrypt_bytes(enc_data[32:], key, enc_data[16:32])) |
46 | sources = self._parse_json(dec_data, video_guid) | |
b8b01bb9 S |
47 | |
48 | formats = [] | |
a2b6f946 RA |
49 | for source in sources: |
50 | source_url = source.get('Src') | |
51 | if not source_url: | |
b8b01bb9 | 52 | continue |
a2b6f946 RA |
53 | height = int_or_none(source.get('Height')) |
54 | f = { | |
55 | 'format_id': 'http' + ('-%dp' % height if height else ''), | |
56 | 'url': source_url, | |
57 | 'width': int_or_none(source.get('Width')), | |
b8b01bb9 | 58 | 'height': height, |
a2b6f946 RA |
59 | } |
60 | source_type = source.get('Type') | |
61 | if source_type: | |
62 | f.update(parse_codecs(self._search_regex( | |
63 | r'codecs="([^"]+)"', source_type, 'codecs', fatal=False))) | |
64 | formats.append(f) | |
e962ae15 | 65 | |
66 | self._check_formats(formats, video_guid) | |
b8b01bb9 S |
67 | |
68 | return { | |
69 | 'id': video_guid, | |
70 | 'title': title, | |
a2b6f946 RA |
71 | 'description': self._html_search_meta(['description', 'og:description'], page), |
72 | 'thumbnail': self._html_search_meta(['og:image:secure_url', 'og:image', 'twitter:image'], page), | |
73 | 'duration': parse_duration(self._html_search_meta('duration', page)), | |
b8b01bb9 | 74 | 'formats': formats, |
5f6a1245 | 75 | } |