Jump to content

ID3 UDF ID3v1 & ID3v2 MP3 Tags


joeyb1275
 Share

Recommended Posts

I just wanted to say thanks. to JoeyB 1275 and TheSaint. I have been using and modifying this au3 for years now, working it in to a few projects. Since the latest autoit upgrade I had to update to the latest id3.au3 version and subsiquently update most of my code.

When i was done updating my most used project i realized that i had to only change a few lines of code and comment out almost all of my mods and additional functions.

through my experience with this i have learned a lot about the file structure used for mp3's and it comes in pretty handy when my boss gives me a file and asks why it does not work with our system. i can just hex edit the thing and bring it back to life or tell him that its thoroughly thrashed with out any doubt.

I know i don't post here much , but i have been using autoit since 2006 when a big name company(can't say) handed me testing process with autohotkey. I found a better way of doing things with autoit....saved the day, and have loved it ever since.

so once again. Thank you.

Link to comment
Share on other sites

  • 2 months later...

I just wanted to say thanks. to JoeyB 1275 and TheSaint. I have been using and modifying this au3 for years now, working it in to a few projects. Since the latest autoit upgrade I had to update to the latest id3.au3 version and subsiquently update most of my code.

When i was done updating my most used project i realized that i had to only change a few lines of code and comment out almost all of my mods and additional functions.

through my experience with this i have learned a lot about the file structure used for mp3's and it comes in pretty handy when my boss gives me a file and asks why it does not work with our system. i can just hex edit the thing and bring it back to life or tell him that its thoroughly thrashed with out any doubt.

I know i don't post here much , but i have been using autoit since 2006 when a big name company(can't say) handed me testing process with autohotkey. I found a better way of doing things with autoit....saved the day, and have loved it ever since.

so once again. Thank you.

It is good to hear that it has helped you. I have definitely learned a lot and I am still learning. I know MP3 tag reading/writing is not as popular as it used to be, but I still enjoy fixing and adding features to this UDF.

Link to comment
Share on other sites

  • 4 weeks later...

I see some really bad ID3V2 headers sometimes. i have one with all my problems in one mp3.

Tag size reads larger than the file size. ver2.2 and 2.3 tags mixed together, wierd OCT data (i think ) in the middle and evidence of old tags at the end... also....it appears to have overwritten part of the first mpeg frame.

I am looking into adding some error detection and the ability to find the first valid mpeg frame without offsetting from the ID3 tag.

I would like to find the location of the first mpeg header and strip left from there. Then create fresh tags with no corruption.

I have something working now using string searched to find the header, but it is too slow for my taste and uses too much memory. I am going to try it using file reads and bitwise operations so that it can be appended to the mostly completed code that's already there.

if someone has already done this, please let me know.

Link to comment
Share on other sites

I see some really bad ID3V2 headers sometimes. i have one with all my problems in one mp3.

Tag size reads larger than the file size. ver2.2 and 2.3 tags mixed together, wierd OCT data (i think ) in the middle and evidence of old tags at the end... also....it appears to have overwritten part of the first mpeg frame.

I am looking into adding some error detection and the ability to find the first valid mpeg frame without offsetting from the ID3 tag.

I would like to find the location of the first mpeg header and strip left from there. Then create fresh tags with no corruption.

I have something working now using string searched to find the header, but it is too slow for my taste and uses too much memory. I am going to try it using file reads and bitwise operations so that it can be appended to the mostly completed code that's already there.

if someone has already done this, please let me know.

That is too bad, I have not built in a way to fix poorly formatted tags nor do I check for that. Do you have any suggestions on how the ID3 code can change to check for the v2.2 and v2.3 mixed tag?

I like your idea of scanning for the first MPEG header! There is a function in the ID3 udf called _MPEG_GetFrameHeader() that you can use as a starting point if you haven't already done so. If you can get it working quickly I would like to add it to the ID3 udf.

Link to comment
Share on other sites

  • 2 months later...

