]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/shared.py
8607482be8b318fa2772fcb3cd882c9359f50cf9
[youtubedl] / youtube_dl / extractor / shared.py
1 from __future__ import unicode_literals
2
3 import re
4 import base64
5
6 from .common import InfoExtractor
7 from ..utils import (
8 ExtractorError,
9 compat_urllib_request,
10 compat_urllib_parse,
11 int_or_none,
12 )
13
14
15 class SharedIE(InfoExtractor):
16 _VALID_URL = r'http://shared\.sx/(?P<id>[\da-z]{10})'
17
18 _TEST = {
19 'url': 'http://shared.sx/0060718775',
20 'md5': '53e1c58fc3e777ae1dfe9e57ba2f9c72',
21 'info_dict': {
22 'id': '0060718775',
23 'ext': 'mp4',
24 'title': 'Big Buck Bunny Trailer',
25 },
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31
32 page = self._download_webpage(url, video_id)
33
34 if re.search(r'>File does not exist<', page) is not None:
35 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
36
37 download_form = dict(re.findall(r'<input type="hidden" name="([^"]+)" value="([^"]*)"', page))
38
39 request = compat_urllib_request.Request(url, compat_urllib_parse.urlencode(download_form))
40 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
41
42 video_page = self._download_webpage(request, video_id, 'Downloading video page')
43
44 video_url = self._html_search_regex(r'data-url="([^"]+)"', video_page, 'video URL')
45 title = base64.b64decode(self._html_search_meta('full:title', page, 'title')).decode('utf-8')
46 filesize = int_or_none(self._html_search_meta('full:size', page, 'file size', fatal=False))
47 thumbnail = self._html_search_regex(
48 r'data-poster="([^"]+)"', video_page, 'thumbnail', fatal=False, default=None)
49
50 return {
51 'id': video_id,
52 'url': video_url,
53 'ext': 'mp4',
54 'filesize': filesize,
55 'title': title,
56 'thumbnail': thumbnail,
57 }