LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash script to set title of MP3 file equal to name of MP3 file (https://www.linuxquestions.org/questions/linux-general-1/bash-script-to-set-title-of-mp3-file-equal-to-name-of-mp3-file-4175415953/)

jwbales 07-10-2012 01:48 PM

Bash script to set title of MP3 file equal to name of MP3 file
 
I bought a tutorial to help me learn a foreign language and want to put the lessons on my ipod. However, none of the hundreds of mp3 files have any tag information. I was able to use eyeD3 to name the artist and album on all the files in batch mode, but none of the files has a title. So when I loaded them into my ipod, no titles are visible. Since the file names are of the form lesson001.mp3, lesson002.mp3, etc, the filenames are ok to use as titles. But how do I do some sort of batch command to place the filename into the 'title' field of the tag? I'm sure there is some simple way to do this using a bash script, but it's been decades since I wrote a bash script. Help!

Kustom42 07-10-2012 02:16 PM

It can more than likely be done via BASH but I am not familair enough with how the meta-data is setup for the file title etc.. I'll do some searching on that and see if I can help. I'm sure someone else here knows more about the way the mp3 files retain that data and may be able to help more directly but I'll see what I can find.

jwbales 07-10-2012 04:04 PM

This is what I tried, but although it echoed the proper commands, it did not actually perform the commands and no changes were made in the id3 tags of the mp3 files.

for x in `ls`; do echo "eyeD3 --title='$x' file $x"; done

Kustom42 07-10-2012 04:14 PM

remove the echo, your not telling the system to execute the eyeD3 command, just to echo it. I was finding similar info and was about to post a similar for loop.

jwbales 07-10-2012 11:17 PM

Yes, thank you, removing the echo helped, but the script still failed. Eventually I figured out how to use EasyTag to accomplish the task.

evo2 07-10-2012 11:42 PM

Hi,

also you should replace youtr `ls` with *. Also the "file" should not be there. Ie

Code:

for x in * ; do
  eyeD3 --title="$x" $x
done

Finally, you might like to strip the filename extension from the title.
Eg.
Code:


for x in * ; do
  eyeD3 --title="${x%.*}" $x
done

HTH,

Evo2.

sazary 09-15-2013 01:19 PM

if your file names have spaces (like my files!) you should change 2nd line to:

Code:

  eyeD3 --title="${x%.*}" $x

Dafydd 09-15-2013 09:20 PM

Here is a script I use.

Code:

#!/bin/bash
##use 'mp3info' to insert data tags in 'mp3' files.

# check if there is no command line argument
if [ $# -eq 0 ]
then
echo "You forgot the information."
echo "This is only for 1 albun name and 1 artist."
echo "3 fields are required artist, album, genre, in that order."
echo "Either no spaces in each field or use quotation marks around each field."
exit
fi

artist=$1;
album=$2;
genre=$3;

for filename in *mp3;  ##list all mp3 names in directory

  do
  if [ -f "$filename" ]
    then
        song_name=${filename%.mp3};
                mp3info -t "$song_name" -a "$artist" -l "$album" -g "$genre" "$filename";
    else
        :
    fi
    done
exit



All times are GMT -5. The time now is 12:57 PM.