]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/yapfiles.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / yapfiles.py
CommitLineData
4c780fbd 1from .common import InfoExtractor
4c780fbd
S
2from ..utils import (
3 ExtractorError,
4 int_or_none,
5 qualities,
3052a30d 6 url_or_none,
4c780fbd
S
7)
8
9
10class YapFilesIE(InfoExtractor):
df773c3d 11 _WORKING = False
4c780fbd 12 _YAPFILES_URL = r'//(?:(?:www|api)\.)?yapfiles\.ru/get_player/*\?.*?\bv=(?P<id>\w+)'
add96eb9 13 _VALID_URL = rf'https?:{_YAPFILES_URL}'
bfd973ec 14 _EMBED_REGEX = [rf'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?{_YAPFILES_URL}.*?)\1']
4c780fbd
S
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,
25 },
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,
30 }]
31
4c780fbd
S
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34
35 webpage = self._download_webpage(url, video_id, fatal=False)
36
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')
43
44 if not player_url:
add96eb9 45 player_url = f'http://api.yapfiles.ru/load/{video_id}/'
4c780fbd
S
46 query = {
47 'md5': 'ded5f369be61b8ae5f88e2eeb2f3caff',
48 'type': 'json',
49 'ref': url,
50 }
51
52 player = self._download_json(
53 player_url, video_id, query=query)['player']
54
55 playlist_url = player['playlist']
56 title = player['title']
57 thumbnail = player.get('poster')
58
59 if title == 'Ролик удален' or 'deleted.jpg' in (thumbnail or ''):
60 raise ExtractorError(
add96eb9 61 f'Video {video_id} has been removed', expected=True)
4c780fbd
S
62
63 playlist = self._download_json(
64 playlist_url, video_id)['player']['main']
65
66 hd_height = int_or_none(player.get('hd'))
67
68 QUALITIES = ('sd', 'hd')
69 quality_key = qualities(QUALITIES)
70 formats = []
71 for format_id in QUALITIES:
72 is_hd = format_id == 'hd'
3052a30d
S
73 format_url = url_or_none(playlist.get(
74 'file%s' % ('_hd' if is_hd else '')))
75 if not format_url:
4c780fbd
S
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,
82 })
4c780fbd
S
83
84 return {
85 'id': video_id,
86 'title': title,
87 'thumbnail': thumbnail,
88 'duration': int_or_none(player.get('length')),
89 'formats': formats,
90 }