]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/yapfiles.py
[extractors] Use new framework for existing embeds (#4307)
[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):
11 _YAPFILES_URL = r'//(?:(?:www|api)\.)?yapfiles\.ru/get_player/*\?.*?\bv=(?P<id>\w+)'
12 _VALID_URL = r'https?:%s' % _YAPFILES_URL
bfd973ec 13 _EMBED_REGEX = [rf'<iframe\b[^>]+\bsrc=(["\'])(?P<url>(?:https?:)?{_YAPFILES_URL}.*?)\1']
4c780fbd
S
14 _TESTS = [{
15 # with hd
16 'url': 'http://www.yapfiles.ru/get_player/?v=vMDE1NjcyNDUt0413',
17 'md5': '2db19e2bfa2450568868548a1aa1956c',
18 'info_dict': {
19 'id': 'vMDE1NjcyNDUt0413',
20 'ext': 'mp4',
21 'title': 'Самый худший пароль WIFI',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'duration': 72,
24 },
25 }, {
26 # without hd
27 'url': 'https://api.yapfiles.ru/get_player/?uid=video_player_1872528&plroll=1&adv=1&v=vMDE4NzI1Mjgt690b',
28 'only_matching': True,
29 }]
30
4c780fbd
S
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33
34 webpage = self._download_webpage(url, video_id, fatal=False)
35
36 player_url = None
37 query = {}
38 if webpage:
39 player_url = self._search_regex(
40 r'player\.init\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
41 'player url', default=None, group='url')
42
43 if not player_url:
44 player_url = 'http://api.yapfiles.ru/load/%s/' % video_id
45 query = {
46 'md5': 'ded5f369be61b8ae5f88e2eeb2f3caff',
47 'type': 'json',
48 'ref': url,
49 }
50
51 player = self._download_json(
52 player_url, video_id, query=query)['player']
53
54 playlist_url = player['playlist']
55 title = player['title']
56 thumbnail = player.get('poster')
57
58 if title == 'Ролик удален' or 'deleted.jpg' in (thumbnail or ''):
59 raise ExtractorError(
60 'Video %s has been removed' % video_id, expected=True)
61
62 playlist = self._download_json(
63 playlist_url, video_id)['player']['main']
64
65 hd_height = int_or_none(player.get('hd'))
66
67 QUALITIES = ('sd', 'hd')
68 quality_key = qualities(QUALITIES)
69 formats = []
70 for format_id in QUALITIES:
71 is_hd = format_id == 'hd'
3052a30d
S
72 format_url = url_or_none(playlist.get(
73 'file%s' % ('_hd' if is_hd else '')))
74 if not format_url:
4c780fbd
S
75 continue
76 formats.append({
77 'url': format_url,
78 'format_id': format_id,
79 'quality': quality_key(format_id),
80 'height': hd_height if is_hd else None,
81 })
82 self._sort_formats(formats)
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 }