[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / yapfiles.py
blob8d89d1d109f78c2e9527e8627ea4033a02449ce2
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 int_or_none,
5 qualities,
6 url_or_none,
10 class YapFilesIE(InfoExtractor):
11 _WORKING = False
12 _YAPFILES_URL = r'//(?:(?:www|api)\.)?yapfiles\.ru/get_player/*\?.*?\bv=(?P<id>\w+)'
13 _VALID_URL = rf'https?:{_YAPFILES_URL}'
14 _EMBED_REGEX = [rf'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?{_YAPFILES_URL}.*?)\1']
15 _TESTS = [{
16 # with hd
17 'url': 'http://www.yapfiles.ru/get_player/?v=vMDE1NjcyNDUt0413',
18 'md5': '2db19e2bfa2450568868548a1aa1956c',
19 'info_dict': {
20 'id': 'vMDE1NjcyNDUt0413',
21 'ext': 'mp4',
22 'title': 'Самый худший пароль WIFI',
23 'thumbnail': r're:^https?://.*\.jpg$',
24 'duration': 72,
26 }, {
27 # without hd
28 'url': 'https://api.yapfiles.ru/get_player/?uid=video_player_1872528&plroll=1&adv=1&v=vMDE4NzI1Mjgt690b',
29 'only_matching': True,
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
35 webpage = self._download_webpage(url, video_id, fatal=False)
37 player_url = None
38 query = {}
39 if webpage:
40 player_url = self._search_regex(
41 r'player\.init\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
42 'player url', default=None, group='url')
44 if not player_url:
45 player_url = f'http://api.yapfiles.ru/load/{video_id}/'
46 query = {
47 'md5': 'ded5f369be61b8ae5f88e2eeb2f3caff',
48 'type': 'json',
49 'ref': url,
52 player = self._download_json(
53 player_url, video_id, query=query)['player']
55 playlist_url = player['playlist']
56 title = player['title']
57 thumbnail = player.get('poster')
59 if title == 'Ролик удален' or 'deleted.jpg' in (thumbnail or ''):
60 raise ExtractorError(
61 f'Video {video_id} has been removed', expected=True)
63 playlist = self._download_json(
64 playlist_url, video_id)['player']['main']
66 hd_height = int_or_none(player.get('hd'))
68 QUALITIES = ('sd', 'hd')
69 quality_key = qualities(QUALITIES)
70 formats = []
71 for format_id in QUALITIES:
72 is_hd = format_id == 'hd'
73 format_url = url_or_none(playlist.get(
74 'file%s' % ('_hd' if is_hd else '')))
75 if not format_url:
76 continue
77 formats.append({
78 'url': format_url,
79 'format_id': format_id,
80 'quality': quality_key(format_id),
81 'height': hd_height if is_hd else None,
84 return {
85 'id': video_id,
86 'title': title,
87 'thumbnail': thumbnail,
88 'duration': int_or_none(player.get('length')),
89 'formats': formats,