AppleScript C Perl Shell Xcode Other

Convert Apple Lossless Audio file to MP3

Post Reply
coding / perl     Views: 3211Prev .. Next
Convert Apple Lossless Audio file to MP3Posted: Tuesday, June 25, 2013 [02:41:55] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
I needed a flash card for my car but car player does not play Apple Lossless Audio files. I've got 32Gb USB Flash drive and most of my music is in above named format.
iTunes can convert them but it's a hassle. Wanted something "set and forget" sort of thing.
Started with AppleScript and hit the wall - backslash escaping white space and other characters was a bummer.
Forgot to mention - installed ffmpeg VIA MacPorts - turned-out to be the easiest way.

To make a long story short - AppleScript:
View Codeset p to "/Users/username/Desktop/music.temp/" -- set it to the folder where all your music temporary stored (do not use iTunes library)
set the_folder to POSIX file p
tell application "Finder"
set inPath to the_folder
set myFiles to (files of entire contents of folder inPath whose name ends with ".m4a") as alias list -- m4a extension for AL
repeat with i from 1 to count of myFiles
set the_file to item i of myFiles as string
set fromFile to POSIX path of the_file
do shell script ("echo " & quoted form of fromFile & " | perl /Users/username/Desktop/run.ffmpeg.cgi") -- full path to Perl file
end repeat

end tell


and Perl file (I know, it's raw but it works):
View Code#!/usr/bin/perl
$files = <STDIN>;chomp $files;$files =~ s/\s+$//;$files =~ s/\/+$//;
$files =~ s/ /\\ /g;$files =~ s#\(#\\\(#g;$files =~ s#\)#\\\)#g;$files =~ s#\'#\\\'#g;$files =~ s#\&#\\\&#g;
$tofl = $files;$tofl =~ s#\.\w{3}$#\.mp3#;
$resf = `ls -la $files`;
unless($resf =~ m/no such file/i) {
print "Good\n";
`/opt/local/bin/ffmpeg -i $files -ar 44100 -ab 128 $tofl`; ## ACTUAL CONVERTER
`rm $files`;
} else {print "No file: $files\n";}


Just run the AppleScript and have some coffee or tea, hell, you can have a beer if your library is big enough.There's no place like ~
RE: Convert Apple Lossless Audio file to MP3Posted: Tuesday, June 25, 2013 [03:06:42] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Installing the ffmpeg with MacPorts is easy:
View Codesudo port install ffmpeg +gpl +postproc +lame +theora +libogg +vorbis +xvid +x264 +a52 +faac +faad +dts +nonfree

just sit back and relaxThere's no place like ~
coding / perlPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group