]>
Commit | Line | Data |
---|---|---|
b9f2bc2d | 1 | import base64 |
4cf393bb | 2 | import os.path |
8da53135 | 3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
8c25f81b | 6 | from ..compat import compat_urllib_parse_unquote |
7141ced5 | 7 | from ..utils import ( |
8 | ExtractorError, | |
b9f2bc2d | 9 | update_url_query, |
7141ced5 | 10 | url_basename, |
11 | ) | |
8da53135 | 12 | |
ce4e242a | 13 | |
6b79f40c | 14 | class DropboxIE(InfoExtractor): |
b9f2bc2d | 15 | _VALID_URL = r'https?://(?:www\.)?dropbox\.com/(?:(?:e/)?scl/fi|sh?)/(?P<id>\w+)' |
9e1a5b84 JW |
16 | _TESTS = [ |
17 | { | |
7a5c1cfe | 18 | 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0', |
9e1a5b84 JW |
19 | 'info_dict': { |
20 | 'id': 'nelirfsxnmcfbfh', | |
21 | 'ext': 'mp4', | |
7a5c1cfe | 22 | 'title': 'youtube-dl test video \'ä"BaW_jenozKc' |
9e1a5b84 JW |
23 | } |
24 | }, { | |
b9f2bc2d NT |
25 | 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh', |
26 | 'only_matching': True, | |
27 | }, { | |
28 | 'url': 'https://www.dropbox.com/sh/2mgpiuq7kv8nqdf/AABy-fW4dkydT4GmWi2mdOUDa?dl=0&preview=Drone+Shot.mp4', | |
29 | 'only_matching': True, | |
30 | }, { | |
31 | 'url': 'https://www.dropbox.com/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h', | |
32 | 'only_matching': True, | |
33 | }, { | |
34 | 'url': 'https://www.dropbox.com/e/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h', | |
9e1a5b84 JW |
35 | 'only_matching': True, |
36 | }, | |
7bd4b422 | 37 | ] |
ce4e242a PH |
38 | |
39 | def _real_extract(self, url): | |
5ad28e7f | 40 | mobj = self._match_valid_url(url) |
ce4e242a | 41 | video_id = mobj.group('id') |
7141ced5 | 42 | webpage = self._download_webpage(url, video_id) |
7bd4b422 | 43 | fn = compat_urllib_parse_unquote(url_basename(url)) |
264a7044 | 44 | title = os.path.splitext(fn)[0] |
7141ced5 | 45 | |
46 | password = self.get_param('videopassword') | |
47 | if (self._og_search_title(webpage) == 'Dropbox - Password Required' | |
48 | or 'Enter the password for this link' in webpage): | |
49 | ||
50 | if password: | |
51 | content_id = self._search_regex(r'content_id=(.*?)["\']', webpage, 'content_id') | |
52 | payload = f'is_xhr=true&t={self._get_cookies("https://www.dropbox.com").get("t").value}&content_id={content_id}&password={password}&url={url}' | |
53 | response = self._download_json( | |
54 | 'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password', data=payload.encode('UTF-8'), | |
55 | headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}) | |
56 | ||
57 | if response.get('status') != 'authed': | |
58 | raise ExtractorError('Authentication failed!', expected=True) | |
59 | webpage = self._download_webpage(url, video_id) | |
60 | elif self._get_cookies('https://dropbox.com').get('sm_auth'): | |
61 | webpage = self._download_webpage(url, video_id) | |
62 | else: | |
63 | raise ExtractorError('Password protected video, use --video-password <password>', expected=True) | |
64 | ||
b9f2bc2d NT |
65 | formats, subtitles, has_anonymous_download = [], {}, False |
66 | for encoded in reversed(re.findall(r'registerStreamedPrefetch\s*\(\s*"[\w/+=]+"\s*,\s*"([\w/+=]+)"', webpage)): | |
67 | decoded = base64.b64decode(encoded).decode('utf-8', 'ignore') | |
68 | transcode_url = self._search_regex( | |
099fb1b3 | 69 | r'\n.(https://[^\x03\x08\x12\n]+\.m3u8)', decoded, 'transcode url', default=None) |
b9f2bc2d NT |
70 | if not transcode_url: |
71 | continue | |
099fb1b3 | 72 | formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id, 'mp4') |
b9f2bc2d NT |
73 | has_anonymous_download = self._search_regex(r'(anonymous:\tanonymous)', decoded, 'anonymous', default=False) |
74 | break | |
7141ced5 | 75 | |
76 | # downloads enabled we can get the original file | |
b9f2bc2d NT |
77 | if has_anonymous_download: |
78 | formats.append({ | |
79 | 'url': update_url_query(url, {'dl': '1'}), | |
80 | 'format_id': 'original', | |
81 | 'format_note': 'Original', | |
82 | 'quality': 1 | |
83 | }) | |
ce4e242a PH |
84 | |
85 | return { | |
86 | 'id': video_id, | |
87 | 'title': title, | |
7141ced5 | 88 | 'formats': formats, |
89 | 'subtitles': subtitles | |
ce4e242a | 90 | } |