fix copy tag in reduce-bitrate by id3lib app
This commit is contained in:
@@ -1,46 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Copy all ID3 tags from source file to target file, preserving multi-value fields.
|
|
||||||
Requires: python-mutagen
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
from mutagen.id3 import ID3, ID3NoHeaderError
|
|
||||||
|
|
||||||
def copy_id3_tags(source_path, target_path):
|
|
||||||
"""Copy all ID3 tags from source to target file."""
|
|
||||||
try:
|
|
||||||
# Load source tags
|
|
||||||
source_tags = ID3(source_path)
|
|
||||||
|
|
||||||
# Load or create target tags
|
|
||||||
try:
|
|
||||||
target_tags = ID3(target_path)
|
|
||||||
except ID3NoHeaderError:
|
|
||||||
target_tags = ID3()
|
|
||||||
|
|
||||||
# Clear all existing tags in target
|
|
||||||
target_tags.clear()
|
|
||||||
|
|
||||||
# Copy all frames from source to target
|
|
||||||
for key, value in source_tags.items():
|
|
||||||
target_tags[key] = value
|
|
||||||
|
|
||||||
# Save to target file
|
|
||||||
target_tags.save(target_path, v2_version=3)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error copying tags: {e}", file=sys.stderr)
|
|
||||||
return 1
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
if len(sys.argv) != 3:
|
|
||||||
print("Usage: copy_id3_tags.py <source_file> <target_file>", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
source = sys.argv[1]
|
|
||||||
target = sys.argv[2]
|
|
||||||
|
|
||||||
sys.exit(copy_id3_tags(source, target))
|
|
||||||
+3
-6
@@ -55,11 +55,8 @@ get_bitrate_kbps() {
|
|||||||
restore_metadata() {
|
restore_metadata() {
|
||||||
local source_file="$1"
|
local source_file="$1"
|
||||||
local target_file="$2"
|
local target_file="$2"
|
||||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
|
|
||||||
# Use Python script with mutagen to properly copy all ID3 tags including multi-value fields
|
|
||||||
"$script_dir/copy_id3_tags.py" "$source_file" "$target_file" 2>/dev/null
|
|
||||||
|
|
||||||
|
id3cp "$source_file" "$target_file" >/dev/null 2>&1
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,8 +135,8 @@ if ! command -v ffprobe >/dev/null 2>&1 || ! command -v ffmpeg >/dev/null 2>&1;
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! python3 -c "import mutagen" 2>/dev/null; then
|
if ! command -v id3cp >/dev/null 2>&1; then
|
||||||
log_error "Python mutagen library not found. Please install python-mutagen (Arch) or python3-mutagen (Debian/Ubuntu)."
|
log_error "id3cp not found. Please install id3lib (Arch: id3lib, Debian/Ubuntu: libid3-tools)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user