Search code examples
bashmetadatamp3

Bash script to tag mp3 files


I would like to edit the metadata of a lot of .mp3 files. I do not want to do this using a GUI, or any manual one-by-one way. I would like to write a script that adds tags for me. I am in search of a command or way of manually editing the metadata so that I could write something like this:

for SONG in ./songs/greenday/*
do
  tag --artist="greenday" --album="Dookie" --album-art="./art/greenday/Dookie.jpg" --file $SONG
done

I am familiar with tools like:

  • Kid3
  • EasyTAG
  • Mp3tag

But none allow me to do what I want to do in the efficient way I want to do it.


Solution

  • I have searched the debian packages and there is a package called kid3-cli

    you can read the manual man kid3-cli

    Kid3 can write sofisticated ID3v2 and v3 tags that would include the coverart a lot more. This example tags all songs in a folder

    kid3-cli -c "set title 'I\'ll be there for you'" \
             -c "set albumart 'http://www.example.com/blah.jpg'" \
             -c "set SYLT:'/path/to/lyrics.lrc'" \
             ./songs/greenday/*.mp3
    

    remember this is just a example, you must read the man even if it hurts

    And now to something completely different

    If you do not need the cover art you can user mp3tag with can tag straight ID3v1 tags

    #!/bin/bash
    
    for SONG in ./songs/greenday/*
    do
        mp3tag -a "greenday" -l "Dookie" "$SONG"
    done
    

    ... I have tested it, and it works

    max@linux:~# ./testmp3
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Brett Eldredge_Love Someone.mp3
    -----------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Brett Eldredge_Somethin' I'm Good At.mp3
    --------------------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 48000Hz, 64kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Brett Eldredge_The Long Way.mp3
    -----------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Brett Eldredge_The Reason.mp3
    ---------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Bring You Back_Don't Ya.mp3
    -------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Illinois_Drunk On Your Love.mp3
    -----------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)
    
    Wrote ID3 tag successfully!
    /root/musik/Brett Eldredge- Lose My Mind_Lose My Mind.mp3
    ---------------------------------------------------------
    Artist    : greenday
    Songname  :
    Album     : Dookie                          Year:
    Etcetera  :
    Genre     : (null)
    Info      : Mpeg-1 layer 3 at 44100Hz, 128kb/s (JointStereo)