]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vodlocker.py
a97995a6dfd92383c2d25ea7250142404176ecad
[youtubedl] / 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 NO_DEFAULT,
9 sanitized_Request,
10 )
11
12
13 class VodlockerIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?vodlocker\.(?:com|city)/(?:embed-)?(?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 if any(p in webpage for p in (
32 '>THIS FILE WAS DELETED<',
33 '>File Not Found<',
34 'The file you were looking for could not be found, sorry for any inconvenience.<')):
35 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
36
37 fields = self._hidden_inputs(webpage)
38
39 if fields['op'] == 'download1':
40 self._sleep(3, video_id) # they do detect when requests happen too fast!
41 post = compat_urllib_parse.urlencode(fields)
42 req = sanitized_Request(url, post)
43 req.add_header('Content-type', 'application/x-www-form-urlencoded')
44 webpage = self._download_webpage(
45 req, video_id, 'Downloading video page')
46
47 def extract_file_url(html, default=NO_DEFAULT):
48 return self._search_regex(
49 r'file:\s*"(http[^\"]+)",', html, 'file url', default=default)
50
51 video_url = extract_file_url(webpage, default=None)
52
53 if not video_url:
54 embed_url = self._search_regex(
55 r'<iframe[^>]+src=(["\'])(?P<url>(?:https?://)?vodlocker\.(?:com|city)/embed-.+?)\1',
56 webpage, 'embed url', group='url')
57 embed_webpage = self._download_webpage(
58 embed_url, video_id, 'Downloading embed webpage')
59 video_url = extract_file_url(embed_webpage)
60 thumbnail_webpage = embed_webpage
61 else:
62 thumbnail_webpage = webpage
63
64 title = self._search_regex(
65 r'id="file_title".*?>\s*(.*?)\s*<(?:br|span)', webpage, 'title')
66 thumbnail = self._search_regex(
67 r'image:\s*"(http[^\"]+)",', thumbnail_webpage, 'thumbnail', fatal=False)
68
69 formats = [{
70 'format_id': 'sd',
71 'url': video_url,
72 }]
73
74 return {
75 'id': video_id,
76 'title': title,
77 'thumbnail': thumbnail,
78 'formats': formats,
79 }