[downloader/f4m] Fragment filenames must be sanitized
[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 ..compat import (
8     compat_urllib_parse,
9     compat_urllib_request,
10 )
11 from ..utils import (
12     ExtractorError,
13     int_or_none,
14 )
15
16
17 class GorillaVidIE(InfoExtractor):
18     IE_DESC = 'GorillaVid.in, daclips.in, movpod.in, fastvideo.in and realvid.net'
19     _VALID_URL = r'''(?x)
20         https?://(?P<host>(?:www\.)?
21             (?:daclips\.in|gorillavid\.in|movpod\.in|fastvideo\.in|realvid\.net))/
22         (?:embed-)?(?P<id>[0-9a-zA-Z]+)(?:-[0-9]+x[0-9]+\.html)?
23     '''
24
25     _FILE_NOT_FOUND_REGEX = r'>(?:404 - )?File Not Found<'
26
27     _TESTS = [{
28         'url': 'http://gorillavid.in/06y9juieqpmi',
29         'md5': '5ae4a3580620380619678ee4875893ba',
30         'info_dict': {
31             'id': '06y9juieqpmi',
32             'ext': 'flv',
33             'title': 'Rebecca Black My Moment Official Music Video Reaction-6GK87Rc8bzQ',
34             'thumbnail': 're:http://.*\.jpg',
35         },
36     }, {
37         'url': 'http://gorillavid.in/embed-z08zf8le23c6-960x480.html',
38         'md5': 'c9e293ca74d46cad638e199c3f3fe604',
39         'info_dict': {
40             'id': 'z08zf8le23c6',
41             'ext': 'mp4',
42             'title': 'Say something nice',
43             'thumbnail': 're:http://.*\.jpg',
44         },
45     }, {
46         'url': 'http://daclips.in/3rso4kdn6f9m',
47         'md5': '1ad8fd39bb976eeb66004d3a4895f106',
48         'info_dict': {
49             'id': '3rso4kdn6f9m',
50             'ext': 'mp4',
51             'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
52             'thumbnail': 're:http://.*\.jpg',
53         }
54     }, {
55         # video with countdown timeout
56         'url': 'http://fastvideo.in/1qmdn1lmsmbw',
57         'md5': '8b87ec3f6564a3108a0e8e66594842ba',
58         'info_dict': {
59             'id': '1qmdn1lmsmbw',
60             'ext': 'mp4',
61             'title': 'Man of Steel - Trailer',
62             'thumbnail': 're:http://.*\.jpg',
63         },
64     }, {
65         'url': 'http://realvid.net/ctn2y6p2eviw',
66         'md5': 'b2166d2cf192efd6b6d764c18fd3710e',
67         'info_dict': {
68             'id': 'ctn2y6p2eviw',
69             'ext': 'flv',
70             'title': 'rdx 1955',
71             'thumbnail': 're:http://.*\.jpg',
72         },
73     }, {
74         'url': 'http://movpod.in/0wguyyxi1yca',
75         'only_matching': True,
76     }]
77
78     def _real_extract(self, url):
79         mobj = re.match(self._VALID_URL, url)
80         video_id = mobj.group('id')
81
82         webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
83
84         if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
85             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
86
87         fields = dict(re.findall(r'''(?x)<input\s+
88             type="hidden"\s+
89             name="([^"]+)"\s+
90             (?:id="[^"]+"\s+)?
91             value="([^"]*)"
92             ''', webpage))
93
94         if fields['op'] == 'download1':
95             countdown = int_or_none(self._search_regex(
96                 r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
97                 webpage, 'countdown', default=None))
98             if countdown:
99                 self._sleep(countdown, video_id)
100
101             post = compat_urllib_parse.urlencode(fields)
102
103             req = compat_urllib_request.Request(url, post)
104             req.add_header('Content-type', 'application/x-www-form-urlencoded')
105
106             webpage = self._download_webpage(req, video_id, 'Downloading video page')
107
108         title = self._search_regex(
109             [r'style="z-index: [0-9]+;">([^<]+)</span>', r'>Watch (.+) '],
110             webpage, 'title', default=None) or self._og_search_title(webpage)
111         video_url = self._search_regex(
112             r'file\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'file url')
113         thumbnail = self._search_regex(
114             r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', fatal=False)
115
116         formats = [{
117             'format_id': 'sd',
118             'url': video_url,
119             'quality': 1,
120         }]
121
122         return {
123             'id': video_id,
124             'title': title,
125             'thumbnail': thumbnail,
126             'formats': formats,
127         }