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