(Solved!) Writing MP3 Tag Data

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
ITSMERSH

(Solved!) Writing MP3 Tag Data

#1 Post by ITSMERSH »

Hi.

I'm working on a program atm that can read MP3 Tag Info from .mp3 files using ffmpeg.

Code: Select all

"$FFMPEGBIN" -i "$FILE" > $TEMPDIR/tmp_id3ffmpeg$FILENAME 2>&1
FF_LENGTH="`grep -wm1 "Duration:" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d. -f1 | awk -F':' '{print $3":"$4}'`"
FF_BITRATE="`grep -wm1 "Audio:" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f4 | awk -F' ' '{print $6}' | tr ',' ' '`"
FF_FORMAT="`grep -wm1 "Audio:" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f4 | awk -F' ' '{print $1}' | tr ',' ' '`"
ID3_TITLE="`grep -wim1 "^    title" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_ARTIST="`grep -wim1 "^    artist" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_ALBUM="`grep -wim1 "^    album" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_DISC="`grep -wim1 "^    disc" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_YEAR="`grep -wim1 "^    year" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_DATE="`grep -wim1 "^    date" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_COMMENT="`grep -wim1 "^    comment" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_TRACK="`grep -wim1 "^    track" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_GENRE="`grep -wim1 "^    genre" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f2- | cut -d' ' -f2-`"
ID3_ALBUMART="`grep -wm1 "Video:" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d: -f4 | awk -F' ' '{print $1}' | tr ',' ' '`"
echo "$FF_LENGTH" > $TEMPDIR/SongLength
[ -f $TEMPDIR/id3_info ] && rm -f $TEMPDIR/id3_info
echo -n "" > $TEMPDIR/id3_info
echo "FFMPEG: `basename "$FFMPEGBIN"`" > $TEMPDIR/id3_info
echo "File: $FILEBN" >> $TEMPDIR/id3_info
echo "Length: $FF_LENGTH" >> $TEMPDIR/id3_info
echo "Artist: $ID3_ARTIST" >> $TEMPDIR/id3_info
echo "Album: $ID3_ALBUM" >> $TEMPDIR/id3_info
echo "Title: $ID3_TITLE" >> $TEMPDIR/id3_info
echo "Track: $ID3_TRACK" >> $TEMPDIR/id3_info
echo "Genre: $ID3_GENRE" >> $TEMPDIR/id3_info
echo "Year: $ID3_YEAR" >> $TEMPDIR/id3_info
echo "Date: $ID3_DATE" >> $TEMPDIR/id3_info
echo "Comment: $ID3_COMMENT" >> $TEMPDIR/id3_info
echo "Bit Rate: $FF_BITRATE" >> $TEMPDIR/id3_info
echo "Format: $FF_FORMAT" >> $TEMPDIR/id3_info
echo "Album Art: $ID3_ALBUMART" >> $TEMPDIR/id3_info
Now I want to a dd a function to write such information into .mp3 files using ffmpeg.

Is that possible from within a shell script?

Any hints of how to achieve?

Thanks.
Last edited by ITSMERSH on Thu 15 Nov 2018, 02:35, edited 4 times in total.

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#2 Post by fabrice_035 »

Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

ITSMERSH

#3 Post by ITSMERSH »

Hi fabrice_035.

Thanks for the links.

Besides I discovered lame seems to have some options for this, I downloaded the source codes of id3tool and id3ren and compiled them successfully.

Then I just checked the PPM and discovered there is already compiled binaries of id3tool and id3ren in the Ubuntu repository.

However, I'm sure I will achieve my goal somehow by these tools.

Thanks again.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#4 Post by Flash »

I have no idea how it does it, but Pcdripper allows to write some of the tag data. Perhaps you can learn something by inspecting the Pcdripper script or code or whatever it is called.
Attachments
pcdripper-3.9.4.pet
(20.98 KiB) Downloaded 116 times

ITSMERSH

#5 Post by ITSMERSH »

Hi Flash.

Thanks for the pcdripper 0.9.4 package.

I have 0.9.3 installed but both of them don't work, as both versions using

- apetag
- id3tag
- mp3info


for ID3 Tag Information.

None of them are installed in my Puppy, which makes pcdripper useless in my system.

---

However, I have successfully written my first ID3 tags into a MP3 file using my compiled version of id3ren. I've chosen to use this fresh compiled version as the binaries from Ubuntu Tahr repository are compiled from 2007 and they are smaller in size for some reason. :shock:

Thanks for all the help. :)

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#6 Post by Flash »

Are any of those things in this .pet? I got it along with Pcdripper at some point.
Attachments
libcddb_DEV-1.3.2-i686.pet
(98.59 KiB) Downloaded 104 times

ITSMERSH

#7 Post by ITSMERSH »

Thanks for the package Flash, but sorry: no!

I found at least

- id3tag
- mp3info


being available from the repos.

The apetag just wasn't found in the repos. Probably just needs to update the package manager repository files, but I'm too lazy to do so atm.

Thanks for the help again.

I think -at least for a first step- I can mark this as solved as my workaround using id3gen seems to work as expected. If anything goes wrong during time I can re-work this by using either id3tool, id3tag or probably mp3info (plus lame not to forget).

phat7
Posts: 179
Joined: Fri 05 Jun 2015, 08:54

#8 Post by phat7 »

ITSMERSH wrote:I think -at least for a first step- I can mark this as solved as my workaround using id3gen seems to work as expected. If anything goes wrong during time I can re-work this by using either id3tool, id3tag or probably mp3info (plus lame not to forget).
Your intention was to write information into .mp3 files using ffmpeg. Didn't this work?

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#9 Post by zigbert »

This is how pMusic is using ffmpeg for writing tags.

Code: Select all

ffmpeg -i "/root/Judas priest - Blood red skies.mp3"  -acodec copy -id3v2_version 3 -metadata title="Blood red skies" -metadata artist="Judas priest" -metadata album="Ram it Down" -metadata year="1993" -metadata track="6" -metadata comment="" -metadata genre="Heavy Metal" -y /root/Judas priest - Blood red skies_TAG.mp3

ITSMERSH

#10 Post by ITSMERSH »

phat7 wrote:Your intention was to write information into .mp3 files using ffmpeg. Didn't this work?
Yes, this was my first thought of it, since I read out the information using ffmpeg. So I just assumed it MUST be done using ffmpeg also (didn't know of the other solutions possible).

After my opening post I discovered lame --help id3 options and found the post made by fabrice_035 mentioning id3ren and id3tool.

I decided to try these tools first as I don't have ffmpeg installed (my Art Studio originally came with avconf instead, which gives different results compared to the ffmpeg output). To read out the id3 tag information I'm using a temporarily sym-linked binary from outer file system (sub-dir on HD).

Since this is only a very small feature of the program I'm working on, I don't want to spend too much time on this issue. That's why I can live whith my id3ren workaround for now. Just calling it workaround since id3ren doesn't only write the id3 tags - it also renames the file. So, I needed to add a few lines to rename the file back to original.

ITSMERSH

#11 Post by ITSMERSH »

Ok.

Tonight I stumbled over a case which makes it necessary to try some of the other possible solutions/options.

Once there was ID3 Tag information applied to an .mp3 file it can't be changed via id3ren.

Had to use kid3 to remove the ID3 Tags made during development.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#12 Post by mikeb »

Not sure if useful but deadbeef can write tag information...there may be useful techniques in their sources though I suspect it actually rewrites the whole file.

Interesting thread.

:)

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#13 Post by technosaurus »

I wrote some basic code to strip ID tags here
It doesn't do exactly what you are looking for but it may be a good starting point.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

ITSMERSH

#14 Post by ITSMERSH »

Thanks for the replies @mikeb & @technosaurus.

I rewrote my idren workaround using id3tool and it could change those ID3 tags immediately that I wrote to .mp3 files during testings. :D

BUT! :(

Unfortunately it can't change ID3 tags made on earlier files using kid3 (these files have data in both versions of ID3 tag data)! :shock:

I suspect both id3ren AND id3tool are writing the ID3 version 1 tags only...

Then I searched the PPM again for id3 and downloaded everything I found from Ubuntu repository.

I found id3v2 which seems to be pretty cool, as it has option to remove all ID3 tag data at once (id3v2 -D $FILE). So I just removing all tags by this command before writing new data to .mp3.

Now I need to find out what version of ID3 tags being written. Probably rewriting my script again for the use of id3v2 in general.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#15 Post by Flash »

Isn't it great that there are so many standards to choose from? :lol:

ITSMERSH

#16 Post by ITSMERSH »

At least it's some kind of fun, as I learn from every step I'm doing things in Puppy.

Just wondering someone doesn't consider it being a drug and to prohibit Puppy Linux? :wink:

ITSMERSH

#17 Post by ITSMERSH »

Sometimes it's a hassle too!

I checked the output of id3ren and id3tool.
Both are writing id3v1 tags only.

The id3v2 writes both versions of tags and has option to choose which one to write (default seems to be id3v1 AND id3v2).

The next issue is on the Comment tag.

As soon as the Comment for id3v2 is written, I can't read out the comment tag via ffmpeg anymore. The kid3 proofed both of them are written, existing and displayed in kid3.

The id3v2 has also option to convert id3v1 tags to id3v2 tags.

When converting the Comment from id3v1 tag is NOT applied to the id3v2 tag!

Instead the kid3 shows a new tag under id3v2: --> id3v1 Comment <-- !

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#18 Post by fredx181 »

Hi RSH, Just mentioning, there's also eyed3
Display and manipulate id3-tags on the command-line
Description:
A command-line editor to add/edit/remove ID3-tags on mp3 files.
It supports version 1.0,1.1,2.3 and 2.4 of the ID3 standard.
Additionally it displays several information about the file
such as length and bitrate from an MP3 file.
It's python based, I've used it in the past, but didn't test recently.

Fred

ITSMERSH

#19 Post by ITSMERSH »

Hi Fred.

Yes, eyed3 was under the packages I downloaded from Ubuntu repository.

After unpacking I found a Python script and removed the extracted directory immediately. I don't want to have hassle with Python added to this.

I recall the only two Python programs I ever got to work, has been:

- Openshot
- JACK Mixer

JACK Mixer just won't work from SFS. In all cases I'd to install JACK Mixer to get it running and working as expected - though, Openshot did work from SFS.

Python is still a mystery to me...

ITSMERSH

#20 Post by ITSMERSH »

Ok,

after examining id3v2 a little more I found option to read out the tags from a file via id3v2. So I rewrote my script and am using now id3v2 exclusively to read AND write ID3 tags into the .mp3 files of my mix-downs/compositions.

Marked as solved now...

Code: Select all

# Get MP3 ID3 Information from File
function GetMP3ID3Info(){
	if [[ "$1" = *.mp3 ]]; then
		FILE="$1"; FILEBN="`basename "$FILE"`"; FILENAME="`basename "$FILE"`".txt;
		WriteLogFile "Get MP3 ID3 Tag Info  :  $1"
		TAGS="$(id3v2 -l $FILE)"
		echo "$TAGS" > "$TEMPDIR/tmp_id3ffmpeg$FILENAME"
		ID3_ARTIST="`grep -im1 "Artist" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 3`"
		ID3_TITLE="`grep -im1 "Title" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 2 | cut -d 'A'  -f 1`"
		ID3_ALBUM="`grep -im1 "Album" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 2 | cut -d 'Y'  -f 1`"
		ID3_YEAR="`grep -im1 "Year" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 3 | cut -d ','  -f 1`"
		ID3_GENRE="`grep -im1 "Genre" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 4 | cut -d ' '  -f 2`"
		ID3_COMMENT="`grep -im1 "Comment" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 2 | cut -d 'T'  -f 1`"
		ID3_TRACK="`grep -im1 "Track" $TEMPDIR/tmp_id3ffmpeg$FILENAME | cut -d ':'  -f 3`"
		echo "Artist: $ID3_ARTIST" > $TEMPDIR/id3_info
		echo "$ID3_ARTIST" > /tmp/vARTISTTAG
		echo "Album: $ID3_ALBUM" >> $TEMPDIR/id3_info
		echo "$ID3_ALBUM" > /tmp/vALBUMTAG
		echo "Title: $ID3_TITLE" >> $TEMPDIR/id3_info
		echo "$ID3_TITLE" > /tmp/vTITLETAG
		echo "Track: $ID3_TRACK" >> $TEMPDIR/id3_info
		echo "$ID3_TRACK" > /tmp/vTRACKTAG
		echo "Year: $ID3_YEAR" >> $TEMPDIR/id3_info
		echo "$ID3_YEAR" > /tmp/vYEARTAG
		echo "Genre: $ID3_GENRE" >> $TEMPDIR/id3_info
		echo "$ID3_GENRE" > /tmp/vGENRETAG
		echo "Comment: $ID3_COMMENT" >> $TEMPDIR/id3_info
		echo "$ID3_COMMENT" > /tmp/vCOMMENTTAG
		rm -f "$TEMPDIR/tmp_id3ffmpeg$FILENAME"
	fi
} # GetMP3ID3Info

Post Reply