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