1- import path from 'path' ;
2- import fs from 'fs' ;
3- import unzipper from 'unzipper' ;
1+ const path = require ( 'path' ) ;
2+ const fs = require ( 'fs' ) ;
3+ const unzipper = require ( 'unzipper' ) ;
4+ const fetch = require ( 'node-fetch' ) ;
45
56const MAC_FFMPEG_ARM_URL = 'https://evermeet.cx/ffmpeg/ffmpeg-121955-g413346bd06.zip' ;
67const MAC_FFPROBE_ARM_URL = 'https://evermeet.cx/ffmpeg/ffprobe-121955-g413346bd06.zip' ;
@@ -21,5 +22,43 @@ function getOutputPath(platform, arch) {
2122}
2223
2324async function downloadAndExtract ( url , outputPath ) {
25+ const res = await fetch ( url ) ;
26+ if ( ! res . ok ) {
27+ throw new Error ( `Failed to download from ${ url } : ${ res . statusText } ` ) ;
28+ }
29+
30+ await new Promise ( ( resolve , reject ) => {
31+ res . body
32+ . pipe ( unzipper . Extract ( { path : outputPath } ) )
33+ . on ( 'close' , resolve )
34+ . on ( 'error' , reject ) ;
35+ } ) ;
36+ }
37+
38+ async function main ( ) {
39+ const platform = process . platform ;
40+ const arch = process . arch ;
41+
42+ const url = getDownloadUrl ( platform , arch ) ;
43+ const outputPath = getOutputPath ( platform , arch ) ;
2444
45+ if ( ! url || ! outputPath ) {
46+ console . log ( `No prebuilt binaries available for ${ platform } ${ arch } . Skipping download.` ) ;
47+ return ;
48+ }
49+ if ( ! fs . existsSync ( outputPath ) ) {
50+ fs . mkdirSync ( outputPath , { recursive : true } ) ;
51+ }
52+
53+ console . log ( `Downloading ffmpeg from ${ url . ffmpeg } ...` ) ;
54+ await downloadAndExtract ( url . ffmpeg , outputPath ) ;
55+ console . log ( `Downloading ffprobe from ${ url . ffprobe } ...` ) ;
56+ await downloadAndExtract ( url . ffprobe , outputPath ) ;
57+
58+ console . log ( `ffmpeg and ffprobe have been set up at ${ outputPath } ` ) ;
2559}
60+
61+ main ( ) . catch ( ( err ) => {
62+ console . error ( 'Error during setup:' , err ) ;
63+ process . exit ( 1 ) ;
64+ } ) ;
0 commit comments