]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gorillavid.py
Prepare for upload.
[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 ..utils import (
8 ExtractorError,
9 determine_ext,
10 compat_urllib_parse,
11 compat_urllib_request,
12 )
13
14
15 class GorillaVidIE(InfoExtractor):
16 IE_DESC = 'GorillaVid.in, daclips.in and movpod.in'
17 _VALID_URL = r'''(?x)
18 https?://(?P<host>(?:www\.)?
19 (?:daclips\.in|gorillavid\.in|movpod\.in))/
20 (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
21 '''
22
23 _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
24
25 _TESTS = [{
26 'url': 'http://gorillavid.in/06y9juieqpmi',
27 'md5': '5ae4a3580620380619678ee4875893ba',
28 'info_dict': {
29 'id': '06y9juieqpmi',
30 'ext': 'flv',
31 'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
32 'thumbnail': 're:http://.*\.jpg',
33 },
34 }, {
35 'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
36 'md5': 'c9e293ca74d46cad638e199c3f3fe604',
37 'info_dict': {
38 'id': 'z08zf8le23c6',
39 'ext': 'mp4',
40 'title': 'Say something nice',
41 'thumbnail': 're:http://.*\.jpg',
42 },
43 }, {
44 'url': 'http://daclips.in/3rso4kdn6f9m',
45 'md5': '1ad8fd39bb976eeb66004d3a4895f106',
46 'info_dict': {
47 'id': '3rso4kdn6f9m',
48 'ext': 'mp4',
49 'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
50 'thumbnail': 're:http://.*\.jpg',
51 }
52 }, {
53 'url': 'http://movpod.in/0wguyyxi1yca',
54 'only_matching': True,
55 }]
56
57 def _real_extract(self, url):
58 mobj = re.match(self._VALID_URL, url)
59 video_id = mobj.group('id')
60
61 webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
62
63 if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
64 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
65
66 fields = dict(re.findall(r'''(?x)<input\s+
67 type="hidden"\s+
68 name="([^"]+)"\s+
69 (?:id="[^"]+"\s+)?
70 value="([^"]*)"
71 ''', webpage))
72
73 if fields['op'] == 'download1':
74 post = compat_urllib_parse.urlencode(fields)
75
76 req = compat_urllib_request.Request(url, post)
77 req.add_header('Content-type', 'application/x-www-form-urlencoded')
78
79 webpage = self._download_webpage(req, video_id, 'Downloading video page')
80
81 title = self._search_regex(r'style="z-index: [0-9]+;">([^<]+)</span>', webpage, 'title')
82 video_url = self._search_regex(r'file\s*:\s*\'(http[^\']+)\',', webpage, 'file url')
83 thumbnail = self._search_regex(r'image\s*:\s*\'(http[^\']+)\',', webpage, 'thumbnail', fatal=False)
84
85 formats = [{
86 'format_id': 'sd',
87 'url': video_url,
88 'ext': determine_ext(video_url),
89 'quality': 1,
90 }]
91
92 return {
93 'id': video_id,
94 'title': title,
95 'thumbnail': thumbnail,
96 'formats': formats,
97 }