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