diff --git a/README.md b/README.md index 3d40643..7b0de98 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ No need to install other programs as ffmpeg-cli will download and extract necess ## Supported OS + MacOS ~ 64 bit + Linux ~ 32/64 bit -+ Windows ~ 32/64 bit ++ Windows ~ [~~32/~~](https://github.com/PotatoParser/ffmpeg-cli/issues/9)64 bit ## FFmpeg Path Returns the path of FFmpeg executable diff --git a/lib/download.js b/lib/download.js index 8eb3811..038f4fb 100644 --- a/lib/download.js +++ b/lib/download.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const https = require('https'); +const { https } = require('follow-redirects'); const tar = require('tar'); const AdmZip = require('adm-zip'); const lzma = require('lzma-native'); @@ -48,7 +48,7 @@ async function getPackage(){ if (fs.existsSync(system.typePath)) rimraf(system.typePath); if (!fs.existsSync(`${system.rootDir}/ffmpeg`)) fs.mkdirSync(`${system.rootDir}/ffmpeg`); var downloaded = await new Promise(resolve=>{ - https.get(system.url, res => { + https.get(system.url, {headers: {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'}}, res => { res.on('error', ()=>resolve(false)); res.pipe(fs.createWriteStream(system.zipPath)).on('finish', ()=>resolve(true)); let bar = console.bar(parseInt(res.headers['content-length'], 10)); @@ -62,8 +62,14 @@ async function getPackage(){ console.log('Unzipped files'); fs.unlinkSync(system.zipPath); - console.log('Renaming files'); - fs.renameSync(temp, system.typePath); + if (system.file) { + console.log('Moving files'); + fs.mkdirSync(system.typePath); + fs.renameSync(system.file, system.path); + } else { + console.log('Renaming files'); + fs.renameSync(system.dir, system.typePath); + } console.log('Applying chmod'); fs.readdirSync(system.pathDir, { withFileTypes: true }).forEach(f => { diff --git a/lib/system.js b/lib/system.js index 97b7142..89065db 100644 --- a/lib/system.js +++ b/lib/system.js @@ -3,37 +3,38 @@ const console = require('./console'); const rootDir = path.join(__dirname, '..'); const OS = process.platform; const BIT = process.arch; -if (!(BIT === 'x32' || BIT === 'x64')) error('CPU architecture not supported'); +if (!(BIT === 'x32' || BIT === 'x64')) console.error('CPU architecture not supported'); const allOS = { linux: { x32: { url: 'https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz', + dir: rootDir + '/ffmpeg/ffmpeg-4.3.1-amd64-static', path: rootDir + '/ffmpeg/linuxx32/ffmpeg' }, x64: { url: 'https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-i686-static.tar.xz', + dir: rootDir + '/ffmpeg/ffmpeg-4.3.1-i686-static', path: rootDir + '/ffmpeg/linuxx64/ffmpeg' } }, darwin: { x64: { - url: 'https://ffmpeg.zeranoe.com/builds/macos64/static/ffmpeg-4.2.2-macos64-static.zip', - path: rootDir + '/ffmpeg/darwinx64/bin/ffmpeg' + url: 'https://evermeet.cx/ffmpeg/ffmpeg-4.3.1.zip', + file: rootDir + '/ffmpeg/ffmpeg', + path: rootDir + '/ffmpeg/darwinx64/ffmpeg' } }, win32: { - x32: { - url: 'https://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.zip', - path: rootDir + '/ffmpeg/win32x32/bin/ffmpeg.exe' - }, x64: { - url: 'https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip', + url: 'https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2020-09-26-14-24/ffmpeg-n4.3.1-18-g6d886b6586-win64-gpl-4.3.zip', + dir: rootDir + '/ffmpeg/ffmpeg-n4.3.1-18-g6d886b6586-win64-gpl-4.3', path: rootDir + '/ffmpeg/win32x64/bin/ffmpeg.exe' } } } -if (allOS[OS] === undefined) console.error('OS not supporteds!'); -if (allOS[OS][BIT] === undefined) console.error('Invalid OS and CPU architecture!'); +if (!allOS[OS]) console.error('OS not supporteds!'); +if (!allOS[OS][BIT]) console.error('Invalid OS and CPU architecture!'); + module.exports = Object.assign({}, allOS[OS][BIT]); module.exports.typePath = path.normalize(rootDir + '/ffmpeg/' + OS + BIT); module.exports.zipPath = path.normalize(rootDir + '/ffmpeg/' + module.exports.url.substring(module.exports.url.lastIndexOf('/')+1)); diff --git a/package-lock.json b/package-lock.json index 6beb0e4..26db5e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ffmpeg-cli", - "version": "2.5.2", + "version": "2.6.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -87,6 +87,11 @@ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" }, + "follow-redirects": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==" + }, "fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", diff --git a/package.json b/package.json index f272e54..189a108 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ffmpeg-cli", - "version": "2.5.2", + "version": "2.6.0", "description": "ffmpeg with support for multiple OSs", "main": "./lib/index.js", "scripts": { @@ -27,6 +27,7 @@ "homepage": "https://github.com/PotatoParser/ffmpeg-cli#readme", "dependencies": { "adm-zip": "^0.4.14", + "follow-redirects": "^1.13.0", "lzma-native": "^5.0.1", "progress": "^2.0.3", "tar": "^6.0.2"