Merge remote-tracking branch 'Boris-de/wdrmaus_fix#8562'
[youtube-dl] / youtube_dl / extractor / xfileshare.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9     int_or_none,
10     sanitized_Request,
11     urlencode_postdata,
12 )
13
14
15 class XFileShareIE(InfoExtractor):
16     _SITES = (
17         ('daclips.in', 'DaClips'),
18         ('filehoot.com', 'FileHoot'),
19         ('gorillavid.in', 'GorillaVid'),
20         ('movpod.in', 'MovPod'),
21         ('powerwatch.pw', 'PowerWatch'),
22         ('rapidvideo.ws', 'Rapidvideo.ws'),
23         ('thevideobee.to', 'TheVideoBee'),
24         ('vidto.me', 'Vidto'),
25         ('streamin.to', 'Streamin.To'),
26     )
27
28     IE_DESC = 'XFileShare based sites: %s' % ', '.join(list(zip(*_SITES))[1])
29     _VALID_URL = (r'https?://(?P<host>(?:www\.)?(?:%s))/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
30                   % '|'.join(re.escape(site) for site in list(zip(*_SITES))[0]))
31
32     _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
33
34     _TESTS = [{
35         'url': 'http://gorillavid.in/06y9juieqpmi',
36         'md5': '5ae4a3580620380619678ee4875893ba',
37         'info_dict': {
38             'id': '06y9juieqpmi',
39             'ext': 'flv',
40             'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
41             'thumbnail': 're:http://.*\.jpg',
42         },
43     }, {
44         'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
45         'only_matching': True,
46     }, {
47         'url': 'http://daclips.in/3rso4kdn6f9m',
48         'md5': '1ad8fd39bb976eeb66004d3a4895f106',
49         'info_dict': {
50             'id': '3rso4kdn6f9m',
51             'ext': 'mp4',
52             'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
53             'thumbnail': 're:http://.*\.jpg',
54         }
55     }, {
56         'url': 'http://movpod.in/0wguyyxi1yca',
57         'only_matching': True,
58     }, {
59         'url': 'http://filehoot.com/3ivfabn7573c.html',
60         'info_dict': {
61             'id': '3ivfabn7573c',
62             'ext': 'mp4',
63             'title': 'youtube-dl test video \'äBaW_jenozKc.mp4.mp4',
64             'thumbnail': 're:http://.*\.jpg',
65         }
66     }, {
67         'url': 'http://vidto.me/ku5glz52nqe1.html',
68         'info_dict': {
69             'id': 'ku5glz52nqe1',
70             'ext': 'mp4',
71             'title': 'test'
72         }
73     }, {
74         'url': 'http://powerwatch.pw/duecjibvicbu',
75         'info_dict': {
76             'id': 'duecjibvicbu',
77             'ext': 'mp4',
78             'title': 'Big Buck Bunny trailer',
79         },
80     }]
81
82     def _real_extract(self, url):
83         mobj = re.match(self._VALID_URL, url)
84         video_id = mobj.group('id')
85
86         url = 'http://%s/%s' % (mobj.group('host'), video_id)
87         webpage = self._download_webpage(url, video_id)
88
89         if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
90             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
91
92         fields = self._hidden_inputs(webpage)
93
94         if fields['op'] == 'download1':
95             countdown = int_or_none(self._search_regex(
96                 r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
97                 webpage, 'countdown', default=None))
98             if countdown:
99                 self._sleep(countdown, video_id)
100
101             post = urlencode_postdata(fields)
102
103             req = sanitized_Request(url, post)
104             req.add_header('Content-type', 'application/x-www-form-urlencoded')
105
106             webpage = self._download_webpage(req, video_id, 'Downloading video page')
107
108         title = (self._search_regex(
109             [r'style="z-index: [0-9]+;">([^<]+)</span>',
110              r'<td nowrap>([^<]+)</td>',
111              r'h4-fine[^>]*>([^<]+)<',
112              r'>Watch (.+) ',
113              r'<h2 class="video-page-head">([^<]+)</h2>'],
114             webpage, 'title', default=None) or self._og_search_title(webpage)).strip()
115         video_url = self._search_regex(
116             [r'file\s*:\s*["\'](http[^"\']+)["\'],',
117              r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)'],
118             webpage, 'file url')
119         thumbnail = self._search_regex(
120             r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', default=None)
121
122         formats = [{
123             'format_id': 'sd',
124             'url': video_url,
125             'quality': 1,
126         }]
127
128         return {
129             'id': video_id,
130             'title': title,
131             'thumbnail': thumbnail,
132             'formats': formats,
133         }