Commit 7be38ef7 authored by Cédric Marie's avatar Cédric Marie
Browse files

tag-sieve: Add seta and uptn commands



"seta" sets the artist, album, and date tags (given in arguments) in
the first track.
"uptn" updates the track number tags from the filenames.
Signed-off-by: default avatarCédric Marie <cedric.marie@openmailbox.org>
parent 82fdea5c
......@@ -38,7 +38,11 @@ print_usage()
printf " Options for \"clean\" command:\n"
printf " -d keep full date (default: keep only the year)\n"
printf " -a multi-artist (read artist in each track)\n"
printf " seta ARTIST ALBUM DATE\n"
printf " set artist, album, and date tags in the first track\n"
printf " upt update title tags from filenames\n"
printf " uptn update track number tags from filenames\n"
printf " id3v2 convert id3v1 tags to id3v2 tags (MP3 files only)\n"
}
print_header()
......@@ -304,6 +308,67 @@ if [ "$command" = "clean" ]; then
exit 0
fi
# -----------------------------------------------------------------------------
# seta
# -----------------------------------------------------------------------------
if [ "$command" = "seta" ]; then
tag_artist=$2
tag_album=$3
tag_date=$4
if [ "$tag_artist" = "" ]; then
printf "ARTIST parameter is missing\n"
exit 1
fi
if [ "$tag_album" = "" ]; then
printf "ALBUM parameter is missing\n"
exit 1
fi
if [ "$tag_date" = "" ]; then
printf "DATE parameter is missing\n"
exit 1
fi
# Print album information
printf "\033[7m"
printf "ARTIST=$tag_artist\n"
printf "ALBUM=$tag_album\n"
printf "DATE=$tag_date\n"
printf "\033[0m"
confirm_to_continue
print_header "Set artist, album, and date in the first track"
# FLAC files
if [ "$flac_files" != "" ]; then
file=`ls -1 *.flac | grep -m 1 flac`
# Set read-write permission
chmod 644 "$file"
metaflac --set-tag="ARTIST=$tag_artist" "$file"
metaflac --set-tag="ALBUM=$tag_album" "$file"
metaflac --set-tag="DATE=$tag_date" "$file"
# Set read-only permission
chmod 444 "$file"
# MP3 files
elif [ "$mp3_files" != "" ]; then
file=`ls -1 *.mp3 | grep -m 1 mp3`
# Set read-write permission
chmod 644 "$file"
id3v2 --artist "$tag_artist" "$file"
id3v2 --album "$tag_album" "$file"
id3v2 --year "$tag_date" "$file"
# Set read-only permission
chmod 444 "$file"
fi
exit 0
fi
# -----------------------------------------------------------------------------
# upt
# -----------------------------------------------------------------------------
......@@ -356,6 +421,62 @@ if [ "$command" = "upt" ]; then
exit 0
fi
# -----------------------------------------------------------------------------
# uptn
# -----------------------------------------------------------------------------
if [ "$command" = "uptn" ]; then
# FLAC files
if [ "$flac_files" != "" ]; then
print_header "Set disc and track numbers from filename in all tracks"
# Set read-write permission
chmod 644 *.flac
ls -1 *.flac |
{
while read file
do
# Remove .flac and leading disc number
tag_tracknumber=`echo ${file%.flac} | sed 's/^[1-9] - //'`
# Get the track number without leading 0
tag_tracknumber=${tag_tracknumber%% - *}
tag_tracknumber=${tag_tracknumber#0}
printf "$file: \033[7m$tag_tracknumber\033[0m\n"
metaflac --set-tag="TRACKNUMBER=$tag_tracknumber" "$file"
done
}
# Set read-only permission
chmod 444 *.flac
# MP3 files
elif [ "$mp3_files" != "" ]; then
# Set read-write permission
chmod 644 *.mp3
ls -1 *.mp3 |
{
while read file
do
# Remove .mp3 and leading disc number
tag_tracknumber=`echo ${file%.mp3} | sed 's/^[1-9] - //'`
# Get the track number without leading 0
tag_tracknumber=${tag_tracknumber%% - *}
tag_tracknumber=${tag_tracknumber#0}
printf "$file: \033[7m$tag_tracknumber\033[0m\n"
id3v2 --track "$tag_tracknumber" "$file"
done
}
# Set read-only permission
chmod 444 *.mp3
fi
exit 0
fi
# -----------------------------------------------------------------------------
# id3v2 (MP3 only)
# -----------------------------------------------------------------------------
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment