diff --git a/.zsh_functions/flac.zsh b/.zsh_functions/flac.zsh new file mode 100644 index 0000000..fa6594a --- /dev/null +++ b/.zsh_functions/flac.zsh @@ -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 [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 +} diff --git a/.zsh_functions/music.zsh b/.zsh_functions/music.zsh deleted file mode 100644 index c6099af..0000000 --- a/.zsh_functions/music.zsh +++ /dev/null @@ -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." -} - diff --git a/.zshrc b/.zshrc index 0282b06..dd2e533 100755 --- a/.zshrc +++ b/.zshrc @@ -32,6 +32,7 @@ autosource nas autosource fuck autosource download autosource jellyfin +autosource flac eval "$(zoxide init --cmd cd zsh)"