Created
March 23, 2020 13:43
-
-
Save mahito1594/5eef132caf5b1d10e0a08d32ca34b600 to your computer and use it in GitHub Desktop.
Rename FLAC files based on its metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
################################################################################ | |
# | |
# TL; DR | |
# This script rename filename.flac to | |
# <Album Artist>/<Album Title>/Disc <Disc Number> - Track <Track Number>.flac | |
# | |
# Usage: | |
# rename-flac [filename] | |
# | |
# Dependencies: | |
# - metaflac | |
# - unaccent | |
# | |
################################################################################ | |
if [[ -z $MUSIC_LIBRARY ]]; then | |
MUSIC_LIBRARY=$(echo "${HOME}/pCloud Drive/Music") | |
fi | |
# get metadatas | |
ALBUM_ARTIST="$(metaflac --show-tag=ALBUMARTIST "$1" | cut -d= -f2 | unaccent utf8)" | |
ALBUM_TITLE="$(metaflac --show-tag=ALBUM "$1" | cut -d= -f2 | unaccent utf8)" | |
DISC_NUMBER="$(metaflac --show-tag=DISCNUMBER "$1" | cut -d= -f2)" | |
TRACK_NUMBER="$(metaflac --show-tag=TRACKNUMBER "$1" | cut -d= -f2)" | |
# rename some special characters: /, : | |
ALBUM_ARTIST="${ALBUM_ARTIST//\//;}" | |
ALBUM_ARTIST="${ALBUM_ARTIST//:/ -}" | |
ALBUM_TITLE="${ALBUM_TITLE//\//;}" | |
ALBUM_TITLE="${ALBUM_TITLE//:/ -}" | |
new_dir="${MUSIC_LIBRARY}/${ALBUM_ARTIST}/${ALBUM_TITLE}" | |
new_name="Disc ${DISC_NUMBER:-1} - Track ${TRACK_NUMBER}.flac" | |
# echo "${new_dir}/${new_name}" | |
mkdir -p "${new_dir}" | |
mv "$1" "${new_dir}/${new_name}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment