How to handle data from mp3-files

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JanVledder
Posts: 3
Joined: Sun Dec 12, 2021 9:39 pm

How to handle data from mp3-files

Post by JanVledder » Sun Dec 19, 2021 5:51 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to handle data from mp3-files

Post by jacque » Mon Dec 20, 2021 10:10 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

JanVledder
Posts: 3
Joined: Sun Dec 12, 2021 9:39 pm

Re: How to handle data from mp3-files

Post by JanVledder » Tue Dec 21, 2021 11:54 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: How to handle data from mp3-files

Post by jacque » Tue Dec 21, 2021 7:45 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

JanVledder
Posts: 3
Joined: Sun Dec 12, 2021 9:39 pm

Re: How to handle data from mp3-files

Post by JanVledder » Tue Dec 21, 2021 10:33 pm

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

Post Reply

Return to “Multimedia”