[vodlocker] Use `_form_hidden_inputs`
[youtube-dl] / youtube_dl / extractor / vodlocker.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..compat import (
8     compat_urllib_parse,
9     compat_urllib_request,
10 )
11
12
13 class VodlockerIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?vodlocker\.com/(?P<id>[0-9a-zA-Z]+)(?:\..*?)?'
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',
23             'thumbnail': 're:http://.*\.jpg',
24         },
25     }]
26
27     def _real_extract(self, url):
28         video_id = self._match_id(url)
29         webpage = self._download_webpage(url, video_id)
30
31         fields = self._form_hidden_inputs(webpage)
32
33         if fields['op'] == 'download1':
34             self._sleep(3, video_id)  # they do detect when requests happen too fast!
35             post = compat_urllib_parse.urlencode(fields)
36             req = compat_urllib_request.Request(url, post)
37             req.add_header('Content-type', 'application/x-www-form-urlencoded')
38             webpage = self._download_webpage(
39                 req, video_id, 'Downloading video page')
40
41         title = self._search_regex(
42             r'id="file_title".*?>\s*(.*?)\s*<(?:br|span)', webpage, 'title')
43         thumbnail = self._search_regex(
44             r'image:\s*"(http[^\"]+)",', webpage, 'thumbnail')
45         url = self._search_regex(
46             r'file:\s*"(http[^\"]+)",', webpage, 'file url')
47
48         formats = [{
49             'format_id': 'sd',
50             'url': url,
51         }]
52
53         return {
54             'id': video_id,
55             'title': title,
56             'thumbnail': thumbnail,
57             'formats': formats,
58         }