Skip to content

Commit 060f046

Browse files
chore(get): factor out ffmpeg download logic (#1021)
### Description of Changes - Factor out FFmpeg download logic
1 parent 8398ad0 commit 060f046

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ nwbuild({
294294
- chore(cli): migrate from `yargs` to `commander`
295295
- chore(get): verify sha checksum for downloads
296296
- chore(util): factor out file paths as constant variables
297-
- chore(get): factor out ffmpeg downloader
298297
- chore(get): factor out node headers downloader
299298
- chore(bld): factor out core build step
300299
- chore(bld): factor out linux config

src/get/ffmpeg.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import path from "node:path";
2+
3+
import request from "./request.js";
4+
5+
/**
6+
* Download community FFmpeg binary from `https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt`.
7+
*
8+
* @param {string} downloadUrl - Download server
9+
* @param {string} version - Runtime version
10+
* @param {string} platform - NW supported platform
11+
* @param {string} arch - NW supported architecture
12+
* @param {string} cacheDir - Directory to store FFmpeg binary
13+
* @return {Promise<string>} Path of compressed file which containscommunity FFmpeg binary.
14+
*/
15+
export default async function ffmpeg(downloadUrl, version, platform, arch, cacheDir) {
16+
17+
/**
18+
* URL to download specific FFmpeg binary from.
19+
*
20+
* @type {string}
21+
*/
22+
const url = [
23+
downloadUrl,
24+
version,
25+
`${version}-${platform}-${arch}.zip`,
26+
].join('/');
27+
28+
/**
29+
* Absolute path of compressed file which contains FFmpeg binary.
30+
*/
31+
const ffmpegFileAbs = path.resolve(
32+
cacheDir,
33+
`ffmpeg-${version}-${platform}-${arch}.zip`,
34+
);
35+
await request(url, ffmpegFileAbs);
36+
37+
return ffmpegFileAbs;
38+
}

src/get/ffmpeg.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import fs from "node:fs";
2+
import process from "node:process";
3+
4+
import { afterEach, describe, expect, it } from "vitest";
5+
6+
import util from "../util.js";
7+
8+
import ffmpeg from "./ffmpeg.js";
9+
10+
describe("get/ffmpeg", function () {
11+
12+
let ffmpegFile = '';
13+
14+
afterEach(function () {
15+
fs.promises.rm(ffmpegFile, { recursive: true, force: true });
16+
});
17+
18+
it("downloades community prebuild FFmpeg for specifc platform", async function () {
19+
ffmpegFile = await ffmpeg(
20+
"https://github.com/nwjs-ffmpeg-prebuilt/nwjs-ffmpeg-prebuilt/releases/download",
21+
"0.83.0",
22+
util.PLATFORM_KV[process.platform],
23+
util.ARCH_KV[process.arch],
24+
"./test/fixture"
25+
);
26+
expect(util.fileExists(ffmpegFile)).resolves.toBe(true);
27+
}, Infinity);
28+
});

0 commit comments

Comments
 (0)