Audio File Handling in Ruby

Last few days I have been looking to handling different audio format uploads in Muziboo. We currently support only mp3 files but I see a lot of wma and m4a uploads being attempted. FFMPEG can convert these files easily to mp3 but the real issue is in validating uploads and then finding out when to fire a conversion. I am currently using attachment_fu plugin for managing uploads. Mime information using file command A way to get mime type is by running this command
$ file -bi filename
The problem with this approach is that it gave me different results on gentoo and debian. Ofcourse the file executable version were different (4.16 and 4.23) but I still feel this approach is not very robust. Using ruby libraries to find out audio file information Another approach is to use a ruby library to check for file type. However the issue is that there is no single library that can check for different kinds of files. The only way I have been able to figure out is to try and open the files in different libraries (and catching exceptions). I found a list of popular ruby audio libraries here. In fact on searching some more, I found a similar approach being followed in metadata extractor library too.

blog comments powered by Disqus