|
1 | 1 | 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 |
4 | 4 |
|
5 | 5 | fprintf('Downloading tutorial data...\n'); |
6 | 6 |
|
7 | 7 | scriptDir = fileparts(mfilename('fullpath')); |
| 8 | + cd(scriptDir); |
8 | 9 |
|
9 | 10 | files = { |
10 | 11 | '11p1lUw4pcj_xp1kPuKv3LO_cfcyYlnw_', 'bodyCoil.dat' |
11 | 12 | '12sYtd-KfkZYM8IBzg_DGXsxT3n_uHSLf', 'brainScan.dat' |
12 | 13 | '1dd8I74Hy4Hb97SF-fHBIkrZP_JzwpMa0', 'surfaceCoil.dat' |
13 | 14 | }; |
14 | 15 |
|
15 | | - opts = weboptions('Timeout', 120); |
16 | | - |
17 | 16 | for i = 1:size(files,1) |
18 | 17 | 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); |
21 | 23 |
|
22 | | - fprintf('→ %s\n', files{i,2}); |
| 24 | + [status, out] = system(cmd); |
23 | 25 |
|
24 | | - try |
25 | | - websave(outFile, url, opts); |
| 26 | + if status == 0 && exist(outFile,'file') |
26 | 27 | fprintf(' ✓ done\n'); |
27 | | - catch ME |
28 | | - fprintf(' ✗ failed: %s\n', ME.message); |
| 28 | + else |
| 29 | + fprintf(' ✗ failed\n'); |
| 30 | + disp(out); |
29 | 31 | end |
30 | 32 | end |
31 | 33 |
|
32 | 34 | fprintf('\nAll downloads completed.\n'); |
33 | 35 | 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