Skip to content

Commit

Permalink
V 2.1.0
Browse files Browse the repository at this point in the history
Multiplatform support, from this version Stickerworld works on windows, linux and mac

It is recommended to download and start the project from 0
  • Loading branch information
kaiserdj committed May 28, 2021
1 parent 55385d3 commit d39d18f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 131 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ logs
tokens
session
temp
package-lock.json
ffmpeg
package-lock.json
78 changes: 6 additions & 72 deletions lib/ffmpeg.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,9 @@
const tools = require("./tools");
const config = require("../config.json");
const fs = require('fs');
const Zip = require('node-7z');
const Zipath = require("7zip-bin");
const ffmpeg_ = require("fluent-ffmpeg");

async function download() {
let url;
switch (process.platform) {
case "win32":
tools.conlog_info('The windows version of ffmpeg will be downloaded');

url = 'https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.7z';

tools.conlog_info('Starting ffmpeg.zip download');

await tools.download(url, './temp/ffmpeg.7z', "ffmpeg.exe");

tools.conlog_info("Download completed");
tools.conlog_info("Starting ffmpeg.exe extract");

return await new Promise((resolve, reject) => {
let files = [];
const extract = Zip.extractFull('./temp/ffmpeg.7z', './temp/', {
$progress: true,
$bin: Zipath.path7za,
recursive: true,
$cherryPick: ['ffmpeg.exe', 'ffprobe.exe']
});
extract.on('data', data => files.push(data));
extract.on('end', async () => {
if (!fs.existsSync("./ffmpeg")) {
fs.mkdirSync("./ffmpeg");
}

files.forEach(async file => {
if (file.status === "extracted") {
if (config.debug) {
console.log(file);
}

let filename = file.file.split("/").slice(-1)[0];

await tools.renameFile(`./temp/${file.file}`, `./ffmpeg/${filename}`, async (err) => {
if (err) {
reject(err);
}
});
tools.conlog_info(`File ${filename} successfully extracted`);
}
});
resolve("Extract completed");
});
extract.on('error', (err) => {
reject(err);
});
})
break;
case "linux":
url = "";
break;
case "darwin":
// https://evermeet.cx/ffmpeg/#api-download
url = "";
break;
}
};
const ffmpegPath = require('@ffmpeg-installer/ffmpeg').path;
const ffprobePath = require('@ffprobe-installer/ffprobe').path;

async function ffprobe(file) {
ffmpeg_.setFfprobePath('./ffmpeg/ffprobe.exe');
ffmpeg_.setFfprobePath(ffprobePath);
return new Promise((resolve, reject) => {
ffmpeg_.ffprobe(file, (err, metadata) => {
if (err) {
Expand All @@ -82,7 +17,7 @@ async function ffprobe(file) {
async function ffmpeg(file, save) {
return await new Promise((resolve, reject) => {
ffmpeg_(file)
.setFfmpegPath('./ffmpeg/ffmpeg.exe')
.setFfmpegPath(ffmpegPath)
.save(save)
.on('error', (err) => {
reject(err);
Expand All @@ -96,7 +31,7 @@ async function ffmpeg(file, save) {
async function ffmpeg_complex(file, inputOptions, complexFilter, outputOptions, save) {
return await new Promise((resolve, reject) => {
ffmpeg_(file)
.setFfmpegPath('./ffmpeg/ffmpeg.exe')
.setFfmpegPath(ffmpegPath)
.inputOptions(inputOptions)
.complexFilter(complexFilter)
.outputOptions(outputOptions)
Expand All @@ -113,7 +48,7 @@ async function ffmpeg_complex(file, inputOptions, complexFilter, outputOptions,
async function ffmpeg_options(file, inputOptions, outputOptions, save) {
return await new Promise((resolve, reject) => {
ffmpeg_(file)
.setFfmpegPath('./ffmpeg/ffmpeg.exe')
.setFfmpegPath(ffmpegPath)
.inputOptions(inputOptions)
.outputOptions(outputOptions)
.save(save)
Expand All @@ -127,7 +62,6 @@ async function ffmpeg_options(file, inputOptions, outputOptions, save) {
}

module.exports = {
download,
ffprobe,
ffmpeg,
ffmpeg_complex,
Expand Down
11 changes: 0 additions & 11 deletions lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ async function check() {
tools.conlog_info("Temp folder created");
}

if (!fs.existsSync("./ffmpeg")) {
tools.conlog_info_force("ffmpeg not detected");

let download = await ffmpeg.download();

tools.conlog_info(download);

tools.conlog_info("Deleting temporary files from the download");
await tools.cleanFileTemp("ffmpeg");
}

if (config.cleanTemp) {
tools.conlog_info("Cleaning Temp folder");

Expand Down
35 changes: 0 additions & 35 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const fs = require('fs');
const util = require('util');
const glob = require('fast-glob');
const crypto = require("crypto");
const Axios = require('axios');
const ProgressBar = require('progress');

const writeFile = util.promisify(fs.writeFile);
const readFile = util.promisify(fs.readFileSync);
Expand All @@ -28,38 +26,6 @@ async function cleanFileTemp(id) {

}

async function download(url, dir, name) {
const writer = fs.createWriteStream(dir);

const response = await Axios({
url,
method: 'GET',
responseType: 'stream'
});
const totalLength = response.headers['content-length'];

const progressBar = new ProgressBar(`-> Downloading ${name} [:bar] :percent :etas`, {
width: 40,
complete: '=',
incomplete: ' ',
renderThrottle: 16,
total: parseInt(totalLength)
});

response.data.on('data', (chunk) => {
progressBar.tick(chunk.length);
});

response.data.pipe(writer);

return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', (err) => {
reject(err);
});
});
}

function genId() {
return crypto.randomBytes(16).toString("hex");
}
Expand Down Expand Up @@ -94,7 +60,6 @@ module.exports = {
readFile,
renameFile,
cleanFileTemp,
download,
genId,
conlog_info,
conlog_info_force,
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stickerworld",
"version": "2.0.6",
"version": "2.1.0",
"main": "index.js",
"scripts": {
"start": "node index",
Expand Down Expand Up @@ -30,21 +30,20 @@
},
"homepage": "https://github.com/kaiserdj/Stickerworld",
"dependencies": {
"7zip-bin": "^5.1.0",
"async-constructor": "^0.4.9",
"@ffmpeg-installer/ffmpeg": "^1.0.20",
"@ffprobe-installer/ffprobe": "^1.1.0",
"async-constructor": "^0.4.14",
"axios": "^0.21.1",
"compress-images": "^1.9.8",
"compress-images": "^1.9.9",
"fast-glob": "^3.2.5",
"fluent-ffmpeg": "^2.1.2",
"i18next": "^19.9.1",
"i18next": "^20.3.1",
"is-valid-http-url": "^1.0.3",
"jimp": "0.16.1",
"mime-types": "^2.1.29",
"node-7z": "^2.1.2",
"progress": "^2.0.3",
"semver": "^7.3.4",
"sharp": "^0.27.2",
"venom-bot": "^3.0.8",
"mime-types": "^2.1.30",
"semver": "^7.3.5",
"sharp": "^0.28.3",
"venom-bot": "^3.0.17",
"winston": "^3.3.3"
}
}

0 comments on commit d39d18f

Please sign in to comment.