bashmetadatamp3id3v2kid3-cli

kid3-cli set picture does not set album photo for mp3


I've been trying to set album art image in mp3 files programmatically for hours now.

(I'm using a Mac running Monterey 12.3.1)

Using the kid3-cli I can set all other metadata using this command:

kid3-cli -c "set artist 'Artist Name'" -c "set album 'Album Name'" -c "set title 'Song Title'" /Path/to/my/audio.mp3

I've extended this command with set picture and all the other metadata updates, but the photo does not show for the audio file in finder.

Using this command:

kid3-cli -c "set artist 'Artist Name'" \
         -c "set album 'Album Name'" \
         -c "set title 'Title'" \
         -c "set albumart 'URL for album art'" \
         -c "set picture: '/Path/to/picture' ''" \
         "/path/to/mp3/file.mp3"

I've followed the documentation here: Kid3 Documentation and have tried running some variations of the command for setting the picture hoping one would work.

These are the command variants I've used to try and get the image to display.

 // with semicolon after command
 kid3-cli -c "set picture: '/Path/to/picture' ''" "/Path/to/my/audio.mp3"
 // without semicolon
 kid3-cli -c "set picture '/Path/to/picture' ''" "/Path/to/my/audio.mp3" 
 // swapping single/double quotes
 kid3-cli -c 'set picture: "/path/to/picture" ""' "/path/to/my/audio.mp3"

The interesting thing is when I run kid3 cli and enter get it prints out the metadata and shows this for picture:

 *Picture: Cover (front) /path/to/my/picture/thumb.jpg

But based on the docs it should be setting the actual image data when calling set picture and not the path to the picture.

Am I missing something??


Solution

  • The reason mine was failing was a simple mistake.

    I have a bash script that I'm calling from another (Mac) application that I pass parameters to, and the script handles calling kid3-cli and passing the arguments to it.

    Here is my script that was not working (only 'set picture:' was not working, all other metadata was set).

    #!/bin/sh
    
    # Arguments this script expects when called:
    # $0 - script name (mp3_update) (passed in by default)
    # $1 - mp3 file path
    # $2 - artist
    # $3 - album
    # $4 - title
    # $5 - album art url
    # $6 - new file path (renamed and move to this path)
    # $7 - cache image path (path to image thumbnail stored locally)
    
    #ARTIST="$(echo "$uat_catalog$line" | sed -e 's/[()&]/\\&/g')" // this is to sanitize vars in []
    #escape any single quotes in the paths
    CURRENT_PATH=${1//\'/\'}
    NEW_PATH=${6//\'/\'}
    LOCAL_IMAGE_CACHE=${7//\'/\'}
    
    /Applications/kid3.app/Contents/MacOS/kid3-cli -c "set artist '${2//\'/\'}'" \
         -c "set album '${3//\'/\'}'" \
         -c "set title '${4//\'/\'}'" \
         -c "set albumart '${5//\'/\'}'" \
         -c "set picture: $LOCAL_IMAGE_CACHE ''" \
         "$CURRENT_PATH"
    
    # move file to new home
    mv "$CURRENT_PATH" "$NEW_PATH"
    

    If you look closely at the 'set picture:' command you'll notice that the $LOCAL_IMAGE_CACHE variable is NOT wrapped in single quotes.

    Omitting the quotes caused the url to be set instead of the actual image data.

    This is my version of the script that is now working:

    #!/bin/sh
    
    # Arguments this script expects when called:
    # $0 - script name (mp3_update) (passed in by default)
    # $1 - mp3 file path
    # $2 - artist
    # $3 - album
    # $4 - title
    # $5 - album art url
    # $6 - new file path (renamed and move to this path)
    # $7 - cache image path (path to image thumbnail stored locally)
    
    #ARTIST="$(echo "$uat_catalog$line" | sed -e 's/[()&]/\\&/g')" // this is to sanitize vars in []
    #escape any single quotes in the paths
    CURRENT_PATH=${1//\'/\'}
    NEW_PATH=${6//\'/\'}
    LOCAL_IMAGE_CACHE=${7//\'/\'}
    
    /Applications/kid3.app/Contents/MacOS/kid3-cli -c "set artist '${2//\'/\'}'" \
         -c "set album '${3//\'/\'}'" \
         -c "set title '${4//\'/\'}'" \
         -c "set albumart '${5//\'/\'}'" \
         -c "set picture:'$LOCAL_IMAGE_CACHE' 'Album Art'" \
         "$CURRENT_PATH"
    
    # move file to new home
    mv "$CURRENT_PATH" "$NEW_PATH"