]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/newstube.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from ..aes
import aes_cbc_decrypt_bytes
, unpad_pkcs7
16 class NewstubeIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
19 'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
20 'md5': '9d10320ad473444352f72f746ccb8b8c',
22 'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
24 'title': 'Телеканал CNN переместил город Славянск в Крым',
25 'description': 'md5:419a8c9f03442bc0b0a794d689360335',
30 def _real_extract(self
, url
):
31 video_id
= self
._match
_id
(url
)
33 page
= self
._download
_webpage
(url
, video_id
)
34 title
= self
._html
_search
_meta
(['og:title', 'twitter:title'], page
, fatal
=True)
36 video_guid
= self
._html
_search
_regex
(
37 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})',
40 enc_data
= base64
.b64decode(self
._download
_webpage
(
41 'https://www.newstube.ru/embed/api/player/getsources2',
46 key
= hashlib
.pbkdf2_hmac(
47 'sha1', video_guid
.replace('-', '').encode(), enc_data
[:16], 1)[:16]
48 dec_data
= unpad_pkcs7(aes_cbc_decrypt_bytes(enc_data
[32:], key
, enc_data
[16:32]))
49 sources
= self
._parse
_json
(dec_data
, video_guid
)
52 for source
in sources
:
53 source_url
= source
.get('Src')
56 height
= int_or_none(source
.get('Height'))
58 'format_id': 'http' + ('-%dp' % height
if height
else ''),
60 'width': int_or_none(source
.get('Width')),
63 source_type
= source
.get('Type')
65 f
.update(parse_codecs(self
._search
_regex
(
66 r
'codecs="([^"]+)"', source_type
, 'codecs', fatal
=False)))
69 self
._check
_formats
(formats
, video_guid
)
70 self
._sort
_formats
(formats
)
75 'description': self
._html
_search
_meta
(['description', 'og:description'], page
),
76 'thumbnail': self
._html
_search
_meta
(['og:image:secure_url', 'og:image', 'twitter:image'], page
),
77 'duration': parse_duration(self
._html
_search
_meta
('duration', page
)),