Compare commits
2 Commits
defe2ef044
...
4cfc8774ce
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cfc8774ce | |||
| 3be3bed903 |
@@ -52,6 +52,14 @@ get_bitrate_kbps() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restore_metadata() {
|
||||||
|
local source_file="$1"
|
||||||
|
local target_file="$2"
|
||||||
|
|
||||||
|
id3cp "$source_file" "$target_file" >/dev/null 2>&1
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
process_file() {
|
process_file() {
|
||||||
local file="$1"
|
local file="$1"
|
||||||
local current_bitrate
|
local current_bitrate
|
||||||
@@ -85,8 +93,18 @@ process_file() {
|
|||||||
temp_file="${file%.mp3}_temp_$$.mp3"
|
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
|
if ffmpeg -nostdin -y -i "$file" -b:a "${TARGET_BITRATE}" -id3v2_version 3 "$temp_file" > /dev/null 2>&1; then
|
||||||
mv "$temp_file" "$file"
|
mv "$temp_file" "$file"
|
||||||
|
|
||||||
|
# Restore all metadata from backup file
|
||||||
|
if restore_metadata "$backup_file" "$file"; then
|
||||||
log_success "Converted: ${file} (${current_bitrate} kbps ➜ ${TARGET_BITRATE}) ✅"
|
log_success "Converted: ${file} (${current_bitrate} kbps ➜ ${TARGET_BITRATE}) ✅"
|
||||||
((converted_count++))
|
((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
|
else
|
||||||
rm -f "$temp_file"
|
rm -f "$temp_file"
|
||||||
log_error "ffmpeg failed: ${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
|
exit 1
|
||||||
fi
|
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
|
if [ ! -d "$ROOT_DIR" ]; then
|
||||||
log_error "Directory not found: ${ROOT_DIR}"
|
log_error "Directory not found: ${ROOT_DIR}"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user