Commit 422b0c3d authored by Cédric Marie's avatar Cédric Marie
Browse files

myaudiotags: Merge 'upt' and 'uptn' into 'update'



Most of the time, only the titles need to be updated, the track numbers
don't change. Yet, the first time, they both need to be set, so it is
easier to have a single command. Setting the track numbers along with
the titles, when not necessary, is not too much annoying. With a single
command, we make sure that everything is up to date, and in sync with
the filenames.
Signed-off-by: default avatarCédric Marie <cedric@hjuvi.lautre.net>
parent 0ccf4397
...@@ -42,8 +42,7 @@ print_usage() ...@@ -42,8 +42,7 @@ print_usage()
printf " set artist, album, and date tags in the first track\n" printf " set artist, album, and date tags in the first track\n"
printf " setc COMMENT\n" printf " setc COMMENT\n"
printf " set comment tag in the first track\n" printf " set comment tag in the first track\n"
printf " upt update title tags from filenames\n" printf " update update title and track/disc number/total tags from filenames\n\n"
printf " uptn update track number tags from filenames\n\n"
printf "Commands applied to a single audio file:\n" printf "Commands applied to a single audio file:\n"
printf " clean-single FILE\n" printf " clean-single FILE\n"
printf " set only following tags (and remove padding) in file FILE:\n" printf " set only following tags (and remove padding) in file FILE:\n"
...@@ -607,62 +606,10 @@ if [ "$command" = "set-single" ]; then ...@@ -607,62 +606,10 @@ if [ "$command" = "set-single" ]; then
fi fi
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# upt # update
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
if [ "$command" = "upt" ]; then if [ "$command" = "update" ]; then
print_header "Set title from filename in all tracks"
# FLAC files
if [ "$flac_files" != "" ]; then
# Set read-write permission
chmod 644 *.flac
# Update title tag in all tracks
ls -1 *.flac |
{
while read file
do
# Remove .flac and leading disc and track numbers
tag_title=`echo ${file%.flac} | sed 's/^[1-9]\.//' | sed 's/^[0-9]\+\. //'`
printf "$file: \033[7m$tag_title\033[0m\n"
metaflac --set-tag="TITLE=$tag_title" "$file"
done
}
# Set read-only permission
chmod 444 *.flac
# MP3 files
elif [ "$mp3_files" != "" ]; then
# Set read-write permission
chmod 644 *.mp3
# Update title tag in all tracks
ls -1 *.mp3 |
{
while read file
do
# Remove .mp3 and leading disc and track numbers
tag_title=`echo ${file%.mp3} | sed 's/^[1-9]\.//' | sed 's/^[0-9]\+\. //'`
printf "$file: \033[7m$tag_title\033[0m\n"
id3v2 --id3v2-only --song "$tag_title" "$file"
done
}
# Set read-only permission
chmod 444 *.mp3
fi
exit 0
fi
# -----------------------------------------------------------------------------
# uptn
# -----------------------------------------------------------------------------
if [ "$command" = "uptn" ]; then
multi_disc=0 multi_disc=0
...@@ -676,10 +623,10 @@ if [ "$command" = "uptn" ]; then ...@@ -676,10 +623,10 @@ if [ "$command" = "uptn" ]; then
current_disc= current_disc=
last_file=`ls -1r *.flac | grep -m 1 flac` last_file=`ls -1r *.flac | grep -m 1 flac`
tag_disctotal=${last_file%%.*} tag_disctotal=${last_file%%.*}
print_header "Set track/disc numbers from filename and track/disc total in all tracks" print_header "Set title and track/disc number/total in all tracks (from filenames)"
else else
tag_tracktotal=`ls -1 *.flac | grep -c flac` tag_tracktotal=`ls -1 *.flac | grep -c flac`
print_header "Set track numbers from filename and track total in all tracks" print_header "Set title and track number/total in all tracks (from filenames)"
fi fi
# Set read-write permission # Set read-write permission
...@@ -689,6 +636,9 @@ if [ "$command" = "uptn" ]; then ...@@ -689,6 +636,9 @@ if [ "$command" = "uptn" ]; then
{ {
while read file while read file
do do
# Remove .flac and leading disc and track numbers
tag_title=`echo ${file%.flac} | sed 's/^[1-9]\.//' | sed 's/^[0-9]\+\. //'`
metaflac --set-tag="TITLE=$tag_title" "$file"
# Remove .flac and leading disc number (if present) # Remove .flac and leading disc number (if present)
tag_tracknumber=`echo ${file%.flac} | sed 's/^[1-9]\.//'` tag_tracknumber=`echo ${file%.flac} | sed 's/^[1-9]\.//'`
# Get the track number without leading 0 # Get the track number without leading 0
...@@ -703,10 +653,11 @@ if [ "$command" = "uptn" ]; then ...@@ -703,10 +653,11 @@ if [ "$command" = "uptn" ]; then
fi fi
metaflac --set-tag="DISCNUMBER=$tag_discnumber" "$file" metaflac --set-tag="DISCNUMBER=$tag_discnumber" "$file"
metaflac --set-tag="DISCTOTAL=$tag_disctotal" "$file" metaflac --set-tag="DISCTOTAL=$tag_disctotal" "$file"
printf "track \033[7m$tag_tracknumber\033[0m / \033[7m$tag_tracktotal\033[0m, disc \033[7m$tag_discnumber\033[0m / \033[7m$tag_disctotal\033[0m: $file\n" printf "track \033[7m$tag_tracknumber\033[0m/\033[7m$tag_tracktotal\033[0m, disc \033[7m$tag_discnumber\033[0m/\033[7m$tag_disctotal\033[0m: "
else else
printf "track \033[7m$tag_tracknumber\033[0m / \033[7m$tag_tracktotal\033[0m: $file\n" printf "track \033[7m$tag_tracknumber\033[0m/\033[7m$tag_tracktotal\033[0m: "
fi fi
printf "\033[7m$tag_title\033[0m ($file)\n"
metaflac --set-tag="TRACKNUMBER=$tag_tracknumber" "$file" metaflac --set-tag="TRACKNUMBER=$tag_tracknumber" "$file"
metaflac --set-tag="TRACKTOTAL=$tag_tracktotal" "$file" metaflac --set-tag="TRACKTOTAL=$tag_tracktotal" "$file"
done done
...@@ -724,10 +675,10 @@ if [ "$command" = "uptn" ]; then ...@@ -724,10 +675,10 @@ if [ "$command" = "uptn" ]; then
current_disc= current_disc=
last_file=`ls -1r *.mp3 | grep -m 1 mp3` last_file=`ls -1r *.mp3 | grep -m 1 mp3`
tag_disctotal=${last_file%%.*} tag_disctotal=${last_file%%.*}
print_header "Set track/disc numbers from filename in all tracks" print_header "Set title and track/disc number/total in all tracks (from filenames)"
else else
tag_tracktotal=`ls -1 *.mp3 | grep -c mp3` tag_tracktotal=`ls -1 *.mp3 | grep -c mp3`
print_header "Set track numbers from filename in all tracks" print_header "Set title and track number/total in all tracks (from filenames)"
fi fi
# Set read-write permission # Set read-write permission
...@@ -737,6 +688,9 @@ if [ "$command" = "uptn" ]; then ...@@ -737,6 +688,9 @@ if [ "$command" = "uptn" ]; then
{ {
while read file while read file
do do
# Remove .mp3 and leading disc and track numbers
tag_title=`echo ${file%.mp3} | sed 's/^[1-9]\.//' | sed 's/^[0-9]\+\. //'`
id3v2 --id3v2-only --song "$tag_title" "$file"
# Remove .mp3 and leading disc number # Remove .mp3 and leading disc number
tag_tracknumber=`echo ${file%.mp3} | sed 's/^[1-9]\.//'` tag_tracknumber=`echo ${file%.mp3} | sed 's/^[1-9]\.//'`
# Get the track number without leading 0 # Get the track number without leading 0
...@@ -750,10 +704,11 @@ if [ "$command" = "uptn" ]; then ...@@ -750,10 +704,11 @@ if [ "$command" = "uptn" ]; then
tag_tracktotal=`ls -1 ${tag_discnumber}.*.mp3 | grep -c mp3` tag_tracktotal=`ls -1 ${tag_discnumber}.*.mp3 | grep -c mp3`
fi fi
id3v2 --id3v2-only --TPOS "$tag_discnumber/$tag_disctotal" "$file" id3v2 --id3v2-only --TPOS "$tag_discnumber/$tag_disctotal" "$file"
printf "track \033[7m$tag_tracknumber\033[0m / \033[7m$tag_tracktotal\033[0m, disc \033[7m$tag_discnumber\033[0m / \033[7m$tag_disctotal\033[0m: $file\n" printf "track \033[7m$tag_tracknumber\033[0m/\033[7m$tag_tracktotal\033[0m, disc \033[7m$tag_discnumber\033[0m/\033[7m$tag_disctotal\033[0m: "
else else
printf "track \033[7m$tag_tracknumber\033[0m / \033[7m$tag_tracktotal\033[0m: $file\n" printf "track \033[7m$tag_tracknumber\033[0m/\033[7m$tag_tracktotal\033[0m: "
fi fi
printf "\033[7m$tag_title\033[0m ($file)\n"
id3v2 --id3v2-only --track "$tag_tracknumber/$tag_tracktotal" "$file" id3v2 --id3v2-only --track "$tag_tracknumber/$tag_tracktotal" "$file"
done done
} }
......
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