6 from .common
import InfoExtractor
14 class DropboxIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?dropbox\.com/(?:(?:e/)?scl/fi|sh?)/(?P<id>\w+)'
18 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0',
20 'id': 'nelirfsxnmcfbfh',
22 'title': 'youtube-dl test video \'รค"BaW_jenozKc',
25 'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh',
26 'only_matching': True,
28 'url': 'https://www.dropbox.com/sh/2mgpiuq7kv8nqdf/AABy-fW4dkydT4GmWi2mdOUDa?dl=0&preview=Drone+Shot.mp4',
29 'only_matching': True,
31 'url': 'https://www.dropbox.com/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h',
32 'only_matching': True,
34 'url': 'https://www.dropbox.com/e/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h',
35 'only_matching': True,
39 def _real_extract(self
, url
):
40 mobj
= self
._match
_valid
_url
(url
)
41 video_id
= mobj
.group('id')
42 webpage
= self
._download
_webpage
(url
, video_id
)
43 fn
= urllib
.parse
.unquote(url_basename(url
))
44 title
= os
.path
.splitext(fn
)[0]
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
):
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(),
55 headers={'content
-type': 'application
/x
-www
-form
-urlencoded
; charset
=UTF
-8'})
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)
63 raise ExtractorError('Password protected video
, use
--video
-password
<password
>', expected=True)
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 if not has_anonymous_download:
69 has_anonymous_download = self._search_regex(
70 r'(anonymous
:\tanonymous
)', decoded, 'anonymous
', default=False)
71 transcode_url = self._search_regex(
72 r'\n.(https
://[^
\x03\x08\x12\n]+\
.m3u8
)', decoded, 'transcode url
', default=None)
75 formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id, 'mp4
')
78 # downloads enabled we can get the original file
79 if has_anonymous_download:
81 'url
': update_url_query(url, {'dl
': '1'}),
82 'format_id
': 'original
',
83 'format_note
': 'Original
',
91 'subtitles
': subtitles,