Hi there,

first of all: THANK YOU for this UDF! It seems to be really useful.

Unfortunately, I have not yet figured out how to use this.

What I'm trying to accomplish is an application to sync ratings between iTunes (stored in it's database) and mp3 tags (POPM). I think I have the logic right, but whenever I want to write a new rating into the POPM tag, my application freezes. Other applications can't change the mp3 tags in this time. I think I somehow locked the mp3 file while reading the tags, so I can't write back...

I can't see any function to close the mp3 file, so I'm kind of lost here. You can take a look at my code here:

https://www.dropbox.com/s/ldnh5jsxdnp7izm/LOGIC.au3

My problem is in the function "Sync()", which first calls "getRatingTag()". After comparing this and the rating from iTunes, I'd like to write a new rating into the tag in my function "setRatingTag()". The line

_ID3SetTagField('POPM', $rating)
seems to be the culprit here. Anyone here who can see what I'm doing wrong?

Cheers, NinjaN

Link to comment
Share on other sites

I haven't looked at the rest of your code, but all that line does, is update that element in the stored variable.

You have to follow that line with the line that writes that stored variable tag data to the mp3 file.

Can't remember it off the top of my head ... been a while since I played around with this stuff.

It should be pretty easy to determine from the example.

And I never updated any ratings ... in fact, I always have that and most other non-essential tags removed.

EDIT

Ok, had a quick look at the first post here, and the second example.

$sTagInfo = _ID3ReadTag($Filename)
_ID3SetTagField("POPM", $rating)
_ID3WriteTag($Filename)

That would probably serve your needs ... depending on what is in $rating.

It's important to note, that you need to read the data in first, then amend that with the set command, then write the result to file.

That's how I remember it anyway.

The other thing, is the format of the tag element you are writing to, as some only accept numbers, etc.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Useful things

Thank you very much for your answer. I followed your advice and have it coded like this now:

$id3 = _ID3ReadTag($currTrack, 2)
MsgBox(0, 'SetField', $rating)
; write new tag rating
$return = _ID3SetTagField('POPM', $rating)
MsgBox(0, 'WriteTag', $return)
$return = _ID3WriteTag($currTrack, 2)
MsgBox(0, 'Finish', $return)

My application doesn't freeze anymore and goes on as wanted, but the rating is not written as desired. The mp3 file is not changed at all... :-

I seem to be trying to insert some wrong datatype into this frame...

I tried looking through ID3 UDF, at line 1890 there seems to be the code to insert or update the POPM frame.

What do I have to put into the function to have it written correctly?

NinjaN

Edited by NinjaN
Link to comment
Share on other sites

What does $rating equal when you try to write it, and what do you get back when you try to read it? What do you get before you try to write it in the POPM field of the file?

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you for your help!

When reading the POPM tag (using ID3.au3, too) I get a value from 0 to 255 which is translated into 0 to 5 (see "getTagRating" in my linked code).

So naturally I tried to write these values back into the tag. My function "setRatingTag" gets the current track and the new rating (0-5) as input. The new rating ist converted into the values from 0 to 255, which is then to be written into the POPM tag.

Func setRatingTag($currTrack, $newRating)
Local $rating = 0

; translate 0-5 to POPM rating
Switch $newRating
Case 0
$rating = 0
Case 1
$rating = 1
Case 2
$rating = 64
Case 3
$rating = 128
Case 4
$rating = 196
Case 5
$rating = 255
Case Else
$rating = 0
EndSwitch

$id3 = _ID3ReadTag($currTrack, 0)

; write new tag rating
_ID3SetTagField('POPM', $rating)
_ID3WriteTag($currTrack, 0)

$updated = $updated + 1
EndFunc

I have tried converting the new rating into various datatypes before writing them, so far unsuccessful...

You can see my current code here:

https://www.dropbox.com/s/ldnh5jsxdnp7izm/LOGIC.au3

Edited by NinjaN
Link to comment
Share on other sites

