Home > Mobile >  eyeD3 with find, xargs to set mp3 tag
eyeD3 with find, xargs to set mp3 tag

Time:11-30

Once again, attempting to reinvent the wheel - for self learning exercise:

audio book file format:

filenames        : titletag
001 bookname.mp3 : bookname
002 bookname.mp3 : bookname
003 bookname.mp3 : bookname

In my player (VLC) I see only the bookname in playlist, makes it hard to know what chapter I am listening to. I listen at sleep time so next day I try to return and find where I was up to.

I have tried various constructs (see below) but other than doing it file by file I can not fathom a script that will do all files in the directory.

To set the title tag eyeD3 expects eyeD3 -t "new tag" FILENAME

eyeD3 filename returns

Time: 07:52 MPEG1, Layer III    [ 64 kb/s @ 44100 Hz - Mono ]
----------------------------------------------------------------------------------------------
ID3 v2.3:
title: 1
artist: Some Author
album: bookname
track: 1        
UserTextFrame: [Description: year]
2014
FRONT_COVER Image: [Size: 38061 bytes] [Type: image/jpeg]
Description: Album cover

So this line works, IIRC.

eyeD3 001 bookname.mp3 | awk  '/track/ {print $2}' | xargs I% sh -c 'eyeD3 -t % "001 bookname.mp3"'

So this code is the concept but raises an error:

find .  -iname "*.mp3" -exec eyeD3 -t "{}" {}
find: Only one instance of {} is supported with -exec ...  

Also this construct, if it worked, would put the file extension in the tag.

I would like to just put the file name, or even just the track number into the Title tag (just to know how to do further string manipulation)

I spent half the night reading about find / xargs but still couldn't grok a solution. I would love to be able to extract the track:num tag and use that, but this too I can not fathom the (meager?) eyeD3 documentation enough to do. If even possible. I think I can do the loop to rename the file using the tag.

I did actually achieve my goal using Easytag but I do enjoy learning the command line (script) programming. The combinations/permutations of the find(exec)/sed/awk/xargs I find mind boggling.

CodePudding user response:

Assuming the mp3 files are located in the currect directory, would you please try:

#!/bin/bash

for f in *.mp3; do                                      # loop over *.mp3 files
    track=$(eyeD3 "$f" | awk '/track/ {print $2}')      # extract track number
    echo eyeD3 -t "$track" "$f"                         # print the command line
done

If the output looks good, drop echo.

  • Related