Commit 82fdea5c authored by Cédric Marie's avatar Cédric Marie
Browse files

tag-sieve: Add support for MP3 files



Add support for MP3 files in commands show, clean, and upt.
Add a new command (id3v2) to convert id3v1 tags into id3v2 tags.
Signed-off-by: default avatarCédric Marie <cedric.marie@openmailbox.org>
parent 574e224f
......@@ -93,12 +93,24 @@ if [ "$command" = "show" ]; then
printf "\033[0m\n"
done
}
# MP3 files
elif [ "$mp3_files" != "" ]; then
ls -1 *.mp3 |
{
while read file
do
printf "$file\n"
printf "\033[7m"
id3v2 --list "$file"
printf "\033[0m\n"
done
}
fi
exit 0
fi
# -----------------------------------------------------------------------------
# rmblocks
# rmblocks (FLAC only)
# -----------------------------------------------------------------------------
if [ "$command" = "rmblocks" ]; then
......@@ -106,9 +118,10 @@ if [ "$command" = "rmblocks" ]; then
# FLAC files
if [ "$flac_files" != "" ]; then
print_header "Remove seek table, picture, cue sheet, and padding blocks in all tracks"
# Set read-write permission
chmod 644 *.flac
# Remove seek table, picture, cue sheet, and padding
# Remove seek table, picture, cue sheet, and padding blocks
metaflac --remove --block-type=SEEKTABLE *.flac
metaflac --remove --block-type=PICTURE *.flac
metaflac --remove --block-type=CUESHEET *.flac
......@@ -138,25 +151,16 @@ if [ "$command" = "clean" ]; then
esac
done
tags_filename=/tmp/tag-sieve-clean.tags
# FLAC files
if [ "$flac_files" != "" ]; then
tag_artist=
tag_album=
tag_date=
tag_tracknumber=
tag_tracktotal=
tag_discnumber=
tag_disctotal=
tag_comment=
tag_license=
multi_disc=0
tags_filename=/tmp/tag-sieve-clean.tags
file=`ls -1 *.flac | grep -m 1 flac`
# Get album information from the first track
print_header "Get album information from the first track ($file)"
file=`ls -1 *.flac | grep -m 1 flac`
metaflac --export-tags-to=$tags_filename "$file"
tag_artist=`grep "^ARTIST=" $tags_filename | cut -d= -f2 | tail -n 1`
tag_album=`grep "^ALBUM=" $tags_filename | cut -d= -f2 | tail -n 1`
......@@ -177,6 +181,7 @@ if [ "$command" = "clean" ]; then
read tag_disctotal
fi
# Print album information
printf "\033[7m"
if [ "$multi_artist" = "0" ]; then
printf "ARTIST=$tag_artist\n"
......@@ -204,6 +209,7 @@ if [ "$command" = "clean" ]; then
# Set read-write permission
chmod 644 *.flac
# Set tags in all tracks
ls -1 *.flac |
{
while read file
......@@ -245,6 +251,55 @@ if [ "$command" = "clean" ]; then
# Set read-only permission
chmod 444 *.flac
# MP3 files
elif [ "$mp3_files" != "" ]; then
# Get album information from the first track
print_header "Get album information from the first track ($file)"
file=`ls -1 *.mp3 | grep -m 1 mp3`
id3v2 --list "$file" > $tags_filename
tag_artist=`grep "^TPE1 " $tags_filename | cut -d: -f2 | tail -n 1 | sed 's/^ \+//'`
tag_album=`grep "^TALB " $tags_filename | cut -d: -f2 | tail -n 1 | sed 's/^ \+//'`
tag_date=`grep "^TYER " $tags_filename | cut -d: -f2 | tail -n 1 | sed 's/^ \+//'`
# 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 tags in all tracks"
# Set read-write permission
chmod 644 *.mp3
# Set tags in all tracks
ls -1 *.mp3 |
{
while read file
do
id3v2 --list "$file" > $tags_filename
tag_title=`grep "^TIT2 " $tags_filename | cut -d: -f2 | tail -n 1 | sed 's/^ \+//'`
tag_tracknumber=`grep "^TRCK " $tags_filename | cut -d: -f2 | tail -n 1 | sed 's/^ \+//'`
old_size=`stat -c %s "$file"`
id3v2 --delete-all "$file" > /dev/null
id3v2 --id3v2-only --artist "$tag_artist" "$file"
id3v2 --id3v2-only --song "$tag_title" "$file"
id3v2 --id3v2-only --album "$tag_album" "$file"
id3v2 --id3v2-only --year "$tag_date" "$file"
id3v2 --id3v2-only --track "$tag_tracknumber" "$file"
new_size=`stat -c %s "$file"`
printf "(saved %4d bytes) $file\n" $(($old_size - $new_size))
done
}
rm -f $tags_filename
# Set read-only permission
chmod 444 *.mp3
fi
exit 0
fi
......@@ -255,14 +310,15 @@ fi
if [ "$command" = "upt" ]; then
print_header "Set title from filename in all tracks"
# FLAC files
if [ "$flac_files" != "" ]; then
print_header "Set title from filename in all tracks"
# Set read-write permission
chmod 644 *.flac
# Update title tag in all tracks
ls -1 *.flac |
{
while read file
......@@ -276,6 +332,54 @@ if [ "$command" = "upt" ]; then
# 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 --song "$tag_title" "$file"
done
}
# Set read-only permission
chmod 444 *.mp3
fi
exit 0
fi
# -----------------------------------------------------------------------------
# id3v2 (MP3 only)
# -----------------------------------------------------------------------------
if [ "$command" = "id3v2" ]; then
# MP3 files
if [ "$mp3_files" != "" ]; then
print_header "Convert tags from id3v1 to id3v2"
# Set read-write permission
chmod 644 *.mp3
# Convert tags in all tracks
ls -1 *.mp3 |
{
while read file
do
id3v2 --convert "$file"
done
}
# Set read-only permission
chmod 444 *.mp3
fi
exit 0
fi
......
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