Skip to content

Commit

Permalink
silly
Browse files Browse the repository at this point in the history
  • Loading branch information
littletsu committed Nov 27, 2021
0 parents commit da94b88
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output/
43 changes: 43 additions & 0 deletions commands.js
Original file line number Diff line number Diff line change
@@ -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'
}];
3 changes: 3 additions & 0 deletions effects/0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (byte, prev) => {
return (((((prev - byte) + 22) >> 3) + 11)/3) + prev || (prev << byte) ;
};
3 changes: 3 additions & 0 deletions effects/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (byte, prev) => {
return ((((byte + prev - 5) / 6)) - 7) * 3;
};
4 changes: 4 additions & 0 deletions effects/10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// chunk[chunk.length-i]
module.exports = (byte, prev, chunk, i) => {
return chunk[chunk.length-i]
}
3 changes: 3 additions & 0 deletions effects/2.js
Original file line number Diff line number Diff line change
@@ -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
};
3 changes: 3 additions & 0 deletions effects/3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (byte, prev) => {
return (((prev + 22) / 2) - 5) - byte;
}
4 changes: 4 additions & 0 deletions effects/4.js
Original file line number Diff line number Diff line change
@@ -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];
};
4 changes: 4 additions & 0 deletions effects/5.js
Original file line number Diff line number Diff line change
@@ -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));
}
4 changes: 4 additions & 0 deletions effects/6.js
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 4 additions & 0 deletions effects/7.js
Original file line number Diff line number Diff line change
@@ -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;
};
4 changes: 4 additions & 0 deletions effects/8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// returns a random byte up to 6
module.exports = (byte, prev, chunk, i) => {
return random(6);
};
4 changes: 4 additions & 0 deletions effects/9.255.prog.js
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions effects/9.js
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions effects/prog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// byte + prog
module.exports = (byte) => {
return byte + prog;
}
111 changes: 111 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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));
}

0 comments on commit da94b88

Please sign in to comment.