Compare commits

..

2 Commits

Author SHA1 Message Date
amir 4cfc8774ce fix copy tag in reduce-bitrate by id3lib app 2026-05-14 21:14:01 +03:30
amir 3be3bed903 copy tags using a python script in reduce-bitrate 2026-05-14 21:08:58 +03:30
+25 -2
View File
@@ -52,6 +52,14 @@ get_bitrate_kbps() {
return 1
}
restore_metadata() {
local source_file="$1"
local target_file="$2"
id3cp "$source_file" "$target_file" >/dev/null 2>&1
return $?
}
process_file() {
local file="$1"
local current_bitrate
@@ -85,8 +93,18 @@ process_file() {
temp_file="${file%.mp3}_temp_$$.mp3"
if ffmpeg -nostdin -y -i "$file" -b:a "${TARGET_BITRATE}" -id3v2_version 3 "$temp_file" > /dev/null 2>&1; then
mv "$temp_file" "$file"
log_success "Converted: ${file} (${current_bitrate} kbps ➜ ${TARGET_BITRATE}) ✅"
((converted_count++))
# Restore all metadata from backup file
if restore_metadata "$backup_file" "$file"; then
log_success "Converted: ${file} (${current_bitrate} kbps ➜ ${TARGET_BITRATE}) ✅"
((converted_count++))
else
log_error "Metadata restoration failed: ${file}"
# Revert to backup since metadata restoration failed
cp "$backup_file" "$file"
log_warn "Reverted to backup (conversion skipped due to metadata error)"
((error_count++))
fi
else
rm -f "$temp_file"
log_error "ffmpeg failed: ${file}"
@@ -117,6 +135,11 @@ if ! command -v ffprobe >/dev/null 2>&1 || ! command -v ffmpeg >/dev/null 2>&1;
exit 1
fi
if ! command -v id3cp >/dev/null 2>&1; then
log_error "id3cp not found. Please install id3lib (Arch: id3lib, Debian/Ubuntu: libid3-tools)."
exit 1
fi
if [ ! -d "$ROOT_DIR" ]; then
log_error "Directory not found: ${ROOT_DIR}"
exit 1