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