Skip to content

Commit e26f9cc

Browse files
[YandexVideoPreview] Add extractor (yt-dlp#2500)
Closes yt-dlp#1794 Authored by: KiberInfinity
1 parent fa8fd95 commit e26f9cc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

yt_dlp/extractor/extractors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,7 @@
19851985
)
19861986
from .yandexvideo import (
19871987
YandexVideoIE,
1988+
YandexVideoPreviewIE,
19881989
ZenYandexIE,
19891990
ZenYandexChannelIE,
19901991
)

yt_dlp/extractor/yandexvideo.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
int_or_none,
1212
try_get,
1313
url_or_none,
14+
lowercase_escape,
1415
)
1516

1617

@@ -148,6 +149,45 @@ def _real_extract(self, url):
148149
}
149150

150151

152+
class YandexVideoPreviewIE(InfoExtractor):
153+
_VALID_URL = r'https?://(?:www\.)?yandex\.ru/video/preview(?:/?\?.*?filmId=|/)(?P<id>\d+)'
154+
_TESTS = [{ # Odnoklassniki
155+
'url': 'https://yandex.ru/video/preview/?filmId=10682852472978372885&text=summer',
156+
'info_dict': {
157+
'id': '1352565459459',
158+
'ext': 'mp4',
159+
'like_count': int,
160+
'upload_date': '20191202',
161+
'age_limit': 0,
162+
'duration': 196,
163+
'thumbnail': 'https://i.mycdn.me/videoPreview?id=544866765315&type=37&idx=13&tkn=TY5qjLYZHxpmcnK8U2LgzYkgmaU&fn=external_8',
164+
'uploader_id': '481054701571',
165+
'title': 'LOFT - summer, summer, summer HD',
166+
'manifest_stream_number': 0,
167+
'uploader': 'АРТЁМ КУДРОВ',
168+
},
169+
}, { # youtube
170+
'url': 'https://yandex.ru/video/preview/?filmId=4479424425337895262&source=main_redirect&text=видео&utm_source=main_stripe_big',
171+
'only_matching': True,
172+
}, { # YandexVideo
173+
'url': 'https://yandex.ru/video/preview/5275069442094787341',
174+
'only_matching': True,
175+
}, { # youtube
176+
'url': 'https://yandex.ru/video/preview/?filmId=16658118429797832897&from=tabbar&p=1&text=%D0%BF%D1%80%D0%BE%D1%81%D0%BC%D0%BE%D1%82%D1%80+%D1%84%D1%80%D0%B0%D0%B3%D0%BC%D0%B5%D0%BD%D1%82%D0%B0+%D0%BC%D0%B0%D0%BB%D0%B5%D0%BD%D1%8C%D0%BA%D0%B8%D0%B9+%D0%BF%D1%80%D0%B8%D0%BD%D1%86+%D0%BC%D1%8B+%D0%B2+%D0%BE%D1%82%D0%B2%D0%B5%D1%82%D0%B5+%D0%B7%D0%B0+%D1%82%D0%B5%D1%85+%D0%BA%D0%BE%D0%B3%D0%BE+%D0%BF%D1%80%D0%B8%D1%80%D1%83%D1%87%D0%B8%D0%BB%D0%B8',
177+
'only_matching': True,
178+
}, { # Odnoklassniki
179+
'url': 'https://yandex.ru/video/preview/?text=Francis%20Lai%20-%20Le%20Bon%20Et%20Les%20MC)chants&path=wizard&parent-reqid=1643208087979310-1481782809207673478-sas3-0931-2f9-sas-l7-balancer-8080-BAL-9380&wiz_type=vital&filmId=12508152936505397283',
180+
'only_matching': True,
181+
}]
182+
183+
def _real_extract(self, url):
184+
id = self._match_id(url)
185+
webpage = self._download_webpage(url, id)
186+
data_raw = self._search_regex(r'window.Ya.__inline_params__\s*=\s*JSON.parse\(\'([^"]+?\\u0022video\\u0022:[^"]+?})\'\);', webpage, 'data_raw')
187+
data_json = self._parse_json(data_raw, id, transform_source=lowercase_escape)
188+
return self.url_result(data_json['video']['url'])
189+
190+
151191
class ZenYandexIE(InfoExtractor):
152192
_VALID_URL = r'https?://zen\.yandex\.ru(?:/video)?/(media|watch)/(?:(?:id/[^/]+/|[^/]+/)(?:[a-z0-9-]+)-)?(?P<id>[a-z0-9-]+)'
153193
_TESTS = [{

0 commit comments

Comments
 (0)