952515c9819406bf9cf0f744d8645eb0c28c77c4
[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 ..compat import (
8     compat_urllib_parse,
9     compat_urllib_request,
10 )
11 from ..utils import (
12     ExtractorError,
13     encode_dict,
14     int_or_none,
15 )
16
17
18 class XFileShareIE(InfoExtractor):
19     IE_DESC = 'XFileShare based sites: GorillaVid.in, daclips.in, movpod.in, fastvideo.in, realvid.net, filehoot.com and vidto.me'
20     _VALID_URL = r'''(?x)
21         https?://(?P<host>(?:www\.)?
22             (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in|realvid\.net|filehoot\.com|vidto\.me))/
23         (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
24     '''
25
26     _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
27
28     _TESTS = [{
29         'url': 'http://gorillavid.in/06y9juieqpmi',
30         'md5': '5ae4a3580620380619678ee4875893ba',
31         'info_dict': {
32             'id': '06y9juieqpmi',
33             'ext': 'flv',
34             'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
35             'thumbnail': 're:http://.*\.jpg',
36         },
37     }, {
38         'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
39         'only_matching': True,
40     }, {
41         'url': 'http://daclips.in/3rso4kdn6f9m',
42         'md5': '1ad8fd39bb976eeb66004d3a4895f106',
43         'info_dict': {
44             'id': '3rso4kdn6f9m',
45             'ext': 'mp4',
46             'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
47             'thumbnail': 're:http://.*\.jpg',
48         }
49     }, {
50         # video with countdown timeout
51         'url': 'http://fastvideo.in/1qmdn1lmsmbw',
52         'md5': '8b87ec3f6564a3108a0e8e66594842ba',
53         'info_dict': {
54             'id': '1qmdn1lmsmbw',
55             'ext': 'mp4',
56             'title': 'Man of Steel - Trailer',
57             'thumbnail': 're:http://.*\.jpg',
58         },
59     }, {
60         'url': 'http://realvid.net/ctn2y6p2eviw',
61         'md5': 'b2166d2cf192efd6b6d764c18fd3710e',
62         'info_dict': {
63             'id': 'ctn2y6p2eviw',
64             'ext': 'flv',
65             'title': 'rdx 1955',
66             'thumbnail': 're:http://.*\.jpg',
67         },
68     }, {
69         'url': 'http://movpod.in/0wguyyxi1yca',
70         'only_matching': True,
71     }, {
72         'url': 'http://filehoot.com/3ivfabn7573c.html',
73         'info_dict': {
74             'id': '3ivfabn7573c',
75             'ext': 'mp4',
76             'title': 'youtube-dl test video \'äBaW_jenozKc.mp4.mp4',
77             'thumbnail': 're:http://.*\.jpg',
78         }
79     }, {
80         'url': 'http://vidto.me/ku5glz52nqe1.html',
81         'info_dict': {
82             'id': 'ku5glz52nqe1',
83             'ext': 'mp4',
84             'title': 'test'
85         }
86     }]
87
88     def _real_extract(self, url):
89         mobj = re.match(self._VALID_URL, url)
90         video_id = mobj.group('id')
91
92         url = 'http://%s/%s' % (mobj.group('host'), video_id)
93         webpage = self._download_webpage(url, video_id)
94
95         if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
96             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
97
98         fields = self._hidden_inputs(webpage)
99
100         if fields['op'] == 'download1':
101             countdown = int_or_none(self._search_regex(
102                 r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
103                 webpage, 'countdown', default=None))
104             if countdown:
105                 self._sleep(countdown, video_id)
106
107             post = compat_urllib_parse.urlencode(encode_dict(fields))
108
109             req = compat_urllib_request.Request(url, post)
110             req.add_header('Content-type', 'application/x-www-form-urlencoded')
111
112             webpage = self._download_webpage(req, video_id, 'Downloading video page')
113
114         title = (self._search_regex(
115             [r'style="z-index: [0-9]+;">([^<]+)</span>',
116              r'<td nowrap>([^<]+)</td>',
117              r'>Watch (.+) ',
118              r'<h2 class="video-page-head">([^<]+)</h2>'],
119             webpage, 'title', default=None) or self._og_search_title(webpage)).strip()
120         video_url = self._search_regex(
121             [r'file\s*:\s*["\'](http[^"\']+)["\'],',
122              r'file_link\s*=\s*\'(https?:\/\/[0-9a-zA-z.\/\-_]+)'],
123             webpage, 'file url')
124         thumbnail = self._search_regex(
125             r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', default=None)
126
127         formats = [{
128             'format_id': 'sd',
129             'url': video_url,
130             'quality': 1,
131         }]
132
133         return {
134             'id': video_id,
135             'title': title,
136             'thumbnail': thumbnail,
137             'formats': formats,
138         }