script-mode task execution — database-backed tasks with direct script runner
Tasks now live in the database (mode: script or agentic). Script-mode tasks bypass the agent entirely — the implementation is materialized to a temp file and executed directly, with stdout/stderr streamed to the UI via WebSocket. Includes convert-to-mp3 as the first native script task. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
---
|
||||
name: Convert To MP3
|
||||
description: Convert audio files to MP3 320kbps, preserving metadata.
|
||||
version: 1
|
||||
mode: script
|
||||
language: bash
|
||||
triggers:
|
||||
- type: file
|
||||
extensions:
|
||||
- flac
|
||||
- wav
|
||||
- ogg
|
||||
- wma
|
||||
- aac
|
||||
- m4a
|
||||
- opus
|
||||
- aiff
|
||||
- aif
|
||||
- ape
|
||||
- wv
|
||||
- alac
|
||||
- dsf
|
||||
- dff
|
||||
- type: directory
|
||||
inputs:
|
||||
file_path:
|
||||
type: string
|
||||
description: Path to an audio file or directory to convert.
|
||||
args: [file_path]
|
||||
---
|
||||
|
||||
# Convert To MP3
|
||||
|
||||
Convert audio files to MP3 320kbps using ffmpeg, preserving metadata.
|
||||
Supports single file conversion and batch directory conversion.
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Accepts path as $1 or $INPUT_FILE_PATH
|
||||
TARGET="${1:-${INPUT_FILE_PATH:-}}"
|
||||
|
||||
if [[ -z "$TARGET" ]]; then
|
||||
echo "Error: No file or directory path provided" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -e "$TARGET" ]]; then
|
||||
echo "Error: Path does not exist: $TARGET" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
convert_file() {
|
||||
local input="$1"
|
||||
local ext="${input##*.}"
|
||||
local dir
|
||||
dir="$(dirname "$input")"
|
||||
local base
|
||||
base="$(basename "$input" ".$ext")"
|
||||
local output="$dir/$base.mp3"
|
||||
|
||||
if [[ "${ext,,}" == "mp3" ]]; then
|
||||
echo "Skipping (already MP3): $input"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -f "$output" ]]; then
|
||||
echo "Skipping (output exists): $output"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Converting: $input → $output"
|
||||
ffmpeg -i "$input" -codec:a libmp3lame -b:a 320k -map_metadata 0 -id3v2_version 3 -y "$output" 2>/dev/null
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo " ✓ Done"
|
||||
else
|
||||
echo " ✗ Failed" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
AUDIO_EXTS="flac|wav|ogg|wma|aac|m4a|opus|aiff|aif|ape|wv|alac|dsf|dff"
|
||||
converted=0
|
||||
failed=0
|
||||
|
||||
if [[ -f "$TARGET" ]]; then
|
||||
if convert_file "$TARGET"; then
|
||||
converted=$((converted + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
fi
|
||||
elif [[ -d "$TARGET" ]]; then
|
||||
while IFS= read -r -d '' file; do
|
||||
if convert_file "$file"; then
|
||||
converted=$((converted + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
fi
|
||||
done < <(find "$TARGET" -type f -regextype posix-extended -iregex ".*\.($AUDIO_EXTS)" -print0 | sort -z)
|
||||
|
||||
if [[ $converted -eq 0 && $failed -eq 0 ]]; then
|
||||
echo "No audio files found in: $TARGET"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
echo "Error: Not a file or directory: $TARGET" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Summary: $converted converted, $failed failed"
|
||||
Reference in New Issue
Block a user