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
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
splitartist() {
|
||||
local flac_file="$1"
|
||||
local sep="${2:-,}" # Default separator is ','
|
||||
|
||||
if [[ ! -f "$flac_file" ]]; then
|
||||
echo "File not found: $flac_file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! command -v metaflac >/dev/null 2>&1; then
|
||||
echo "Error: metaflac not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "Reading tags from: $flac_file"
|
||||
|
||||
local artist_tag albumartist_tag
|
||||
artist_tag=$(metaflac --show-tag=ARTIST "$flac_file" | sed 's/^ARTIST=//')
|
||||
albumartist_tag=$(metaflac --show-tag=ALBUMARTIST "$flac_file" | sed 's/^ALBUMARTIST=//')
|
||||
|
||||
IFS="$sep" read -ra artist_array <<< "$artist_tag"
|
||||
IFS="$sep" read -ra albumartist_array <<< "$albumartist_tag"
|
||||
|
||||
echo -e "\nCurrent ARTIST tag: $artist_tag"
|
||||
echo "Split ARTIST into:"
|
||||
for a in "${artist_array[@]}"; do echo " - ${a#" "}"; done
|
||||
|
||||
echo -e "\nCurrent ALBUMARTIST tag: $albumartist_tag"
|
||||
echo "Split ALBUMARTIST into:"
|
||||
for a in "${albumartist_array[@]}"; do echo " - ${a#" "}"; done
|
||||
|
||||
echo -e "\nThe following actions will be performed on: $flac_file"
|
||||
echo "1. Remove all ARTIST and ALBUMARTIST tags"
|
||||
echo "2. Add split ARTIST tags:"
|
||||
for a in "${artist_array[@]}"; do echo " --set-tag=ARTIST='${a#" "}"; done
|
||||
echo "3. Add split ALBUMARTIST tags:"
|
||||
for a in "${albumartist_array[@]}"; do echo " --set-tag=ALBUMARTIST='${a#" "}"; done
|
||||
|
||||
read -p $'\nProceed with these changes? [y/N]: ' confirm
|
||||
if [[ "$confirm" != [yY] ]]; then
|
||||
echo "Aborted."
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Clear old tags
|
||||
metaflac --remove-tag=ARTIST --remove-tag=ALBUMARTIST "$flac_file"
|
||||
|
||||
# Add split artist tags
|
||||
for a in "${artist_array[@]}"; do
|
||||
metaflac --set-tag="ARTIST=${a#" "}" "$flac_file"
|
||||
done
|
||||
|
||||
# Add split albumartist tags
|
||||
for a in "${albumartist_array[@]}"; do
|
||||
metaflac --set-tag="ALBUMARTIST=${a#" "}" "$flac_file"
|
||||
done
|
||||
|
||||
echo "Tags updated successfully."
|
||||
}
|
||||
|
1
.zshrc
1
.zshrc
|
@ -32,6 +32,7 @@ autosource nas
|
|||
autosource fuck
|
||||
autosource download
|
||||
autosource jellyfin
|
||||
autosource flac
|
||||
|
||||
eval "$(zoxide init --cmd cd zsh)"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue