[xfileshare] Add support for gorillavid.com and daclips.com (closes #12776)
[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     decode_packed_codes,
9     determine_ext,
10     ExtractorError,
11     int_or_none,
12     NO_DEFAULT,
13     sanitized_Request,
14     urlencode_postdata,
15 )
16
17
18 class XFileShareIE(InfoExtractor):
19     _SITES = (
20         (r'daclips\.(?:in|com)', 'DaClips'),
21         (r'filehoot\.com', 'FileHoot'),
22         (r'gorillavid\.(?:in|com)', 'GorillaVid'),
23         (r'movpod\.in', 'MovPod'),
24         (r'powerwatch\.pw', 'PowerWatch'),
25         (r'rapidvideo\.ws', 'Rapidvideo.ws'),
26         (r'thevideobee\.to', 'TheVideoBee'),
27         (r'vidto\.me', 'Vidto'),
28         (r'streamin\.to', 'Streamin.To'),
29         (r'xvidstage\.com', 'XVIDSTAGE'),
30         (r'vidabc\.com', 'Vid ABC'),
31         (r'vidbom\.com', 'VidBom'),
32         (r'vidlo\.us', 'vidlo'),
33     )
34
35     IE_DESC = 'XFileShare based sites: %s' % ', '.join(list(zip(*_SITES))[1])
36     _VALID_URL = (r'https?://(?P<host>(?:www\.)?(?:%s))/(?:embed-)?(?P<id>[0-9a-zA-Z]+)'
37                   % '|'.join(site for site in list(zip(*_SITES))[0]))
38
39     _FILE_NOT_FOUND_REGEXES = (
40         r'>(?:404 - )?File Not Found<',
41         r'>The file was removed by administrator<',
42     )
43
44     _TESTS = [{
45         'url': 'http://gorillavid.in/06y9juieqpmi',
46         'md5': '5ae4a3580620380619678ee4875893ba',
47         'info_dict': {
48             'id': '06y9juieqpmi',
49             'ext': 'mp4',
50             'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
51             'thumbnail': r're:http://.*\.jpg',
52         },
53     }, {
54         'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
55         'only_matching': True,
56     }, {
57         'url': 'http://daclips.in/3rso4kdn6f9m',
58         'md5': '1ad8fd39bb976eeb66004d3a4895f106',
59         'info_dict': {
60             'id': '3rso4kdn6f9m',
61             'ext': 'mp4',
62             'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
63             'thumbnail': r're:http://.*\.jpg',
64         }
65     }, {
66         'url': 'http://movpod.in/0wguyyxi1yca',
67         'only_matching': True,
68     }, {
69         'url': 'http://filehoot.com/3ivfabn7573c.html',
70         'info_dict': {
71             'id': '3ivfabn7573c',
72             'ext': 'mp4',
73             'title': 'youtube-dl test video \'äBaW_jenozKc.mp4.mp4',
74             'thumbnail': r're:http://.*\.jpg',
75         },
76         'skip': 'Video removed',
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         'url': 'http://xvidstage.com/e0qcnl03co6z',
93         'info_dict': {
94             'id': 'e0qcnl03co6z',
95             'ext': 'mp4',
96             'title': 'Chucky Prank 2015.mp4',
97         },
98     }, {
99         # removed by administrator
100         'url': 'http://xvidstage.com/amfy7atlkx25',
101         'only_matching': True,
102     }, {
103         'url': 'http://vidabc.com/i8ybqscrphfv',
104         'info_dict': {
105             'id': 'i8ybqscrphfv',
106             'ext': 'mp4',
107             'title': 're:Beauty and the Beast 2017',
108         },
109         'params': {
110             'skip_download': True,
111         },
112     }]
113
114     def _real_extract(self, url):
115         mobj = re.match(self._VALID_URL, url)
116         video_id = mobj.group('id')
117
118         url = 'http://%s/%s' % (mobj.group('host'), video_id)
119         webpage = self._download_webpage(url, video_id)
120
121         if any(re.search(p, webpage) for p in self._FILE_NOT_FOUND_REGEXES):
122             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
123
124         fields = self._hidden_inputs(webpage)
125
126         if fields['op'] == 'download1':
127             countdown = int_or_none(self._search_regex(
128                 r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
129                 webpage, 'countdown', default=None))
130             if countdown:
131                 self._sleep(countdown, video_id)
132
133             post = urlencode_postdata(fields)
134
135             req = sanitized_Request(url, post)
136             req.add_header('Content-type', 'application/x-www-form-urlencoded')
137
138             webpage = self._download_webpage(req, video_id, 'Downloading video page')
139
140         title = (self._search_regex(
141             (r'style="z-index: [0-9]+;">([^<]+)</span>',
142              r'<td nowrap>([^<]+)</td>',
143              r'h4-fine[^>]*>([^<]+)<',
144              r'>Watch (.+) ',
145              r'<h2 class="video-page-head">([^<]+)</h2>',
146              r'<h2 style="[^"]*color:#403f3d[^"]*"[^>]*>([^<]+)<'),  # streamin.to
147             webpage, 'title', default=None) or self._og_search_title(
148             webpage, default=None) or video_id).strip()
149
150         def extract_formats(default=NO_DEFAULT):
151             urls = []
152             for regex in (
153                     r'file\s*:\s*(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1',
154                     r'file_link\s*=\s*(["\'])(?P<url>http(?:(?!\1).)+)\1',
155                     r'addVariable\((\\?["\'])file\1\s*,\s*(\\?["\'])(?P<url>http(?:(?!\2).)+)\2\)',
156                     r'<embed[^>]+src=(["\'])(?P<url>http(?:(?!\1).)+\.(?:m3u8|mp4|flv)(?:(?!\1).)*)\1'):
157                 for mobj in re.finditer(regex, webpage):
158                     video_url = mobj.group('url')
159                     if video_url not in urls:
160                         urls.append(video_url)
161             formats = []
162             for video_url in urls:
163                 if determine_ext(video_url) == 'm3u8':
164                     formats.extend(self._extract_m3u8_formats(
165                         video_url, video_id, 'mp4',
166                         entry_protocol='m3u8_native', m3u8_id='hls',
167                         fatal=False))
168                 else:
169                     formats.append({
170                         'url': video_url,
171                         'format_id': 'sd',
172                     })
173             if not formats and default is not NO_DEFAULT:
174                 return default
175             self._sort_formats(formats)
176             return formats
177
178         formats = extract_formats(default=None)
179
180         if not formats:
181             webpage = decode_packed_codes(self._search_regex(
182                 r"(}\('(.+)',(\d+),(\d+),'[^']*\b(?:file|embed)\b[^']*'\.split\('\|'\))",
183                 webpage, 'packed code'))
184             formats = extract_formats()
185
186         thumbnail = self._search_regex(
187             r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', default=None)
188
189         return {
190             'id': video_id,
191             'title': title,
192             'thumbnail': thumbnail,
193             'formats': formats,
194         }