testsAndMisc/linux_configuration/misc/convert.sh
Krzysztof kuhy Rudnicki 08aac8d7d1 Flatten i3-configuration and misc/testsAndMisc-bash
i3 config was filed under periodic_background, which it never was. It is
now linux_configuration/i3/ (config + installer) and
linux_configuration/i3blocks/ (the status scripts), both at depth 2.

misc/testsAndMisc-bash/ was a directory named after the repo it already
lived in, so its contents moved up to misc/. Its stray .gitignore came
along, keeping the media rules working from the new location; its
.vscode/tasks.json did not, because it invoked Bash/transcribe.sh, a path
this repo dropped long ago.

Most of this commit is the references the previous flatten missed. Its
regex skipped anything with a variable prefix, which left 16 files --
including check_and_enable_services.sh and install_core_system.sh, the
orchestrators -- still naming $CONFIG_DIR/scripts/periodic_background/...
It had also rewritten three i3 paths into scripts/i3blocks/, a directory
that has never existed; the i3blocks suites caught that by failing.

13 more symlinks broke on the i3 move. Repointed, and cpu_monitor/volume/
disk were run again to confirm the bar still reports.

Depth 139 -> 104. Roughly 47 of the remainder sit in digital_wellbeing
and hosts, still deferred. The rest encode real structure -- a C project,
Python package directories, artgate's routes/styles, systemd unit dirs --
so flattening them further would destroy information rather than
taxonomy.

Verified: 1798 tests at 100%, both i3blocks suites pass, the shell
coverage gate is clean, and the relocated media rules still ignore what
they should while test_fw.srt stays tracked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 19:02:18 +02:00

87 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Default values
TARGET_EXT="mp4"
TARGET_SIZE=10M
# Parse arguments
if [ -n "$1" ]; then
INPUT_PATH="$1"
else
INPUT_PATH="."
fi
if [ -n "$2" ]; then
TARGET_EXT="$2"
fi
if [ -n "$3" ]; then
TARGET_SIZE="$3"
fi
# Create output directory
OUTPUT_DIR="converted"
mkdir -p "$OUTPUT_DIR"
# Function to convert video
convert_video() {
local input_file="$1"
local output_file="$OUTPUT_DIR/${input_file%.*}.$TARGET_EXT"
# Get video duration in seconds
DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$input_file")
echo "Duration: $DURATION seconds"
# Convert target size to bytes
TARGET_SIZE_BYTES=$(numfmt --from=iec "$TARGET_SIZE")
# Calculate target bitrate in kilobits per second
TARGET_BITRATE=$(echo "($TARGET_SIZE_BYTES * 8) / $DURATION / 2000" | bc)
# Convert video
ffmpeg -i "$input_file" -vcodec libx264 -b:v "${TARGET_BITRATE}k" -preset veryslow -acodec aac -c:a copy "$output_file"
# Get original and converted video sizes
ORIGINAL_SIZE=$(stat -c%s "$input_file")
CONVERTED_SIZE=$(stat -c%s "$output_file")
# Print out details
echo "Original size: $(numfmt --to=iec "$ORIGINAL_SIZE")"
echo "Video length: $DURATION seconds"
echo "Target size: $TARGET_SIZE"
echo "Converted size: $(numfmt --to=iec "$CONVERTED_SIZE")"
echo "Target bitrate: ${TARGET_BITRATE}kbps"
}
# Function to move video if already below target size and in desired format
move_video() {
local input_file="$1"
local output_file="$OUTPUT_DIR/${input_file##*/}"
# Get original video size
ORIGINAL_SIZE=$(stat -c%s "$input_file")
# Check if video is below target size and in desired format
if [[ $ORIGINAL_SIZE -le $TARGET_SIZE_BYTES && ${input_file##*.} == "$TARGET_EXT" ]]; then
mv "$input_file" "$output_file"
echo "Moved $input_file to $output_file"
else
convert_video "$input_file"
fi
}
# Export functions for find command
export -f convert_video
export -f move_video
export TARGET_EXT
export TARGET_SIZE
export TARGET_SIZE_BYTES
export OUTPUT_DIR
# Find and process videos
if [ -d "$INPUT_PATH" ]; then
find "$INPUT_PATH" \( -name "*.mkv" -o -name "*.mp4" -o -name "*.avi" -o -name "*.webm" \) -type f -exec bash -c 'move_video "$0"' {} \;
else
move_video "$INPUT_PATH"
fi