[ZenYandex] Fix extractor (#1558)

Closes #1545
Authored by: u-spec-png
pull/1214/head^2
u-spec-png 3 years ago committed by GitHub
parent a49891c761
commit a109acbf82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
extract_attributes,
int_or_none, int_or_none,
try_get, try_get,
url_or_none, url_or_none,
@ -148,7 +149,7 @@ class YandexVideoIE(InfoExtractor):
class ZenYandexIE(InfoExtractor): class ZenYandexIE(InfoExtractor):
_VALID_URL = r'https?://zen\.yandex\.ru/media/(?:id/[^/]+/|[^/]+/)(?:[a-z0-9-]+)-(?P<id>[a-z0-9-]+)' _VALID_URL = r'https?://zen\.yandex\.ru(?:/video)?/(media|watch)/(?:(?:id/[^/]+/|[^/]+/)(?:[a-z0-9-]+)-)?(?P<id>[a-z0-9-]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://zen.yandex.ru/media/popmech/izverjenie-vulkana-iz-spichek-zreliscnyi-opyt-6002240ff8b1af50bb2da5e3', 'url': 'https://zen.yandex.ru/media/popmech/izverjenie-vulkana-iz-spichek-zreliscnyi-opyt-6002240ff8b1af50bb2da5e3',
'info_dict': { 'info_dict': {
@ -156,19 +157,38 @@ class ZenYandexIE(InfoExtractor):
'ext': 'mp4', 'ext': 'mp4',
'title': 'Извержение вулкана из спичек: зрелищный опыт', 'title': 'Извержение вулкана из спичек: зрелищный опыт',
'description': 'md5:053ad3c61b5596d510c9a199dc8ee633', 'description': 'md5:053ad3c61b5596d510c9a199dc8ee633',
'thumbnail': 'https://avatars.mds.yandex.net/get-zen-pub-og/3558619/pub_6002240ff8b1af50bb2da5e3_600bad814d953e4132a30b5e/orig', 'thumbnail': 're:^https://avatars.mds.yandex.net/',
'uploader': 'Популярная механика', 'uploader': 'Популярная механика',
}, },
'params': {
'skip_download': 'm3u8',
},
}, { }, {
'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/vot-eto-focus-dedy-morozy-na-gidrociklah-60c7c443da18892ebfe85ed7', 'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/vot-eto-focus-dedy-morozy-na-gidrociklah-60c7c443da18892ebfe85ed7',
'info_dict': { 'info_dict': {
'id': '60c7c443da18892ebfe85ed7', 'id': '60c7c443da18892ebfe85ed7',
'ext': 'mp4', 'ext': 'mp4',
'title': 'ВОТ ЭТО Focus. Деды Морозы на гидроциклах', 'title': 'ВОТ ЭТО Focus. Деды Морозы на гидроциклах',
'description': 'md5:8684912f6086f298f8078d4af0e8a600', 'description': 'md5:f3db3d995763b9bbb7b56d4ccdedea89',
'thumbnail': 'https://avatars.mds.yandex.net/get-zen-pub-og/4410519/pub_60c7c443da18892ebfe85ed7_60c7c48e060a163121f42cc3/orig', 'thumbnail': 're:^https://avatars.mds.yandex.net/',
'uploader': 'AcademeG DailyStream' 'uploader': 'AcademeG DailyStream'
}, },
'params': {
'skip_download': 'm3u8',
'format': 'bestvideo',
},
}, {
'url': 'https://zen.yandex.ru/video/watch/6002240ff8b1af50bb2da5e3',
'info_dict': {
'id': '6002240ff8b1af50bb2da5e3',
'ext': 'mp4',
'title': 'Извержение вулкана из спичек: зрелищный опыт',
'description': 'md5:053ad3c61b5596d510c9a199dc8ee633',
'uploader': 'Популярная механика',
},
'params': {
'skip_download': 'm3u8',
},
}, { }, {
'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360', 'url': 'https://zen.yandex.ru/media/id/606fd806cc13cb3c58c05cf5/novyi-samsung-fold-3-moskvich-barahlit-612f93b7f8d48e7e945792a2?from=channel&rid=2286618386.482.1630817595976.42360',
'only_matching': True, 'only_matching': True,
@ -177,23 +197,37 @@ class ZenYandexIE(InfoExtractor):
def _real_extract(self, url): def _real_extract(self, url):
id = self._match_id(url) id = self._match_id(url)
webpage = self._download_webpage(url, id) webpage = self._download_webpage(url, id)
data_json = self._parse_json(self._search_regex(r'w\._data\s?=\s?({.+?});', webpage, 'metadata'), id) data_json = self._parse_json(
stream_json = try_get(data_json, lambda x: x['publication']['content']['gifContent'], dict) self._search_regex(r'data\s*=\s*({["\']_*serverState_*video.+?});', webpage, 'metadata'), id)
stream_url = stream_json.get('stream') or try_get(stream_json, lambda x: x['streams']['url']) serverstate = self._search_regex(r'(_+serverState_+video-site_[^_]+_+)',
formats = self._extract_m3u8_formats(stream_url, id) webpage, 'server state').replace('State', 'Settings')
uploader = self._search_regex(r'(<a\s*class=["\']card-channel-link[^"\']+["\'][^>]+>)',
webpage, 'uploader', default='<a>')
uploader_name = extract_attributes(uploader).get('aria-label')
video_json = try_get(data_json, lambda x: x[serverstate]['exportData']['video'], dict)
stream_urls = try_get(video_json, lambda x: x['video']['streams'])
formats = []
for s_url in stream_urls:
ext = determine_ext(s_url)
if ext == 'mpd':
formats.extend(self._extract_mpd_formats(s_url, id, mpd_id='dash'))
elif ext == 'm3u8':
formats.extend(self._extract_m3u8_formats(s_url, id, 'mp4'))
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': id, 'id': id,
'title': try_get(data_json, (lambda x: x['og']['title'], lambda x: x['publication']['content']['preview']['title'])), 'title': video_json.get('title') or self._og_search_title(webpage),
'uploader': data_json.get('authorName') or try_get(data_json, lambda x: x['publisher']['name']),
'description': try_get(data_json, lambda x: x['og']['description']),
'thumbnail': try_get(data_json, lambda x: x['og']['imageUrl']),
'formats': formats, 'formats': formats,
'duration': int_or_none(video_json.get('duration')),
'view_count': int_or_none(video_json.get('views')),
'uploader': uploader_name or data_json.get('authorName') or try_get(data_json, lambda x: x['publisher']['name']),
'description': self._og_search_description(webpage) or try_get(data_json, lambda x: x['og']['description']),
'thumbnail': self._og_search_thumbnail(webpage) or try_get(data_json, lambda x: x['og']['imageUrl']),
} }
class ZenYandexChannelIE(InfoExtractor): class ZenYandexChannelIE(InfoExtractor):
_VALID_URL = r'https?://zen\.yandex\.ru/(?!media)(?:id/)?(?P<id>[a-z0-9-_]+)' _VALID_URL = r'https?://zen\.yandex\.ru/(?!media|video)(?:id/)?(?P<id>[a-z0-9-_]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://zen.yandex.ru/tok_media', 'url': 'https://zen.yandex.ru/tok_media',
'info_dict': { 'info_dict': {

Loading…
Cancel
Save