-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit da94b88
Showing
16 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (byte, prev) => { | ||
return (((prev + 22) / 2) - 5) - byte; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// byte + prog | ||
module.exports = (byte) => { | ||
return byte + prog; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |