]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gorillavid.py
d23e3eac1aa7a46a82d21a527d06862f245b4e29
[youtubedl] / youtube_dl / extractor / gorillavid.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 GorillaVidIE(InfoExtractor):
19 IE_DESC = 'GorillaVid.in, daclips.in, movpod.in, fastvideo.in, realvid.net and filehoot.com'
20 _VALID_URL = r'''(?x)
21 https?://(?P<host>(?:www\.)?
22 (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in|realvid\.net|filehoot\.com))/
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
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 = compat_urllib_parse.urlencode(encode_dict(fields))
101
102 req = compat_urllib_request.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>', r'<td nowrap>([^<]+)</td>', r'>Watch (.+) '],
109 webpage, 'title', default=None) or self._og_search_title(webpage)
110 video_url = self._search_regex(
111 r'file\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'file url')
112 thumbnail = self._search_regex(
113 r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', fatal=False)
114
115 formats = [{
116 'format_id': 'sd',
117 'url': video_url,
118 'quality': 1,
119 }]
120
121 return {
122 'id': video_id,
123 'title': title,
124 'thumbnail': thumbnail,
125 'formats': formats,
126 }