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