ai-renamer
Advanced tools
Comparing version 1.0.22 to 1.0.23
{ | ||
"version": "1.0.22", | ||
"version": "1.0.23", | ||
"license": "GPL-3.0", | ||
@@ -23,2 +23,3 @@ "name": "ai-renamer", | ||
"pdf-parse": "^1.1.1", | ||
"uuid": "^10.0.0", | ||
"yargs": "^17.7.2" | ||
@@ -33,4 +34,6 @@ }, | ||
"ollama", | ||
"openai", | ||
"llama3", | ||
"cli-tool", | ||
"lm-studio", | ||
"automation", | ||
@@ -37,0 +40,0 @@ "file-renamer", |
@@ -20,3 +20,3 @@ # ai-renamer | ||
You need to have [Ollama](https://ollama.com/download) or [LM Studio](https://lmstudio.ai/) and at least one LLM (Llava, Gemma, Llama etc.) installed on your system | ||
You need to have [Ollama](https://ollama.com/download) or [LM Studio](https://lmstudio.ai/) and at least one LLM (Llava, Gemma, Llama etc.) installed on your system. You need to have [ffmpeg][https://www.ffmpeg.org/download.html] to rename videos. | ||
@@ -89,2 +89,4 @@ Run with NPX | ||
gpt-4o) [string] | ||
-f, --frames Set the maximum number of frames to extract from | ||
videos (e.g. 3, 5, 10) [number] | ||
-c, --case Set the case style (e.g. camelCase, pascalCase, | ||
@@ -91,0 +93,0 @@ snakeCase, kebabCase) [string] |
@@ -51,2 +51,7 @@ const os = require('os') | ||
}) | ||
.option('frames', { | ||
alias: 'f', | ||
type: 'number', | ||
description: 'Set the maximum number of frames to extract from videos (e.g. 3, 5, 10)' | ||
}) | ||
.option('case', { | ||
@@ -98,2 +103,7 @@ alias: 'c', | ||
if (argv.frames) { | ||
config.defaultFrames = argv.frames | ||
await saveConfig({ config }) | ||
} | ||
if (argv.case) { | ||
@@ -100,0 +110,0 @@ config.defaultCase = argv.case |
@@ -15,4 +15,6 @@ const fs = require('fs') | ||
if (images && images.length > 0) { | ||
const imageData = await fs.readFileSync(images[0]) | ||
data.images = [imageData.toString('base64')] | ||
data.images = await Promise.all(images.map(async imagePath => { | ||
const imageData = await fs.promises.readFile(imagePath) | ||
return imageData.toString('base64') | ||
})) | ||
} | ||
@@ -50,7 +52,9 @@ | ||
if (images && images.length > 0) { | ||
const imageData = await fs.readFileSync(images[0]) | ||
messages[0].content.push({ | ||
type: 'image_url', | ||
image_url: { url: `data:image/jpeg;base64,${imageData.toString('base64')}` } | ||
}) | ||
for (const imagePath of images) { | ||
const imageData = await fs.promises.readFile(imagePath) | ||
messages[0].content.push({ | ||
type: 'image_url', | ||
image_url: { url: `data:image/jpeg;base64,${imageData.toString('base64')}` } | ||
}) | ||
} | ||
} | ||
@@ -57,0 +61,0 @@ |
@@ -5,3 +5,3 @@ const changeCase = require('./changeCase') | ||
module.exports = async options => { | ||
const { _case, chars, content, language, relativeFilePath } = options | ||
const { _case, chars, content, language, videoPrompt, relativeFilePath } = options | ||
@@ -24,2 +24,6 @@ try { | ||
if (videoPrompt) { | ||
promptLines.unshift(videoPrompt, '') | ||
} | ||
if (content) { | ||
@@ -26,0 +30,0 @@ promptLines.push('', 'Content:', content) |
const path = require('path') | ||
const { v4: uuidv4 } = require('uuid') | ||
const isImage = require('./isImage') | ||
const isVideo = require('./isVideo') | ||
const saveFile = require('./saveFile') | ||
const getNewName = require('./getNewName') | ||
const extractFrames = require('./extractFrames') | ||
const readFileContent = require('./readFileContent') | ||
const deleteDirectory = require('./deleteDirectory') | ||
const isProcessableFile = require('./isProcessableFile') | ||
@@ -11,3 +15,3 @@ | ||
try { | ||
const { filePath, inputPath } = options | ||
const { frames, filePath, inputPath } = options | ||
@@ -26,5 +30,16 @@ const fileName = path.basename(filePath) | ||
let content | ||
const images = [] | ||
let videoPrompt | ||
let images = [] | ||
let framesOutputDir | ||
if (isImage({ ext })) { | ||
images.push(filePath) | ||
} else if (isVideo({ ext })) { | ||
framesOutputDir = `/tmp/ai-renamer/${uuidv4()}` | ||
const _extractedFrames = await extractFrames({ | ||
frames, | ||
framesOutputDir, | ||
inputFile: filePath | ||
}) | ||
images = _extractedFrames.images | ||
videoPrompt = _extractedFrames.videoPrompt | ||
} else { | ||
@@ -38,3 +53,3 @@ content = await readFileContent({ filePath }) | ||
const newName = await getNewName({ ...options, images, content, relativeFilePath }) | ||
const newName = await getNewName({ ...options, images, content, videoPrompt, relativeFilePath }) | ||
if (!newName) return | ||
@@ -45,2 +60,6 @@ | ||
console.log(`🟢 Renamed: ${relativeFilePath} to ${relativeNewFilePath}`) | ||
if (isVideo({ ext }) && framesOutputDir) { | ||
await deleteDirectory({ folderPath: framesOutputDir }) | ||
} | ||
} catch (err) { | ||
@@ -47,0 +66,0 @@ console.log(err.message) |
@@ -7,3 +7,3 @@ const fs = require('fs').promises | ||
module.exports = async ({ inputPath, defaultCase, defaultModel, defaultChars, defaultApiKey, defaultBaseURL, defaultLanguage, defaultProvider, defaultIncludeSubdirectories }) => { | ||
module.exports = async ({ inputPath, defaultCase, defaultModel, defaultChars, defaultFrames, defaultApiKey, defaultBaseURL, defaultLanguage, defaultProvider, defaultIncludeSubdirectories }) => { | ||
try { | ||
@@ -31,2 +31,5 @@ const provider = defaultProvider || 'ollama' | ||
const frames = defaultFrames || 3 | ||
console.log(`⚪ Frames: ${frames}`) | ||
const _case = defaultCase || 'kebabCase' | ||
@@ -51,2 +54,3 @@ console.log(`⚪ Case: ${_case}`) | ||
chars, | ||
frames, | ||
apiKey, | ||
@@ -53,0 +57,0 @@ baseURL, |
@@ -32,4 +32,7 @@ module.exports = [ | ||
// video files | ||
'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', | ||
// handled separately in code | ||
'.pdf' | ||
] |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
59652
20
611
125
5
8
1
+ Addeduuid@^10.0.0
+ Addeduuid@10.0.0(transitive)