Browse Source

retag: update mp3 tags

master
Maxim Likhachev 5 years ago
parent
commit
4ad8c4f60d
  1. 1
      README.md
  2. 101
      retag

1
README.md

@ -35,6 +35,7 @@ will create the symbolic link for each script in the \<path> directory. @@ -35,6 +35,7 @@ will create the symbolic link for each script in the \<path> directory.
- [a2mp3](a2mp3) converts wav audio files to mp3 format.
- [axaudio](axaudio) gets an information and audio stream from Axia Livewire network.
- [retag](retag) writes id3 tags based on file path.
- [radio](radio) plays the internet radio stations from a list stored in the file.
- [vls](vls) runs vlc-ncurses with increased speed.

101
retag

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
#!/bin/bash
#Создан: Ср 19 фев 2020 21:59:29
#Изменён: Чт 20 фев 2020 00:45:38
# Requirements:
# - mid3v2 from media-libs/mutagen
rstc="\033[00m"
green="\033[1;32m"
yellow="\033[1;33m"
blue="\033[1;34m"
REGEXP=".*/(.*)/(.*) \[(.*)\]/(.*)/(.*?) - (.*)/(.*?) - (.*)\.([[:alnum:]]{3})$"
usage() {
echo "$(basename "$0") - simple mp3 tagger."
echo
echo "USAGE: $(basename "$0") [file] [options]"
echo
echo "The filenames should be in the format \"[...]/GENRE/ARTIST [COUNTRY]/TYPE/YEAR - ALBUM/TRACK - TITLE.FORMAT\""
echo
echo "Command line arguments:"
echo " -h --help - show this help"
echo " -v --verbose - show updating tags"
echo " -d --dry - run without tags saving"
}
tag_file() {
file="$1"
[[ $file =~ $REGEXP ]]
printf "${blue}%s[%02d/%02d] ${yellow}Tagging the file «%s»${rstc}\n" "$INDENT" "$((++CURRENT_TRACK))" "$TRACKS" "$file"
GENRE="${BASH_REMATCH[1]}"
ARTIST="${BASH_REMATCH[2]}"
YEAR="${BASH_REMATCH[5]}"
ALBUM="${BASH_REMATCH[6]}"
TRACK="${BASH_REMATCH[7]}"
TITLE="${BASH_REMATCH[8]}"
if [ -n "$VERBOSE" ]; then
printf "%s\t Genre: %s | Artist: %s |" "$INDENT" "$GENRE" "$ARTIST"
printf "Year: %s | Album: %s |" "$YEAR" "$ALBUM"
printf "Track: %s | Title: %s\n" "$TRACK" "$TITLE"
fi
if [ -z "$DRY_RUN" ]; then
mid3v2 --genre="$GENRE" --artist="$ARTIST" --year="$YEAR" \
--album="$ALBUM" --track="$TRACK" --song="$TITLE" \
"$file"
fi
}
tag_directory() {
TRACKS=$(find "$1" -name '*.mp3' -print | wc -l)
printf "${green}> %s/${rstc}\n" "$1"
INDENT=" "
find "$1" -name '*.mp3' | while read -r file; do tag_file "$file"; done
}
tag() {
if [[ -d "$1" ]]; then
tag_directory "$1"
elif [[ "$1" =~ \.mp3 ]]; then
tag_file "$1"
fi
}
if (( $# == 0 )); then
usage
exit 1
fi
QUEUE=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help) usage; exit 0; shift;;
-v|--verbose) VERBOSE=1; shift;;
-d|--dry) DRY_RUN=1; VERBOSE=1; shift;;
*) QUEUE+=("$1"); shift;;
esac
done
set -- "${QUEUE[@]}"
INDENT=
TRACKS="$#"
CURRENT_TRACK=0
for item in "${QUEUE[@]}"; do
tag "$(realpath "$item")"
done
Loading…
Cancel
Save