I know what you want it ($rating) to equal, my question was what DOES it equal when you try to write it? Also, what do you get before you try to write the value in the POPM field, does it already have a value set in it? What does it read after you try to set it, does it have a value in it, but not the right one, or is it just blank?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Oh, sorry ;-P

That's different for each file.

I have a test file, which has a tag rating of 2 ("_ID3GetTagField('POPM')" returns 64) and an iTunes rating (in it's database) of 4.

My application asks for user input here, so I have control over which rating gets written to the other side. In some cases (like my test case here), I want to write the iTunes rating of 4 (translating to 196) into the POPM tag, overwriting the original content of 64 (translating to 2).

The application does all of this without an error message, each output looks OK.

I haven't tried writing a completely blank rating into the tags, yet

Edited by NinjaN
Link to comment
Share on other sites

Oh, sorry ;-P

That's different for each file.

I guessed that part, you're still not answering any of the questions I asked.

I have a test file, which has a tag rating of 2 ("_ID3GetTagField('POPM')" returns 64) and an iTunes rating (in it's database) of 4.

My application asks for user input here, so I have control over which rating gets written to the other side. In some cases (like my test case here), I want to write the iTunes rating of 4 into the POPM tag, overwriting the original content of 64 (translating to 2).

The application does all of this without an error message, each output looks OK.

So what's the problem then if it looks ok then there's no problem right?

If you want help with this, then you have to write your answers to the questions that are asked. Right now, from reading your words, you have no problem and we're just dancing around the issue. Answer the questions with answers that match what is asked and maybe, just maybe we can try and figure this out.

Also, a reproducer script would be extremely helpful to see exactly what you're doing. Small snippets of code without the related information is not helping as I can't run it, and I'm not going to try and build a whole script around it. It's like looking into the room through the keyhole, all I see is what's in front of me with no idea what else is in the room. I need the rest of the room.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I seem to have worded myself unclear, sorry...

I'll try to answer your questions as good as I can.

I have a mp3 file with a tag rating of 2 (ID3.au3 returns 64)

_ID3ReadTag($currTrack.Location, 2)
$popm = _ID3GetTagField('POPM')

, which I want to update to a tag rating of 4 (for which the above function returns 196)

$id3 = _ID3ReadTag($currTrack, 2)
_ID3SetTagField('POPM', 196)
_ID3WriteTag($currTrack, 2)

There's no error (that I can see), yet the tag is not updated. Reading the file again with my application returns a tag rating of 2, other programs (MP3Tag and foobar2000) also show a rating of 2)

I'll try and upload my application for you to see. At the moment, it's dependant on my iTunes library...

EDIT:

Nevermind, I got it... Stupid mistake on my side, what else...

I put "$currTrack" into "_ID3WriteTag", but that is the iTunes object, not the path of the actual mp3 file. So (for future reference) the following code works:

Func setRatingTag($currTrack, $newRating)
Local $rating = 0

; translate 0-5 to POPM rating
Switch $newRating
Case 0
$rating = 0
Case 1
$rating = 1
Case 2
$rating = 64
Case 3
$rating = 128
Case 4
$rating = 196
Case 5
$rating = 255
Case Else
$rating = 0
EndSwitch

$id3 = _ID3ReadTag($currTrack.Location, 2)

; write new tag rating
$return = _ID3SetTagField('POPM', Binary($rating))
$return = _ID3WriteTag($currTrack.Location, 2)

$updated = $updated + 1
EndFunc
Edited by NinjaN
Link to comment
Share on other sites

how to remove all tags?

Try _ID3RemoveTag($sPath,0) to remove all tags.

Looks like I need to update the function description comments. The second input to the function should be an integer 0-4 where

0 - removes ID3v1, ID3v2 and APEv2 tags

1 - removes ID3v1

2 - removes ID3v2

3 - removes ID3v1 and ID3v2

4 - removes APEv2 only

Edited by joeyb1275
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...