[gorillavid] Add support for movpod.in (Fixes #3881)
[youtube-dl] / 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     determine_ext,
9     compat_urllib_parse,
10     compat_urllib_request,
11 )
12
13
14 class GorillaVidIE(InfoExtractor):
15     IE_DESC = 'GorillaVid.in, daclips.in and movpod.in'
16     _VALID_URL = r'''(?x)
17         https?://(?P<host>(?:www\.)?
18             (?:daclips\.in|gorillavid\.in|movpod\.in))/
19         (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
20     '''
21
22     _TESTS = [{
23         'url': 'http://gorillavid.in/06y9juieqpmi',
24         'md5': '5ae4a3580620380619678ee4875893ba',
25         'info_dict': {
26             'id': '06y9juieqpmi',
27             'ext': 'flv',
28             'title': 'Rebecca Black My Moment Official Music Video Reaction',
29             'thumbnail': 're:http://.*\.jpg',
30         },
31     }, {
32         'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
33         'md5': 'c9e293ca74d46cad638e199c3f3fe604',
34         'info_dict': {
35             'id': 'z08zf8le23c6',
36             'ext': 'mp4',
37             'title': 'Say something nice',
38             'thumbnail': 're:http://.*\.jpg',
39         },
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',
47             'thumbnail': 're:http://.*\.jpg',
48         },
49     }, {
50         'url': 'http://movpod.in/0wguyyxi1yca',
51         'only_matching': True,
52     }]
53
54     def _real_extract(self, url):
55         mobj = re.match(self._VALID_URL, url)
56         video_id = mobj.group('id')
57
58         webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
59
60         fields = dict(re.findall(r'''(?x)<input\s+
61             type="hidden"\s+
62             name="([^"]+)"\s+
63             (?:id="[^"]+"\s+)?
64             value="([^"]*)"
65             ''', webpage))
66         
67         if fields['op'] == 'download1':
68             post = compat_urllib_parse.urlencode(fields)
69
70             req = compat_urllib_request.Request(url, post)
71             req.add_header('Content-type', 'application/x-www-form-urlencoded')
72
73             webpage = self._download_webpage(req, video_id, 'Downloading video page')
74
75         title = self._search_regex(r'style="z-index: [0-9]+;">([0-9a-zA-Z ]+)(?:-.+)?</span>', webpage, 'title')
76         thumbnail = self._search_regex(r'image:\'(http[^\']+)\',', webpage, 'thumbnail')
77         url = self._search_regex(r'file: \'(http[^\']+)\',', webpage, 'file url')
78
79         formats = [{
80             'format_id': 'sd',
81             'url': url,
82             'ext': determine_ext(url),
83             'quality': 1,
84         }]
85
86         return {
87             'id': video_id,
88             'title': title,
89             'thumbnail': thumbnail,
90             'formats': formats,
91         }