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