]>
Commit | Line | Data |
---|---|---|
678f58de NJ |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..compat import ( |
678f58de NJ |
8 | compat_urllib_parse, |
9 | compat_urllib_request, | |
678f58de | 10 | ) |
1cc79574 PH |
11 | from ..utils import ( |
12 | ExtractorError, | |
13 | ) | |
678f58de NJ |
14 | |
15 | ||
16 | class FiredriveIE(InfoExtractor): | |
17 | _VALID_URL = r'https?://(?:www\.)?firedrive\.com/' + \ | |
18 | '(?:file|embed)/(?P<id>[0-9a-zA-Z]+)' | |
19 | _FILE_DELETED_REGEX = r'<div class="removed_file_image">' | |
20 | ||
21 | _TESTS = [{ | |
22 | 'url': 'https://www.firedrive.com/file/FEB892FA160EBD01', | |
23 | 'md5': 'd5d4252f80ebeab4dc2d5ceaed1b7970', | |
24 | 'info_dict': { | |
25 | 'id': 'FEB892FA160EBD01', | |
26 | 'ext': 'flv', | |
27 | 'title': 'bbb_theora_486kbit.flv', | |
c993c829 | 28 | 'thumbnail': 're:^http://.*\.jpg$', |
678f58de NJ |
29 | }, |
30 | }] | |
31 | ||
32 | def _real_extract(self, url): | |
1cc79574 | 33 | video_id = self._match_id(url) |
678f58de | 34 | url = 'http://firedrive.com/file/%s' % video_id |
678f58de NJ |
35 | webpage = self._download_webpage(url, video_id) |
36 | ||
37 | if re.search(self._FILE_DELETED_REGEX, webpage) is not None: | |
c993c829 | 38 | raise ExtractorError('Video %s does not exist' % video_id, |
678f58de NJ |
39 | expected=True) |
40 | ||
41 | fields = dict(re.findall(r'''(?x)<input\s+ | |
42 | type="hidden"\s+ | |
43 | name="([^"]+)"\s+ | |
678f58de NJ |
44 | value="([^"]*)" |
45 | ''', webpage)) | |
46 | ||
47 | post = compat_urllib_parse.urlencode(fields) | |
48 | req = compat_urllib_request.Request(url, post) | |
49 | req.add_header('Content-type', 'application/x-www-form-urlencoded') | |
50 | ||
51 | # Apparently, this header is required for confirmation to work. | |
52 | req.add_header('Host', 'www.firedrive.com') | |
53 | ||
54 | webpage = self._download_webpage(req, video_id, | |
55 | 'Downloading video page') | |
56 | ||
57 | title = self._search_regex(r'class="external_title_left">(.+)</div>', | |
58 | webpage, 'title') | |
59 | thumbnail = self._search_regex(r'image:\s?"(//[^\"]+)', webpage, | |
c993c829 PH |
60 | 'thumbnail', fatal=False) |
61 | if thumbnail is not None: | |
62 | thumbnail = 'http:' + thumbnail | |
63 | ||
678f58de NJ |
64 | ext = self._search_regex(r'type:\s?\'([^\']+)\',', |
65 | webpage, 'extension', fatal=False) | |
c993c829 | 66 | video_url = self._search_regex( |
6b8492a7 | 67 | r'file:\s?loadURL\(\'(http[^\']+)\'\),', webpage, 'file url') |
678f58de NJ |
68 | |
69 | formats = [{ | |
70 | 'format_id': 'sd', | |
c993c829 PH |
71 | 'url': video_url, |
72 | 'ext': ext, | |
678f58de NJ |
73 | }] |
74 | ||
75 | return { | |
76 | 'id': video_id, | |
77 | 'title': title, | |
c993c829 | 78 | 'thumbnail': thumbnail, |
678f58de NJ |
79 | 'formats': formats, |
80 | } |