Jump to content

Why can't AutoIt read ID3 tags on MP3


Recommended Posts

Hi all,

Please help. I was experimenting on trying to read ID3 tags on an MP3 file. TO test it, I first tried to read the file into a variable and output it in a msgbox but all autoit could find is "ID3". :huh2:

$SOURCE =  FileOpen("gondor.mp3",0)
$FILE = FileRead($SOURCE, FileGetSize($SOURCE))
MsgBox(0,"",$FILE)

I also tried to read just the first line - same result. :D

$SOURCE =  FileOpen("gondor.mp3",0)
$FILE = FileReadLine($SOURCE, 1)
MsgBox(0,"",$FILE)

When opened in notepad, the tags look like this:

ID3    vPRIV '  WM/MediaClassPrimaryID ¼}`Ñ#ãâK¡H¤*(DPRIV )  WM/MediaClassSecondaryID              PRIV   PeakValue S!  PRIV   AverageLevel   TIT2 Steward of Gondor SongTIT3 Return of the KingTALB Return of the KingTCON (24)WOAF      WOAR

Thanks in advance for the help/information.
Link to comment
Share on other sites

A string in C is terminated by a NULL character (ASC(0)). AutoIt uses C-style strings, so it can not read any binary files. The first NULL character AutoIt finds terminates the string. I would expect there to be tons of NULL characters in an MP3.

Link to comment
Share on other sites

What about creating your own function that would read in one character at a time? That way, you could test it and not include it if it's a null character. It shouldn't interfere with your readout since you are interested in text, not null line terminators. You'll have to play with the result to see how to parse it, but that should at least allow you to read the beginning of the file. It might also be eaisier to only include the first XXX chars so you don't end up reading the whole mp3 file byte by byte into a variable through AutoIt. ID3 tag info should be at the start, so play around to see what the XXX number actually ends up being to read all the tag.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

You sent me to thinking. I finally figured out a way to copy binary files with AutoIt, although it is ungodly slow (16 seconds to duplicate a shortcut on an Athlon XP 3200+). I'm sure that could be improved.

Anyway, pekster is correct, you can read and skip NULL characters with a loop like this:

While 1
    $chr = FileRead("file.txt", 1)
    If @error Then ExitLoop
    if $chr = "" Then ContinueLoop   ; NULL character
   ; Process the character
Wend
Link to comment
Share on other sites

You sent me to thinking.  I finally figured out a way to copy binary files with AutoIt, although it is ungodly slow (16 seconds to duplicate a shortcut on an Athlon XP 3200+).  I'm sure that could be improved.

Anyway, pekster is correct, you can read and skip NULL characters with a loop like this:

While 1
    $chr = FileRead("file.txt", 1)
    If @error Then ExitLoop
    if $chr = "" Then ContinueLoop  ; NULL character
  ; Process the character
Wend
How about if you did:

$fHandle = FileOpen ( "file.txt", 0 )
While 1
    $chr = FileRead($fHandle, 1)
    If @error Then ExitLoop
    if $chr = "" Then ContinueLoop  ; NULL character
  ; Process the character
Wend
FileClose ( $fHandle )

then you wouldn't be opening and closing the file each time you read a character. It might go faster.

H'mmmn, on rereading this, the line "$chr = FileRead("file.txt", 1)" (in Valik's code)always reads the first character of the file because it is freshly opening the file in each pass of the loop. I ran the code just to be sure.

Gene

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

It would help if you could point out one these are to me .

and what they do .

RunWait(@comspec & ' /c find /v "@~@" adaware.lnk> adaware.txt',"",@SW_HIDE)

$a = FileRead("adaware.txt",FileGetSize("adaware.txt"))

$a = StringReplace($a,@CRLF,"")

MsgBox(4096,"",$a)

Link to comment
Share on other sites

Interesting, what I did with some DOS...

RunWait(@comspec & ' /c find /v "@~@" adaware.lnk > adaware.txt',"",@SW_HIDE)
$a = FileRead("adaware.txt",FileGetSize("adaware.txt"))
$a = StringReplace($a,@CRLF,"")
MsgBox(4096,"",$a)
When I did it I got an empty text file and msgbox. What did you get?

It was interesting to open adaware.lnk in the DOS text editor.

Gene

Edited by Gene

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

You have to point it to something that the script can find. I'm assuming Larry has AdAware installed and used it's shortcut. I do not, so I modified it to use another shortcut I have and it basically strips all NULL characters from the file leaving you with everything else. That allows the entire file to be loaded at once instead of doing the character by character reading.

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...