1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-27 00:37:55 +01:00
youtube-dl/youtube_dl/extractor/newstube.py

84 lines
3.0 KiB
Python
Raw Normal View History

2016-10-02 13:39:18 +02:00
# coding: utf-8
from __future__ import unicode_literals
2019-04-03 11:19:36 +02:00
import base64
import hashlib
from .common import InfoExtractor
2019-04-03 11:19:36 +02:00
from ..aes import aes_cbc_decrypt
from ..utils import (
2019-04-03 11:19:36 +02:00
bytes_to_intlist,
int_or_none,
2019-04-03 11:19:36 +02:00
intlist_to_bytes,
parse_codecs,
parse_duration,
)
class NewstubeIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
_TEST = {
2014-07-06 14:32:13 +02:00
'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
2019-04-03 11:19:36 +02:00
'md5': '9d10320ad473444352f72f746ccb8b8c',
'info_dict': {
2014-07-06 14:32:13 +02:00
'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
'ext': 'mp4',
2014-07-06 14:32:13 +02:00
'title': 'Телеканал CNN переместил город Славянск в Крым',
'description': 'md5:419a8c9f03442bc0b0a794d689360335',
'duration': 31.05,
},
}
def _real_extract(self, url):
2019-04-03 11:19:36 +02:00
video_id = self._match_id(url)
2019-04-03 11:19:36 +02: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 11:19:36 +02: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 11:19:36 +02: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]
dec_data = aes_cbc_decrypt(
bytes_to_intlist(enc_data[32:]), bytes_to_intlist(key),
bytes_to_intlist(enc_data[16:32]))
sources = self._parse_json(intlist_to_bytes(dec_data[:-dec_data[-1]]), video_guid)
formats = []
2019-04-03 11:19:36 +02:00
for source in sources:
source_url = source.get('Src')
if not source_url:
continue
2019-04-03 11:19:36 +02: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 11:19:36 +02: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 11:19:36 +02: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 20:41:03 +01:00
}