2023-08-28 15:33:48 -06:00
|
|
|
import base64
|
2014-01-18 22:16:40 -07:00
|
|
|
import os.path
|
2014-01-18 08:15:53 -07:00
|
|
|
import re
|
2024-06-11 17:09:58 -06:00
|
|
|
import urllib.parse
|
2014-01-18 08:15:53 -07:00
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2022-01-02 03:44:10 -07:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2024-09-27 16:05:22 -06:00
|
|
|
update_url,
|
2023-08-28 15:33:48 -06:00
|
|
|
update_url_query,
|
2022-01-02 03:44:10 -07:00
|
|
|
url_basename,
|
2024-09-27 16:05:22 -06:00
|
|
|
urlencode_postdata,
|
2022-01-02 03:44:10 -07:00
|
|
|
)
|
2014-01-18 08:15:53 -07:00
|
|
|
|
2014-01-18 22:14:24 -07:00
|
|
|
|
2014-01-18 21:50:26 -07:00
|
|
|
class DropboxIE(InfoExtractor):
|
2023-08-28 15:33:48 -06:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?dropbox\.com/(?:(?:e/)?scl/fi|sh?)/(?P<id>\w+)'
|
2014-11-23 13:39:15 -07:00
|
|
|
_TESTS = [
|
|
|
|
{
|
2021-02-24 11:45:56 -07:00
|
|
|
'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh/youtube-dl%20test%20video%20%27%C3%A4%22BaW_jenozKc.mp4?dl=0',
|
2014-11-23 13:39:15 -07:00
|
|
|
'info_dict': {
|
|
|
|
'id': 'nelirfsxnmcfbfh',
|
|
|
|
'ext': 'mp4',
|
2024-06-11 17:09:58 -06:00
|
|
|
'title': 'youtube-dl test video \'ä"BaW_jenozKc',
|
|
|
|
},
|
2014-11-23 13:39:15 -07:00
|
|
|
}, {
|
2023-08-28 15:33:48 -06:00
|
|
|
'url': 'https://www.dropbox.com/s/nelirfsxnmcfbfh',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.dropbox.com/sh/2mgpiuq7kv8nqdf/AABy-fW4dkydT4GmWi2mdOUDa?dl=0&preview=Drone+Shot.mp4',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.dropbox.com/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.dropbox.com/e/scl/fi/r2kd2skcy5ylbbta5y1pz/DJI_0003.MP4?dl=0&rlkey=wcdgqangn7t3lnmmv6li9mu9h',
|
2014-11-23 13:39:15 -07:00
|
|
|
'only_matching': True,
|
|
|
|
},
|
2014-09-21 05:40:22 -06:00
|
|
|
]
|
2014-01-18 22:14:24 -07:00
|
|
|
|
2024-09-27 16:05:22 -06:00
|
|
|
def _yield_decoded_parts(self, webpage):
|
|
|
|
for encoded in reversed(re.findall(r'registerStreamedPrefetch\s*\(\s*"[\w/+=]+"\s*,\s*"([\w/+=]+)"', webpage)):
|
|
|
|
yield base64.b64decode(encoded).decode('utf-8', 'ignore')
|
|
|
|
|
2014-01-18 22:14:24 -07:00
|
|
|
def _real_extract(self, url):
|
2021-08-18 19:41:24 -06:00
|
|
|
mobj = self._match_valid_url(url)
|
2014-01-18 22:14:24 -07:00
|
|
|
video_id = mobj.group('id')
|
2022-01-02 03:44:10 -07:00
|
|
|
webpage = self._download_webpage(url, video_id)
|
2024-06-11 17:09:58 -06:00
|
|
|
fn = urllib.parse.unquote(url_basename(url))
|
2014-07-21 04:57:40 -06:00
|
|
|
title = os.path.splitext(fn)[0]
|
2022-01-02 03:44:10 -07:00
|
|
|
password = self.get_param('videopassword')
|
|
|
|
|
2024-09-27 16:05:22 -06:00
|
|
|
for part in self._yield_decoded_parts(webpage):
|
|
|
|
if '/sm/password' in part:
|
|
|
|
webpage = self._download_webpage(
|
|
|
|
update_url('https://www.dropbox.com/sm/password', query=part.partition('?')[2]), video_id)
|
|
|
|
break
|
|
|
|
|
|
|
|
if (self._og_search_title(webpage, default=None) == 'Dropbox - Password Required'
|
|
|
|
or 'Enter the password for this link' in webpage):
|
2022-01-02 03:44:10 -07:00
|
|
|
if password:
|
|
|
|
response = self._download_json(
|
2024-09-27 16:05:22 -06:00
|
|
|
'https://www.dropbox.com/sm/auth', video_id, 'POSTing video password',
|
|
|
|
headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'},
|
|
|
|
data=urlencode_postdata({
|
|
|
|
'is_xhr': 'true',
|
|
|
|
't': self._get_cookies('https://www.dropbox.com')['t'].value,
|
|
|
|
'content_id': self._search_regex(r'content_id=([\w.+=/-]+)["\']', webpage, 'content id'),
|
|
|
|
'password': password,
|
|
|
|
'url': url,
|
|
|
|
}))
|
2022-01-02 03:44:10 -07:00
|
|
|
|
|
|
|
if response.get('status') != 'authed':
|
2024-09-27 16:05:22 -06:00
|
|
|
raise ExtractorError('Invalid password', expected=True)
|
|
|
|
elif not self._get_cookies('https://dropbox.com').get('sm_auth'):
|
2022-01-02 03:44:10 -07:00
|
|
|
raise ExtractorError('Password protected video, use --video-password <password>', expected=True)
|
2024-09-27 16:05:22 -06:00
|
|
|
webpage = self._download_webpage(url, video_id)
|
2022-01-02 03:44:10 -07:00
|
|
|
|
2024-09-27 16:05:22 -06:00
|
|
|
formats, subtitles = [], {}
|
|
|
|
has_anonymous_download = False
|
|
|
|
thumbnail = None
|
|
|
|
for part in self._yield_decoded_parts(webpage):
|
2024-04-06 11:19:44 -06:00
|
|
|
if not has_anonymous_download:
|
|
|
|
has_anonymous_download = self._search_regex(
|
2024-09-27 16:05:22 -06:00
|
|
|
r'(anonymous:\tanonymous)', part, 'anonymous', default=False)
|
2023-08-28 15:33:48 -06:00
|
|
|
transcode_url = self._search_regex(
|
2024-09-27 16:05:22 -06:00
|
|
|
r'\n.(https://[^\x03\x08\x12\n]+\.m3u8)', part, 'transcode url', default=None)
|
2023-08-28 15:33:48 -06:00
|
|
|
if not transcode_url:
|
|
|
|
continue
|
2023-08-29 07:06:02 -06:00
|
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(transcode_url, video_id, 'mp4')
|
2024-09-27 16:05:22 -06:00
|
|
|
thumbnail = self._search_regex(
|
|
|
|
r'(https://www\.dropbox\.com/temp_thumb_from_token/[\w/?&=]+)', part, 'thumbnail', default=None)
|
2023-08-28 15:33:48 -06:00
|
|
|
break
|
2022-01-02 03:44:10 -07:00
|
|
|
|
|
|
|
# downloads enabled we can get the original file
|
2023-08-28 15:33:48 -06:00
|
|
|
if has_anonymous_download:
|
|
|
|
formats.append({
|
|
|
|
'url': update_url_query(url, {'dl': '1'}),
|
|
|
|
'format_id': 'original',
|
|
|
|
'format_note': 'Original',
|
2024-06-11 17:09:58 -06:00
|
|
|
'quality': 1,
|
2023-08-28 15:33:48 -06:00
|
|
|
})
|
2014-01-18 22:14:24 -07:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
2022-01-02 03:44:10 -07:00
|
|
|
'formats': formats,
|
2024-06-11 17:09:58 -06:00
|
|
|
'subtitles': subtitles,
|
2024-09-27 16:05:22 -06:00
|
|
|
'thumbnail': thumbnail,
|
2014-01-18 22:14:24 -07:00
|
|
|
}
|