Created
January 21, 2015 23:35
-
-
Save Gabelbombe/afdfae9a1a6f585b3ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
#cptag - A script to resample mp3 files with LAME and | |
# copy id3v2 tags from the old file to the new one. | |
# | |
##################### | |
# Read id3 tags and write to file | |
mid3v2 -l "$1" > tag2.txt | |
# Resample music file | |
lame -V5 --vbr-new --resample 44.1 "$1" "resample/$1" | |
# Set value of variable 'title' | |
if | |
grep TIT2= tag2.txt > /dev/null #Test if title tag exists | |
then | |
title=`grep TIT2= tag2.txt | sed "s:TIT2=::"` | |
echo $title | |
else | |
echo "Title tag does not exist." | |
fi | |
# Set value of variable 'album' | |
if | |
grep TALB= tag2.txt > /dev/null #Test if album tag exists | |
then | |
album=`grep TALB= tag2.txt | sed "s:TALB=::"` | |
echo $album | |
else | |
echo "Album tag does not exist." | |
fi | |
# Set value of variable 'artist' | |
if | |
grep TPE1= tag2.txt > /dev/null #Test if artist tag exists | |
then | |
artist=`grep TPE1= tag2.txt | sed "s:TPE1=::"` | |
echo $artist | |
else | |
echo "Artist tag does not exist." | |
fi | |
# Set value of variable 'track' | |
if | |
grep TRCK= tag2.txt > /dev/null # Test if track tag exists | |
then | |
track=`grep TRCK= tag2.txt | sed "s:TRCK=::"` | |
echo $track | |
else | |
echo "Track tag does not exist." | |
fi | |
# Set value of variable 'genre' | |
if | |
grep TCON= tag2.txt > /dev/null # Test if genre tag exists | |
then | |
genre=`grep TCON= tag2.txt | sed "s:TCON=::"` | |
echo $genre | |
else | |
echo "Genre tag does not exist." | |
fi | |
# Write tags to file | |
mid3v2 -t "$title" -A "$album" -a "$artist" -T "$track" -g "$genre" "resample/$1" | |
exit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
#mp3shrink - A script to resample all mp3 files in a | |
# directory. This script calls the cptag script which | |
# must also be in the user's path. cptag depends upon | |
# lame and mid3v2 (mid3v2 can be found in the | |
# python-mutagen package). | |
# | |
# It is suggested that both the mp3shink and cptag | |
# scripts be placed in the user's private bin (~/bin). | |
###################################################### | |
# List mp3's in current directory. | |
ls *.mp3 > mp3_list | |
ls *.MP3 >> mp3_list | |
# Parse the mp3_list and replace spaces with escaped spaces. | |
sed -i 's: :\\ :g' mp3_list | |
# Check if resample directory exists and create it if it doesn't. | |
if | |
test -e ./resample | |
then | |
echo "resample directory/file already exists - delete it? (Y/n)" | |
read reply | |
if | |
[ "$reply" != "n" ] | |
then | |
rm -r resample | |
mkdir resample | |
else | |
exit | |
fi | |
else | |
mkdir resample | |
fi | |
# Resample each mp3 and write tags using the cptag script | |
cat mp3_list |while read song | |
do | |
echo "$song" | |
cptag "$song" | |
done | |
#clean up | |
if | |
test -e mp3_list | |
then | |
rm mp3_list | |
fi | |
if | |
test -e tag2.txt | |
then | |
rm tag2.txt | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment