Merge pull request #7322 from remitamine/vgtv
[youtube-dl] / youtube_dl / extractor / vodlocker.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..compat import compat_urllib_parse
6 from ..utils import (
7     ExtractorError,
8     sanitized_Request,
9 )
10
11
12 class VodlockerIE(InfoExtractor):
13     _VALID_URL = r'https?://(?:www\.)?vodlocker\.com/(?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:\..*?)?'
14
15     _TESTS = [{
16         'url': 'http://vodlocker.com/e8wvyzz4sl42',
17         'md5': 'ce0c2d18fa0735f1bd91b69b0e54aacf',
18         'info_dict': {
19             'id': 'e8wvyzz4sl42',
20             'ext': 'mp4',
21             'title': 'Germany vs Brazil',
22             'thumbnail': 're:http://.*\.jpg',
23         },
24     }]
25
26     def _real_extract(self, url):
27         video_id = self._match_id(url)
28         webpage = self._download_webpage(url, video_id)
29
30         if any(p in webpage for p in (
31                 '>THIS FILE WAS DELETED<',
32                 '>File Not Found<',
33                 'The file you were looking for could not be found, sorry for any inconvenience.<')):
34             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
35
36         fields = self._hidden_inputs(webpage)
37
38         if fields['op'] == 'download1':
39             self._sleep(3, video_id)  # they do detect when requests happen too fast!
40             post = compat_urllib_parse.urlencode(fields)
41             req = sanitized_Request(url, post)
42             req.add_header('Content-type', 'application/x-www-form-urlencoded')
43             webpage = self._download_webpage(
44                 req, video_id, 'Downloading video page')
45
46         title = self._search_regex(
47             r'id="file_title".*?>\s*(.*?)\s*<(?:br|span)', webpage, 'title')
48         thumbnail = self._search_regex(
49             r'image:\s*"(http[^\"]+)",', webpage, 'thumbnail')
50         url = self._search_regex(
51             r'file:\s*"(http[^\"]+)",', webpage, 'file url')
52
53         formats = [{
54             'format_id': 'sd',
55             'url': url,
56         }]
57
58         return {
59             'id': video_id,
60             'title': title,
61             'thumbnail': thumbnail,
62             'formats': formats,
63         }