4 from .common
import InfoExtractor
5 from ..compat
import compat_urllib_parse_unquote
14 class DropboxIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?dropbox[.]com/sh?/(?P<id>[a-zA-Z0-9]{15})/.*'
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/sh/662glsejgzoj9sr/AAByil3FGH9KFNZ13e08eSa1a/Pregame%20Ceremony%20Program%20PA%2020140518.m4v',
26 'only_matching': True,
30 def _real_extract(self
, url
):
31 mobj
= self
._match
_valid
_url
(url
)
32 video_id
= mobj
.group('id')
33 webpage
= self
._download
_webpage
(url
, video_id
)
34 fn
= compat_urllib_parse_unquote(url_basename(url
))
35 title
= os
.path
.splitext(fn
)[0]
37 password
= self
.get_param('videopassword')
38 if (self
._og
_search
_title
(webpage
) == 'Dropbox - Password Required'
39 or 'Enter the password for this link' in webpage
):
42 content_id
= self
._search
_regex
(r
'content_id=(.*?)["\']', webpage, 'content_id
')
43 payload = f'is_xhr
=true
&t
={self._get_cookies("https://www.dropbox.com").get("t").value}
&content_id
={content_id}
&password
={password}
&url
={url}
'
44 response = self._download_json(
45 'https
://www
.dropbox
.com
/sm
/auth
', video_id, 'POSTing video password
', data=payload.encode('UTF
-8'),
46 headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'})
48 if response.get('status
') != 'authed
':
49 raise ExtractorError('Authentication failed
!', expected=True)
50 webpage = self._download_webpage(url, video_id)
51 elif self._get_cookies('https
://dropbox
.com
').get('sm_auth
'):
52 webpage = self._download_webpage(url, video_id)
54 raise ExtractorError('Password protected video
, use
--video
-password
<password
>', expected=True)
56 info_json = self._search_json(r'InitReact\
.mountComponent\
(.*?
,', webpage, 'mountComponent
', video_id,
57 contains_pattern=r'.+?
"preview".+?
', end_pattern=r'\
)')['props
']
58 transcode_url = traverse_obj(info_json, ((None, 'preview
'), 'file', 'preview
', 'content
', 'transcode_url
'), get_all=False)
59 formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id)
61 # downloads enabled we can get the original file
62 if 'anonymous
' in (try_get(info_json, lambda x: x['sharePermission
']['canDownloadRoles
']) or []):
63 video_url = re.sub(r'[?
&]dl
=0', '', url)
64 video_url += ('?
' if '?
' not in video_url else '&') + 'dl
=1'
65 formats.append({'url': video_url, 'format_id': 'original', 'format_note': 'Original', 'quality': 1})
66 self._sort_formats(formats)
72 'subtitles
': subtitles