76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Downloads the official VLC for Windows x64 zip and unpacks it into
|
|
* tools/packaging/bundled-vlc/win64/ (vlc.exe at the root of that folder).
|
|
* Used by make-kiratv-windows-nsis.mjs so the NSIS installer ships VLC in resources/vlc.
|
|
*
|
|
* GPL-2.0+ applies to VLC; see https://www.videolan.org/legal.html
|
|
*/
|
|
import { execSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const root = path.resolve(__dirname, '..', '..');
|
|
const destDir = path.join(root, 'tools', 'packaging', 'bundled-vlc', 'win64');
|
|
const VLC_VERSION = '3.0.21';
|
|
const zipName = `vlc-${VLC_VERSION}-win64.zip`;
|
|
const zipUrl = `https://get.videolan.org/vlc/${VLC_VERSION}/win64/${zipName}`;
|
|
|
|
const force = process.argv.includes('--force');
|
|
const vlcExe = path.join(destDir, 'vlc.exe');
|
|
|
|
if (!force && fs.existsSync(vlcExe)) {
|
|
console.log('VLC bundle already present:', vlcExe);
|
|
console.log('Use --force to re-download.');
|
|
process.exit(0);
|
|
}
|
|
|
|
const tmpParent = path.join(root, 'tmp');
|
|
fs.mkdirSync(tmpParent, { recursive: true });
|
|
const tmpRoot = fs.mkdtempSync(path.join(tmpParent, 'vlc-dl-'));
|
|
const zipPath = path.join(tmpRoot, zipName);
|
|
const extractDir = path.join(tmpRoot, 'extracted');
|
|
|
|
try {
|
|
console.log('Downloading', zipUrl);
|
|
const res = await fetch(zipUrl, { redirect: 'follow' });
|
|
if (!res.ok) {
|
|
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
}
|
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
fs.writeFileSync(zipPath, buf);
|
|
|
|
fs.mkdirSync(extractDir, { recursive: true });
|
|
if (process.platform === 'win32') {
|
|
execSync(`tar -xf "${zipPath}" -C "${extractDir}"`, {
|
|
stdio: 'inherit',
|
|
shell: true,
|
|
});
|
|
} else {
|
|
execSync(`unzip -o -q "${zipPath}" -d "${extractDir}"`, {
|
|
stdio: 'inherit',
|
|
});
|
|
}
|
|
|
|
const top = fs.readdirSync(extractDir, { withFileTypes: true });
|
|
const innerDir = top.find((e) => e.isDirectory());
|
|
if (!innerDir) {
|
|
throw new Error('Unexpected zip layout: no top-level directory');
|
|
}
|
|
const innerPath = path.join(extractDir, innerDir.name);
|
|
const innerVlc = path.join(innerPath, 'vlc.exe');
|
|
if (!fs.existsSync(innerVlc)) {
|
|
throw new Error('Unexpected zip layout: vlc.exe not found under ' + innerPath);
|
|
}
|
|
|
|
fs.rmSync(destDir, { recursive: true, force: true });
|
|
fs.mkdirSync(path.dirname(destDir), { recursive: true });
|
|
fs.cpSync(innerPath, destDir, { recursive: true });
|
|
|
|
console.log('VLC extracted to', destDir);
|
|
} finally {
|
|
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
}
|