0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-27 03:03:01 +00:00
yt-dlp/yt_dlp/extractor/newstube.py

80 lines
2.9 KiB
Python
Raw Normal View History

2016-10-02 11:39:18 +00:00
# coding: utf-8
from __future__ import unicode_literals
2019-04-03 09:19:36 +00:00
import base64
import hashlib
from .common import InfoExtractor
2022-01-31 14:49:33 +00:00
from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
from ..utils import (
int_or_none,
2019-04-03 09:19:36 +00:00
parse_codecs,
parse_duration,
)
class NewstubeIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
_TEST = {
2014-07-06 12:32:13 +00:00
'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
2019-04-03 09:19:36 +00:00
'md5': '9d10320ad473444352f72f746ccb8b8c',
'info_dict': {
2014-07-06 12:32:13 +00:00
'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
'ext': 'mp4',
2014-07-06 12:32:13 +00:00
'title': 'Телеканал CNN переместил город Славянск в Крым',
'description': 'md5:419a8c9f03442bc0b0a794d689360335',
'duration': 31.05,
},
}
def _real_extract(self, url):
2019-04-03 09:19:36 +00:00
video_id = self._match_id(url)
2019-04-03 09:19:36 +00:00
page = self._download_webpage(url, video_id)
title = self._html_search_meta(['og:title', 'twitter:title'], page, fatal=True)
video_guid = self._html_search_regex(
2019-04-03 09:19:36 +00:00
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})',
page, 'video GUID')
2019-04-03 09:19:36 +00:00
enc_data = base64.b64decode(self._download_webpage(
'https://www.newstube.ru/embed/api/player/getsources2',
video_guid, query={
'guid': video_guid,
'ff': 3,
}))
key = hashlib.pbkdf2_hmac(
'sha1', video_guid.replace('-', '').encode(), enc_data[:16], 1)[:16]
2022-01-31 14:49:33 +00:00
dec_data = unpad_pkcs7(aes_cbc_decrypt_bytes(enc_data[32:], key, enc_data[16:32]))
sources = self._parse_json(dec_data, video_guid)
formats = []
2019-04-03 09:19:36 +00:00
for source in sources:
source_url = source.get('Src')
if not source_url:
continue
2019-04-03 09:19:36 +00:00
height = int_or_none(source.get('Height'))
f = {
'format_id': 'http' + ('-%dp' % height if height else ''),
'url': source_url,
'width': int_or_none(source.get('Width')),
'height': height,
2019-04-03 09:19:36 +00:00
}
source_type = source.get('Type')
if source_type:
f.update(parse_codecs(self._search_regex(
r'codecs="([^"]+)"', source_type, 'codecs', fatal=False)))
formats.append(f)
self._check_formats(formats, video_guid)
self._sort_formats(formats)
return {
'id': video_guid,
'title': title,
2019-04-03 09:19:36 +00:00
'description': self._html_search_meta(['description', 'og:description'], page),
'thumbnail': self._html_search_meta(['og:image:secure_url', 'og:image', 'twitter:image'], page),
'duration': parse_duration(self._html_search_meta('duration', page)),
'formats': formats,
2014-11-23 19:41:03 +00:00
}