]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/firedrive.py
debian/changelog: Initiate new release.
[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 ..compat import (
8 compat_urllib_parse,
9 compat_urllib_request,
10 )
11 from ..utils import (
12 ExtractorError,
13 )
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',
28 'thumbnail': 're:^http://.*\.jpg$',
29 },
30 }]
31
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
34 url = 'http://firedrive.com/file/%s' % video_id
35 webpage = self._download_webpage(url, video_id)
36
37 if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
38 raise ExtractorError('Video %s does not exist' % video_id,
39 expected=True)
40
41 fields = dict(re.findall(r'''(?x)<input\s+
42 type="hidden"\s+
43 name="([^"]+)"\s+
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,
60 'thumbnail', fatal=False)
61 if thumbnail is not None:
62 thumbnail = 'http:' + thumbnail
63
64 ext = self._search_regex(r'type:\s?\'([^\']+)\',',
65 webpage, 'extension', fatal=False)
66 video_url = self._search_regex(
67 r'file:\s?loadURL\(\'(http[^\']+)\'\),', webpage, 'file url')
68
69 formats = [{
70 'format_id': 'sd',
71 'url': video_url,
72 'ext': ext,
73 }]
74
75 return {
76 'id': video_id,
77 'title': title,
78 'thumbnail': thumbnail,
79 'formats': formats,
80 }