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