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