Skip to content

Commit 077fcdc

Browse files
committed
bugfix tutorialdownload
1 parent d8e216b commit 077fcdc

1 file changed

Lines changed: 30 additions & 11 deletions

File tree

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
11
function downloadData()
2-
%DOWNLOADDATA Download tutorial data from Google Drive
3-
% Cross-platform: Windows / macOS / Linux
2+
%DOWNLOADDATA Download tutorial data using curl/wget via system()
3+
% Works on Windows / macOS / Linux
44

55
fprintf('Downloading tutorial data...\n');
66

77
scriptDir = fileparts(mfilename('fullpath'));
8+
cd(scriptDir);
89

910
files = {
1011
'11p1lUw4pcj_xp1kPuKv3LO_cfcyYlnw_', 'bodyCoil.dat'
1112
'12sYtd-KfkZYM8IBzg_DGXsxT3n_uHSLf', 'brainScan.dat'
1213
'1dd8I74Hy4Hb97SF-fHBIkrZP_JzwpMa0', 'surfaceCoil.dat'
1314
};
1415

15-
opts = weboptions('Timeout', 120);
16-
1716
for i = 1:size(files,1)
1817
fileId = files{i,1};
19-
outFile = fullfile(scriptDir, files{i,2});
20-
url = sprintf('https://drive.google.com/uc?export=download&id=%s', fileId);
18+
outFile = files{i,2};
19+
20+
fprintf('%s\n', outFile);
21+
22+
cmd = buildDownloadCommand(fileId, outFile);
2123

22-
fprintf('%s\n', files{i,2});
24+
[status, out] = system(cmd);
2325

24-
try
25-
websave(outFile, url, opts);
26+
if status == 0 && exist(outFile,'file')
2627
fprintf(' ✓ done\n');
27-
catch ME
28-
fprintf(' ✗ failed: %s\n', ME.message);
28+
else
29+
fprintf(' ✗ failed\n');
30+
disp(out);
2931
end
3032
end
3133

3234
fprintf('\nAll downloads completed.\n');
3335
end
36+
37+
38+
function cmd = buildDownloadCommand(fileId, outFile)
39+
%BUILD DOWNLOAD COMMAND FOR CURRENT OS
40+
41+
url = sprintf( ...
42+
'https://drive.usercontent.google.com/download?id=%s&confirm=xxx', ...
43+
fileId);
44+
45+
if ispc
46+
% Windows: curl is available by default (Win10+)
47+
cmd = sprintf('curl -L "%s" -o "%s"', url, outFile);
48+
else
49+
% macOS / Linux
50+
cmd = sprintf('curl -L "%s" -o "%s"', url, outFile);
51+
end
52+
end

0 commit comments

Comments
 (0)