From da94b88e2556d9fa133ce57f5110e22c1fe55fa8 Mon Sep 17 00:00:00 2001 From: lucia7777 <38116582+qinatsu@users.noreply.github.com> Date: Fri, 26 Nov 2021 22:07:05 -0600 Subject: [PATCH] silly --- .gitignore | 1 + commands.js | 43 ++++++++++++++++ effects/0.js | 3 ++ effects/1.js | 3 ++ effects/10.js | 4 ++ effects/2.js | 3 ++ effects/3.js | 3 ++ effects/4.js | 4 ++ effects/5.js | 4 ++ effects/6.js | 4 ++ effects/7.js | 4 ++ effects/8.js | 4 ++ effects/9.255.prog.js | 4 ++ effects/9.js | 4 ++ effects/prog.js | 4 ++ index.js | 111 ++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 203 insertions(+) create mode 100644 .gitignore create mode 100644 commands.js create mode 100644 effects/0.js create mode 100644 effects/1.js create mode 100644 effects/10.js create mode 100644 effects/2.js create mode 100644 effects/3.js create mode 100644 effects/4.js create mode 100644 effects/5.js create mode 100644 effects/6.js create mode 100644 effects/7.js create mode 100644 effects/8.js create mode 100644 effects/9.255.prog.js create mode 100644 effects/9.js create mode 100644 effects/prog.js create mode 100644 index.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b1960e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +output/ \ No newline at end of file diff --git a/commands.js b/commands.js new file mode 100644 index 0000000..4eec50b --- /dev/null +++ b/commands.js @@ -0,0 +1,43 @@ +module.exports = [{ + option: '-file', + aliases: ['-f', '-input', '-i'], + description: 'File that will be used.', + displayArgs: '[path]', + requiresArgs: true, + setVar: 'file' +}, { + option: '-output', + aliases: ['-o', '-out'], + description: 'Output file.', + displayArgs: '[path]', + requiresArgs: true, + setVar: 'output' +}, { + option: '-effect', + aliases: ['-fx', '-code', '-e', '-ef'], + description: 'Effect that will be applied to the file. For a list of effects, use -effects', + displayArgs: '[effect]', + requiresArgs: true, + setVar: 'effect' +}, { + option: '-start', + aliases: ['-s'], + description: 'Where the effect will start to be applied (in bytes), evaled. This is very influential to the result, be sure to change it if you\'re not happy with it. Defaults to 5000', + displayArgs: '[path]', + requiresArgs: true, + setVar: 'start' +}, { + option: '-end', + aliases: [], + description: 'Where the effect will stop being applied (in bytes), evaled. This is very influential to the result, be sure to change it if you\'re not happy with it. Defaults to the video size minus 1/12 of itself in bytes.', + displayArgs: '[path]', + requiresArgs: true, + setVar: 'end' +}, { + option: '-effects', + aliases: ['-fxs', '-l'], + description: 'List of all effects in ./effects with a description if they have any.', + displayArgs: '', + requiresArgs: false, + setVar: 'effects' +}]; \ No newline at end of file diff --git a/effects/0.js b/effects/0.js new file mode 100644 index 0000000..27ea154 --- /dev/null +++ b/effects/0.js @@ -0,0 +1,3 @@ +module.exports = (byte, prev) => { + return (((((prev - byte) + 22) >> 3) + 11)/3) + prev || (prev << byte) ; +}; \ No newline at end of file diff --git a/effects/1.js b/effects/1.js new file mode 100644 index 0000000..5f4bd66 --- /dev/null +++ b/effects/1.js @@ -0,0 +1,3 @@ +module.exports = (byte, prev) => { + return ((((byte + prev - 5) / 6)) - 7) * 3; +}; \ No newline at end of file diff --git a/effects/10.js b/effects/10.js new file mode 100644 index 0000000..9cc3286 --- /dev/null +++ b/effects/10.js @@ -0,0 +1,4 @@ +// chunk[chunk.length-i] +module.exports = (byte, prev, chunk, i) => { + return chunk[chunk.length-i] +} \ No newline at end of file diff --git a/effects/2.js b/effects/2.js new file mode 100644 index 0000000..bddff12 --- /dev/null +++ b/effects/2.js @@ -0,0 +1,3 @@ +module.exports = (byte, prev) => { + return (byte > 50 ? (((byte - 5) * 2) + 2) * (prev > 6 ? prev + 2 : prev) : (((byte + 5)) * 3) + (prev > 6 ? prev / 2 : prev)) / 3 +}; \ No newline at end of file diff --git a/effects/3.js b/effects/3.js new file mode 100644 index 0000000..43a27fc --- /dev/null +++ b/effects/3.js @@ -0,0 +1,3 @@ +module.exports = (byte, prev) => { + return (((prev + 22) / 2) - 5) - byte; +} \ No newline at end of file diff --git a/effects/4.js b/effects/4.js new file mode 100644 index 0000000..dd4f729 --- /dev/null +++ b/effects/4.js @@ -0,0 +1,4 @@ +// math.sin and other stuff with next bytes +module.exports = (byte, prev, chunk, i) => { + return (((Math.floor(Math.sin(prev) * 70) + byte)) + prev) + chunk[i+4]; +}; \ No newline at end of file diff --git a/effects/5.js b/effects/5.js new file mode 100644 index 0000000..8a19e8b --- /dev/null +++ b/effects/5.js @@ -0,0 +1,4 @@ +// funny stuff with bytes next to the current one +module.exports = (byte, prev, chunk, i) => { + return (chunk[i+1] + chunk[i+2] + chunk[i+3] + chunk[i+9] + random(10)) - chunk[i] - 200 / (random(2) == 2 ? 2 : 3) + ((Math.sin((prog-100) % 360)*100)); +} \ No newline at end of file diff --git a/effects/6.js b/effects/6.js new file mode 100644 index 0000000..9987e9d --- /dev/null +++ b/effects/6.js @@ -0,0 +1,4 @@ +// does a lot of stuff with next and previous bytes depending on the current one +module.exports = (byte, prev, chunk, i) => { + return byte < 127 ? (chunk[i*10]) || (byte - (prog % 21)) || byte : byte > 55 ? byte == 33 ? chunk[i-10] || 127 : prev + 11 : 0; +} \ No newline at end of file diff --git a/effects/7.js b/effects/7.js new file mode 100644 index 0000000..5d8fd9c --- /dev/null +++ b/effects/7.js @@ -0,0 +1,4 @@ +// if byte is more than 127 return 255, otherwise just return the byte +module.exports = (byte) => { + return byte > 127 ? 255 : byte; +}; \ No newline at end of file diff --git a/effects/8.js b/effects/8.js new file mode 100644 index 0000000..77d32d9 --- /dev/null +++ b/effects/8.js @@ -0,0 +1,4 @@ +// returns a random byte up to 6 +module.exports = (byte, prev, chunk, i) => { + return random(6); +}; \ No newline at end of file diff --git a/effects/9.255.prog.js b/effects/9.255.prog.js new file mode 100644 index 0000000..a6078c8 --- /dev/null +++ b/effects/9.255.prog.js @@ -0,0 +1,4 @@ +// if byte is the same as the previous return prog, otherwise return the byte inverted (-255) +module.exports = (byte, prev) => { + return byte === prev ? prog : 255-byte +} \ No newline at end of file diff --git a/effects/9.js b/effects/9.js new file mode 100644 index 0000000..c3fb4f5 --- /dev/null +++ b/effects/9.js @@ -0,0 +1,4 @@ +// if byte is the same as the previous return 0, otherwise return the byte +module.exports = (byte, prev) => { + return byte === prev ? 0 : byte +} \ No newline at end of file diff --git a/effects/prog.js b/effects/prog.js new file mode 100644 index 0000000..eb6c1e7 --- /dev/null +++ b/effects/prog.js @@ -0,0 +1,4 @@ +// byte + prog +module.exports = (byte) => { + return byte + prog; +} \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..37e6b1f --- /dev/null +++ b/index.js @@ -0,0 +1,111 @@ +const fs = require('fs'); +const commands = require('./commands'); + +const err = (msg) => { + console.error(msg); + process.exit(); +} +const displayHelp = (m='') => { + console.log(`${m}\nHelp:\n${commands.sort((a,b) => (a.option > b.option) ? 1 : ((b.option > a.option) ? -1 : 0)) + .map(cmd => `\t${cmd.option} ${cmd.requiresArgs ? cmd.displayArgs + ' ' : ''}- ${cmd.description}`).join('\n')}`); + process.exit(); +} +if(process.argv.length <= 2) { + displayHelp('Too few arguments.') +} else { + let argsObj = {}; + process.argv.forEach((arg, i) => { + let argument = arg.toLowerCase(); + let command = commands.find(command => (command.option === argument) || (command.aliases.indexOf(argument) !== -1)); + if(command) { + if(command.requiresArgs) { + if(process.argv[i+1] ? process.argv[i+1].startsWith('-') : true) { + argsObj[command.setVar] = null; + } else { + argsObj[command.setVar] = process.argv[i+1] || null; + } + } else { + argsObj[command.setVar] = true; + } + } + }) + + const effectsPath = './effects/'; + + if(argsObj.effects) { + let effects = fs.readdirSync(effectsPath).map(dir => { + let firstLine = fs.readFileSync(effectsPath + dir, 'utf8').split('\n')[0]; + let effName = dir.split('.'); + effName.pop(); + effName = effName.join('.'); + if(firstLine.startsWith('// ')) { + firstLine = firstLine.slice(3); + return `${effName} - ${firstLine}`; + } else return `${effName} - move the bytes all arround, no specific effect desired`; + }); + console.log(effects.join('\n')); + process.exit(); + } + + global._buf = []; + global.readed = 0; + global.chunkI = 0; + global.prog = 0; // increments every time a byte is modified + global.MB = 1048576; + global.random = (lim=12) => Math.floor(Math.random() * lim); + + const file = argsObj.file; + const output = argsObj.output; + const effectName = argsObj.effect; + + if(!file) return err("Please provide a file to be used with -file."); + if(!output) return err("Please provide an output file with -output.") + if(!effectName) return err("Please provide an effect name or use -effects for a list of them."); + + let effect; + + try { + effect = require(effectsPath + effectName); + } catch(error) { + if(error.code === 'MODULE_NOT_FOUND') { + err(`Effect at "${effectsPath + effectName}" not found.`); + } else { + console.warn(err); + } + } + + const videoStat = fs.statSync(file); + const video = fs.createReadStream(file); + + const start = eval(argsObj.start) || 5000; + const end = eval(argsObj.end) || (videoStat.size - (Math.trunc(videoStat.size / 12))); + + const DownloadingProgress = (recieved, total) => { + process.stdout.write("\x1B[0G"); + process.stdout.write(`${Math.trunc(recieved/1e+6)}/${Math.trunc(total/1e+6)} megabytes modified (${recieved > start}, ${recieved < end}) `); + } + + console.log(`Starting (${videoStat.size} offsets ${start}-${end}) with effect ${effect} (effect name: ${effectName})`) + + video.on("data", (chunk) => { + let prev = 0; + readed+=chunk.length; + global.chunkI++; + if((readed > start) && (readed < end)) { + for(let byte of chunk.entries()) { + chunk[byte[0]] = effect(chunk[byte[0]], prev, chunk, byte[0]); + global.prog++; + prev = chunk[byte[0]] + } + } + _buf.push(chunk); + DownloadingProgress(readed, videoStat.size); + }); + video.on("end", () => { + let buff = Buffer.concat(_buf) + console.log(`\nWriting to ${output}...`) + fs.writeFileSync(output, buff); + console.log("Done"); + }); + video.on("error", (err) => reject(err)); +} \ No newline at end of file