]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vodlocker.py
[ie/box] Fix formats extraction (#8649)
[yt-dlp.git] / yt_dlp / extractor / vodlocker.py
CommitLineData
537ba6f3 1from .common import InfoExtractor
3d2623a8 2from ..networking import Request
3from ..utils import NO_DEFAULT, ExtractorError, urlencode_postdata
537ba6f3 4
5
6class VodlockerIE(InfoExtractor):
fbd90643 7 _VALID_URL = r'https?://(?:www\.)?vodlocker\.(?:com|city)/(?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:\..*?)?'
537ba6f3 8
9 _TESTS = [{
10 'url': 'http://vodlocker.com/e8wvyzz4sl42',
11 'md5': 'ce0c2d18fa0735f1bd91b69b0e54aacf',
12 'info_dict': {
13 'id': 'e8wvyzz4sl42',
14 'ext': 'mp4',
15 'title': 'Germany vs Brazil',
ec85ded8 16 'thumbnail': r're:http://.*\.jpg',
537ba6f3 17 },
18 }]
19
20 def _real_extract(self, url):
1cc79574 21 video_id = self._match_id(url)
537ba6f3 22 webpage = self._download_webpage(url, video_id)
23
af284305
S
24 if any(p in webpage for p in (
25 '>THIS FILE WAS DELETED<',
26 '>File Not Found<',
32f2627a
S
27 'The file you were looking for could not be found, sorry for any inconvenience.<',
28 '>The file was removed')):
af284305
S
29 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
30
f8da79f8 31 fields = self._hidden_inputs(webpage)
537ba6f3 32
33 if fields['op'] == 'download1':
4094b6e3 34 self._sleep(3, video_id) # they do detect when requests happen too fast!
6e6bc8da 35 post = urlencode_postdata(fields)
3d2623a8 36 req = Request(url, post)
37 req.headers['Content-type'] = 'application/x-www-form-urlencoded'
4094b6e3
PH
38 webpage = self._download_webpage(
39 req, video_id, 'Downloading video page')
537ba6f3 40
fbd90643
S
41 def extract_file_url(html, default=NO_DEFAULT):
42 return self._search_regex(
43 r'file:\s*"(http[^\"]+)",', html, 'file url', default=default)
44
45 video_url = extract_file_url(webpage, default=None)
46
47 if not video_url:
48 embed_url = self._search_regex(
49 r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?vodlocker\.(?:com|city)/embed-.+?)\1',
50 webpage, 'embed url', group='url')
51 embed_webpage = self._download_webpage(
52 embed_url, video_id, 'Downloading embed webpage')
53 video_url = extract_file_url(embed_webpage)
54 thumbnail_webpage = embed_webpage
55 else:
56 thumbnail_webpage = webpage
57
4094b6e3 58 title = self._search_regex(
b7b04c92 59 r'id="file_title".*?>\s*(.*?)\s*<(?:br|span)', webpage, 'title')
4094b6e3 60 thumbnail = self._search_regex(
fbd90643 61 r'image:\s*"(http[^\"]+)",', thumbnail_webpage, 'thumbnail', fatal=False)
537ba6f3 62
63 formats = [{
64 'format_id': 'sd',
fbd90643 65 'url': video_url,
537ba6f3 66 }]
67
68 return {
69 'id': video_id,
70 'title': title,
71 'thumbnail': thumbnail,
72 'formats': formats,
73 }