]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vidly.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / vidly.py
CommitLineData
34df1c1f 1from .common import InfoExtractor
2from ..utils import (
3 ExtractorError,
4 mimetype2ext,
5 url_or_none,
6)
7from ..utils.traversal import traverse_obj
8
9
10class VidlyIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:vid\.ly/|(?:s\.)?vid\.ly/embeded\.html\?(?:[^#]+&)?link=)(?P<id>\w+)'
12 _EMBED_REGEX = [r'<script[^>]+\bsrc=[\'"](?P<url>(?:https?:)?//vid\.ly/\w+/embed[^\'"]+)',
13 r'<iframe[^>]+\bsrc=[\'"](?P<url>(?:https?:)?//(?:s\.)?vid\.ly/embeded\.html\?(?:[^#\'"]+&)?link=\w+[^\'"]+)']
14 _TESTS = [{
15 # JWPlayer 7, Embeds forbidden
16 'url': 'https://vid.ly/2i3o9j/embed',
17 'info_dict': {
18 'id': '2i3o9j',
19 'ext': 'mp4',
20 'title': '2i3o9j',
21 'thumbnail': r're:https://\w+\.cloudfront\.net/',
22 },
23 }, {
24 # JWPlayer 6
25 'url': 'http://s.vid.ly/embeded.html?link=jw_test&new=1&autoplay=true&controls=true',
26 'info_dict': {
27 'id': 'jw_test',
28 'ext': 'mp4',
29 'title': '2x8m8t',
30 'thumbnail': r're:https://\w+\.cloudfront\.net/',
31 },
32 }, {
33 # Vidlyplayer
34 'url': 'https://vid.ly/7x0e6l',
35 'info_dict': {
36 'id': '7x0e6l',
37 'ext': 'mp4',
38 'title': '7x0e6l',
39 },
40 }]
41 _WEBPAGE_TESTS = [{
42 'url': 'https://www.petfinder.com/dog/gus-57378930/tn/ooltewah/furever-furkids-rescue-tn592/',
43 'info_dict': {
44 'id': 'w8p5b0',
45 'ext': 'mp4',
46 'title': 'w8p5b0',
47 'thumbnail': r're:https://\w+\.cloudfront\.net/',
add96eb9 48 },
34df1c1f 49 }]
50
51 def _real_extract(self, url):
52 video_id = self._match_id(url)
53
54 embed_script = self._download_webpage(
55 f'https://vid.ly/{video_id}/embed', video_id, headers={'Referer': 'https://vid.ly/'})
56 player = self._search_json(r'initCallback\(', embed_script, 'player', video_id)
57
58 player_type = player.get('player') or ''
59 if player_type.startswith('jwplayer'):
60 return self._parse_jwplayer_data(player['config'], video_id)
61 elif not player_type.startswith('vidly'):
62 raise ExtractorError(f'Unknown player type {player_type!r}')
63
64 formats = []
65 ext = mimetype2ext(traverse_obj(player, ('config', 'type')))
66 for source, fid in [('source', 'sd'), ('source_hd', 'hd')]:
67 if traverse_obj(player, ('config', source, {url_or_none})):
68 formats.append({
69 'url': player['config'][source],
70 'format_id': f'http-{fid}',
71 'ext': ext,
72 })
73 # Has higher quality formats
74 formats.extend(self._extract_m3u8_formats(
75 f'https://d3fenhwk93s16g.cloudfront.net/{video_id}/hls.m3u8', video_id,
76 fatal=False, note='Requesting higher quality m3u8 formats',
77 errnote='No higher quality m3u8 formats found') or [])
78
79 return {
80 'id': video_id,
81 'title': video_id,
82 'formats': formats,
83 }