diff --git a/scripts/myaudiotags b/scripts/myaudiotags index b26ac70fbb5ec9d49d977da911150057fa7a1c38..4d03898de9d56eb43a36a2156cdcfe30cbb0f8f5 100755 --- a/scripts/myaudiotags +++ b/scripts/myaudiotags @@ -42,8 +42,7 @@ print_usage() printf " set artist, album, and date tags in the first track\n" printf " setc COMMENT\n" printf " set comment tag in the first track\n" - printf " upt update title tags from filenames\n" - printf " uptn update track number tags from filenames\n\n" + printf " update update title and track/disc number/total tags from filenames\n\n" printf "Commands applied to a single audio file:\n" printf " clean-single FILE\n" printf " set only following tags (and remove padding) in file FILE:\n" @@ -607,62 +606,10 @@ if [ "$command" = "set-single" ]; then fi # ----------------------------------------------------------------------------- -# upt +# update # ----------------------------------------------------------------------------- -if [ "$command" = "upt" ]; 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 +if [ "$command" = "update" ]; then multi_disc=0 @@ -676,10 +623,10 @@ if [ "$command" = "uptn" ]; then current_disc= last_file=`ls -1r *.flac | grep -m 1 flac` 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 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 # Set read-write permission @@ -689,6 +636,9 @@ if [ "$command" = "uptn" ]; then { 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]\+\. //'` + metaflac --set-tag="TITLE=$tag_title" "$file" # Remove .flac and leading disc number (if present) tag_tracknumber=`echo ${file%.flac} | sed 's/^[1-9]\.//'` # Get the track number without leading 0 @@ -703,10 +653,11 @@ if [ "$command" = "uptn" ]; then fi metaflac --set-tag="DISCNUMBER=$tag_discnumber" "$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 - 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 + printf "\033[7m$tag_title\033[0m ($file)\n" metaflac --set-tag="TRACKNUMBER=$tag_tracknumber" "$file" metaflac --set-tag="TRACKTOTAL=$tag_tracktotal" "$file" done @@ -724,10 +675,10 @@ if [ "$command" = "uptn" ]; then current_disc= last_file=`ls -1r *.mp3 | grep -m 1 mp3` 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 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 # Set read-write permission @@ -737,6 +688,9 @@ if [ "$command" = "uptn" ]; then { 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]\+\. //'` + id3v2 --id3v2-only --song "$tag_title" "$file" # Remove .mp3 and leading disc number tag_tracknumber=`echo ${file%.mp3} | sed 's/^[1-9]\.//'` # Get the track number without leading 0 @@ -750,10 +704,11 @@ if [ "$command" = "uptn" ]; then tag_tracktotal=`ls -1 ${tag_discnumber}.*.mp3 | grep -c mp3` fi 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 - 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 + printf "\033[7m$tag_title\033[0m ($file)\n" id3v2 --id3v2-only --track "$tag_tracknumber/$tag_tracktotal" "$file" done }