Page 1 of 1

How to handle data from mp3-files

Posted: Sun Dec 19, 2021 5:51 pm
by JanVledder
Hi All,

I came across a very versatile tool developed by the late Mark Smith, called id3lib.

When I use this tool while gathering info about more than one mp3-files the output is not adequate: only the data of the first mp3-file is presented. I tried the following script:

on mouseUp
set the itemDelimiter to slash
put item 1 to -2 of the effective filename of this stack into stdFolder
set the defaultFolder to stdFolder & "/" & "MyFiles"
put the files into theFiles
filter theFiles with "*[.mp3]"
set defaultFolder to stdFolder
start using stack "id3lib"
repeat for each line K in theFiles
id3_setFile ("MyFiles" & "/" & K)
set the clipboardData["rtf"] to id3_getArtist() & tab & id3_getTitle() & tab & id3_getAlbum() & tab & id3_getYear()
put the clipboardData & cr after tData
end repeat
delete last char in tData
put tData into fld 1
end mouseUp


How can I get the info of all the files in MyFiles?

Kind Regards,

JanVledder

Re: How to handle data from mp3-files

Posted: Mon Dec 20, 2021 10:10 pm
by jacque
I'm not familiar with the library but it doesn't look like you need to go through the clipboard to collect the data. This should work:

Code: Select all

repeat for each line K in theFiles
   id3_setFile ("MyFiles" & "/" & K)
   put id3_getArtist() & tab & id3_getTitle() & tab & id3_getAlbum() & tab & id3_getYear() & cr after tData
end repeat
delete last char of tData
put tData into fld 1
Does the library return info as rtf, and that's why you're using the clipboard to convert it to plain text? If so, the last line could be:

Code: Select all

set the rtfText of fld 1 to tData
That doesn't explain why only the first file is processed. You could add a breakpoint to see how many lines are returned in the file list.

Re: How to handle data from mp3-files

Posted: Tue Dec 21, 2021 11:54 am
by JanVledder
Thank you for your quick response. I changed the script and that works well, except for one thing: the cr doesn't result in a new line, so everything in fld 1 is one line. Could you tell me how to fix this? I use an Apple MacBook Pro with intel processor and MacOS Monterey.

Thanks in advance

JanVledder

Re: How to handle data from mp3-files

Posted: Tue Dec 21, 2021 7:45 pm
by jacque
You didn't mention whether the library returns rtf text, but if so you'd want to use the rtf version of a carriage return instead of LC's cr constant. I couldn't find a definitive answer after a cursory search but try "\n" for starters. Maybe someone here knows more about the file format.

Re: How to handle data from mp3-files

Posted: Tue Dec 21, 2021 10:33 pm
by JanVledder
I'm sure the output is RTF text. After you mentioned trying "\n" (which didn't work, the output was empty) I tried other 'commands', "\par" and "\line" are candidates. After a lot of trial and error I ended up with "\par1" and "\line1" that do the trick. I don't understand why this is working, but it works!

So thank you for guiding me to this solution. ('Dankjewel' in Dutch).

Kind regards,

JanVledder