diff --git a/.zsh_functions/music.zsh b/.zsh_functions/music.zsh new file mode 100644 index 0000000..c6099af --- /dev/null +++ b/.zsh_functions/music.zsh @@ -0,0 +1,60 @@ +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.d/aliases.zsh b/.zshrc.d/aliases.zsh index d9a1746..fa3ed93 100644 --- a/.zshrc.d/aliases.zsh +++ b/.zshrc.d/aliases.zsh @@ -7,3 +7,4 @@ alias tf="tofu" alias terraform="tofu" alias dotfiles="git --work-tree=$HOME --git-dir=$HOME/.dotgit " alias instaloader="uvx --with browser_cookie3 instaloader" +alias beet="uvx --with requests,langdetect,pylast,bs4,pillow --from beets beet"