[dcn] make m3u8 formats extraction non fatal
[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         'only_matching': True,
39     }, {
40         'url': 'http://daclips.in/3rso4kdn6f9m',
41         'md5': '1ad8fd39bb976eeb66004d3a4895f106',
42         'info_dict': {
43             'id': '3rso4kdn6f9m',
44             'ext': 'mp4',
45             'title': 'Micro Pig piglets ready on 16th July 2009-bG0PdrCdxUc',
46             'thumbnail': 're:http://.*\.jpg',
47         }
48     }, {
49         # video with countdown timeout
50         'url': 'http://fastvideo.in/1qmdn1lmsmbw',
51         'md5': '8b87ec3f6564a3108a0e8e66594842ba',
52         'info_dict': {
53             'id': '1qmdn1lmsmbw',
54             'ext': 'mp4',
55             'title': 'Man of Steel - Trailer',
56             'thumbnail': 're:http://.*\.jpg',
57         },
58     }, {
59         'url': 'http://realvid.net/ctn2y6p2eviw',
60         'md5': 'b2166d2cf192efd6b6d764c18fd3710e',
61         'info_dict': {
62             'id': 'ctn2y6p2eviw',
63             'ext': 'flv',
64             'title': 'rdx 1955',
65             'thumbnail': 're:http://.*\.jpg',
66         },
67     }, {
68         'url': 'http://movpod.in/0wguyyxi1yca',
69         'only_matching': True,
70     }]
71
72     def _real_extract(self, url):
73         mobj = re.match(self._VALID_URL, url)
74         video_id = mobj.group('id')
75
76         webpage = self._download_webpage('http://%s/%s' % (mobj.group('host'), video_id), video_id)
77
78         if re.search(self._FILE_NOT_FOUND_REGEX, webpage) is not None:
79             raise ExtractorError('Video %s does not exist' % video_id, expected=True)
80
81         fields = self._hidden_inputs(webpage)
82
83         if fields['op'] == 'download1':
84             countdown = int_or_none(self._search_regex(
85                 r'<span id="countdown_str">(?:[Ww]ait)?\s*<span id="cxc">(\d+)</span>\s*(?:seconds?)?</span>',
86                 webpage, 'countdown', default=None))
87             if countdown:
88                 self._sleep(countdown, video_id)
89
90             post = compat_urllib_parse.urlencode(fields)
91
92             req = compat_urllib_request.Request(url, post)
93             req.add_header('Content-type', 'application/x-www-form-urlencoded')
94
95             webpage = self._download_webpage(req, video_id, 'Downloading video page')
96
97         title = self._search_regex(
98             [r'style="z-index: [0-9]+;">([^<]+)</span>', r'>Watch (.+) '],
99             webpage, 'title', default=None) or self._og_search_title(webpage)
100         video_url = self._search_regex(
101             r'file\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'file url')
102         thumbnail = self._search_regex(
103             r'image\s*:\s*["\'](http[^"\']+)["\'],', webpage, 'thumbnail', fatal=False)
104
105         formats = [{
106             'format_id': 'sd',
107             'url': video_url,
108             'quality': 1,
109         }]
110
111         return {
112             'id': video_id,
113             'title': title,
114             'thumbnail': thumbnail,
115             'formats': formats,
116         }