65 lines
1.8 KiB
Bash
65 lines
1.8 KiB
Bash
#AI GENERATED
|
|
#write_tags "Artist1,Artist2" "music_*.flac" "ALBUMARTIST,ARTIST"
|
|
function write_tags() {
|
|
# Check if at least artists are provided
|
|
if [[ $# -lt 1 ]]; then
|
|
echo "Usage: write_tags <comma-separated-artists> [path-regex] [comma-separated-tags]"
|
|
echo "Defaults: path-regex='ALL', tags='ALBUMARTIST,ARTIST,ARTISTS'"
|
|
return 1
|
|
fi
|
|
|
|
local artists=("${(@s:,:)1}") # Split comma-separated artists into array
|
|
local file_pattern="${2:-ALL}" # Default to 'ALL' if not provided
|
|
local tags=("${(@s:,:)3:-ALBUMARTIST,ARTIST,ARTISTS}") # Default tags if not provided
|
|
|
|
# If ALL was specified for files, use all FLAC files in current directory
|
|
local files
|
|
if [[ "$file_pattern" == "ALL" ]]; then
|
|
files=(*.flac(N))
|
|
else
|
|
files=($~file_pattern(N)) # Expand the pattern
|
|
fi
|
|
|
|
if [[ ${#files} -eq 0 ]]; then
|
|
echo "No files found matching pattern: $file_pattern"
|
|
return 1
|
|
fi
|
|
|
|
# Build the metaflac commands
|
|
local show_cmd="metaflac"
|
|
local remove_cmd="metaflac"
|
|
local set_cmd="metaflac"
|
|
|
|
# Add show and remove tags to commands
|
|
for tag in $tags; do
|
|
show_cmd+=" --show-tag=$tag"
|
|
remove_cmd+=" --remove-tag=$tag"
|
|
done
|
|
|
|
# Add set tags for each artist to each tag type
|
|
for tag in $tags; do
|
|
for artist in $artists; do
|
|
set_cmd+=" --set-tag=$tag=\"${artist}\""
|
|
done
|
|
done
|
|
|
|
# Process each file
|
|
for file in $files; do
|
|
echo "Processing $file"
|
|
|
|
# Show current tags
|
|
echo "Current tags:"
|
|
eval "$show_cmd \"$file\""
|
|
|
|
# Remove old tags
|
|
eval "$remove_cmd \"$file\""
|
|
|
|
# Set new tags
|
|
eval "$set_cmd \"$file\""
|
|
|
|
# Show updated tags
|
|
echo "Updated tags:"
|
|
eval "$show_cmd \"$file\""
|
|
echo
|
|
done
|
|
}
|