feat: Ai generated helper to split artist tags
This commit is contained in:
parent
5539013342
commit
52ef0aedff
3 changed files with 66 additions and 60 deletions
65
.zsh_functions/flac.zsh
Normal file
65
.zsh_functions/flac.zsh
Normal file
|
@ -0,0 +1,65 @@
|
|||
#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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue