]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/shared.py
debian/control: Update list of supported sites/extractors.
[youtubedl] / youtube_dl / extractor / shared.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_b64decode
5 from ..utils import (
6 ExtractorError,
7 int_or_none,
8 urlencode_postdata,
9 )
10
11
12 class SharedBaseIE(InfoExtractor):
13 def _real_extract(self, url):
14 video_id = self._match_id(url)
15
16 webpage, urlh = self._download_webpage_handle(url, video_id)
17
18 if self._FILE_NOT_FOUND in webpage:
19 raise ExtractorError(
20 'Video %s does not exist' % video_id, expected=True)
21
22 video_url = self._extract_video_url(webpage, video_id, url)
23
24 title = compat_b64decode(self._html_search_meta(
25 'full:title', webpage, 'title')).decode('utf-8')
26 filesize = int_or_none(self._html_search_meta(
27 'full:size', webpage, 'file size', fatal=False))
28
29 return {
30 'id': video_id,
31 'url': video_url,
32 'ext': 'mp4',
33 'filesize': filesize,
34 'title': title,
35 }
36
37
38 class SharedIE(SharedBaseIE):
39 IE_DESC = 'shared.sx'
40 _VALID_URL = r'https?://shared\.sx/(?P<id>[\da-z]{10})'
41 _FILE_NOT_FOUND = '>File does not exist<'
42
43 _TEST = {
44 'url': 'http://shared.sx/0060718775',
45 'md5': '106fefed92a8a2adb8c98e6a0652f49b',
46 'info_dict': {
47 'id': '0060718775',
48 'ext': 'mp4',
49 'title': 'Bmp4',
50 'filesize': 1720110,
51 },
52 }
53
54 def _extract_video_url(self, webpage, video_id, url):
55 download_form = self._hidden_inputs(webpage)
56
57 video_page = self._download_webpage(
58 url, video_id, 'Downloading video page',
59 data=urlencode_postdata(download_form),
60 headers={
61 'Content-Type': 'application/x-www-form-urlencoded',
62 'Referer': url,
63 })
64
65 video_url = self._html_search_regex(
66 r'data-url=(["\'])(?P<url>(?:(?!\1).)+)\1',
67 video_page, 'video URL', group='url')
68
69 return video_url
70
71
72 class VivoIE(SharedBaseIE):
73 IE_DESC = 'vivo.sx'
74 _VALID_URL = r'https?://vivo\.sx/(?P<id>[\da-z]{10})'
75 _FILE_NOT_FOUND = '>The file you have requested does not exists or has been removed'
76
77 _TEST = {
78 'url': 'http://vivo.sx/d7ddda0e78',
79 'md5': '15b3af41be0b4fe01f4df075c2678b2c',
80 'info_dict': {
81 'id': 'd7ddda0e78',
82 'ext': 'mp4',
83 'title': 'Chicken',
84 'filesize': 528031,
85 },
86 }
87
88 def _extract_video_url(self, webpage, video_id, *args):
89 return self._parse_json(
90 self._search_regex(
91 r'InitializeStream\s*\(\s*(["\'])(?P<url>(?:(?!\1).)+)\1',
92 webpage, 'stream', group='url'),
93 video_id,
94 transform_source=lambda x: compat_b64decode(x).decode('utf-8'))[0]