3 #################################
4 # wma converter 0.3.6 for Linux #
5 #################################
7 # Made by Peter Simon <simon.peter@linuxuser.hu>
12 # Getopt::Long - Perl Module
13 # MPlayer - http://www.mplayerhq.hu
14 # BladeEnc - http://bladeenc.mp3.no
15 # oggenc - http://www.vorbis.com
16 # mp3info - http://www.ibiblio.org/mp3info
20 # decoding all files to wav without any switches and encoders
22 # converting to mp3 or ogg with bitrate, delete options
24 # L.A.M.E. support for fanatics
25 # Default output filetype: ogg
28 # Reading the wma tags out and puting into the mp3 or the ogg tags. (What the MPlayer shows of those.)
29 # Default output bitrate: the original bitrate
30 # Simlink for the default encode mode (wma2ogg = ogg, wma2mp3 = mp3)
32 # Neglecting missing encoders if those are not in use.
34 # Using mp3info for the mp3 tags
36 # Convert more then one files in the start dir.
40 # Some bugfixes by Diego Biurrun
43 # Eg.: The L.A.M.E.'s code isn't compatible for some hardwer-decoders. Makes noise and clashings.
44 # I never met this trouble using BladeEnc.
47 use Getopt
::Long
qw(:config pass_through);
51 GetOptions
("help|?",\
&showhelp
, 'a' => \
$all, "file|f=s" => \
@files,"t=s" => \
$mtype, "lame" => \
$needlame, "del" => \
$delete, "br=i" => \
$sbrate);
55 error
("Missing parameter after the $_ switch!");
60 print "wma2ogg $ver\nPeter Simon <simon.peter\@linuxuser.hu>";
62 if (!$all && !@files) {
63 error
("There is no selected file!");
67 if ($0 =~/wma2mp3/ && !$mtype) {
71 if ($mtype eq "ogg") {
72 $ttype{"ogg"}="oggenc";
73 needed_prgs
(oggenc
, "http://www.vorbis.com");
76 if ($needlame && $mtype eq "ogg") {
77 error
("\nYou can not use L.A.M.E. & oggenc together!\n");
81 if (!$mtype && !$needlame) {
83 $ttype{"ogg"}="oggenc";
84 needed_prgs
(oggenc
, "http://www.vorbis.com");
88 if (!$needlame && $mtype eq "mp3") {
89 $ttype{"mp3"}="BladeEnc";
90 needed_prgs
(BladeEnc
, "http://bladeenc.mp3.no", mp3info
, "http://www.ibiblio.org/mp3info");
96 needed_prgs
(lame
, "http://lame.sourceforge.net", mp3info
, "http://www.ibiblio.org/mp3info");
100 print "\nUsing lame - WARNING - this is not optimal!\n";
109 $o_type=$ttype{$mtype};
111 if ($mtype ne "wav") {
112 $def_path=$ENV{PATH
};
113 @exec_path=split /\:/, $def_path;
114 foreach $temp_path (@exec_path) {
115 if (-d
$temp_path && !$enc_ok) {
116 $enc_ok=`find $temp_path -name $o_type -type f -maxdepth 1 2>/dev/null`;
121 if ((!$o_type || !$enc_ok) && $mtype ne "wav") {
122 error
("Unknown encoder.");
128 if ($sbrate && ((($sbrate <32 || $sbrate>350) && $mtype eq "mp3") || (($sbrate<64 || $sbrate>500) && $mtype eq "ogg") )) {
129 error
("Invalid, missing or redundant bitrate.");
135 if ($all && @files) {
136 error
("You can't use -a switch and -f together!");
141 @enc_files=`ls | grep '.wma'\$`;
142 foreach (@enc_files) {
154 print "\n\nUsage: wma2ogg [OPTIONS] (-f FILE1 | -f FILE2 ... | -a)\n
156 -a converts all wma files in the current directory\n
158 -t output filetype (ogg, mp3) [default=ogg]
159 -lame I wanna use L.A.M.E. sure enough!
160 -br bitrate (kb/s) [default=from the wma]
161 -del remove wma file(s) after the transcoding\n";
163 print "\n$errtext\nExiting program.\n";
174 $that=$needed{$keys};
175 $miss_text.="\nThe needed \'$what\' program is missing, see: $that!";
180 `perl -e 'use Getopt::Long;' 2>./err`;
181 open (FILE
, "<./err");
182 while ($sor=<FILE
>) {
183 if ($sor =~ /Can\'t locate/) {
184 missing_prg
("Getopt::Long", ": your Perl is too old... (uhhh... get a new one!)");
190 foreach $keys (keys %needed) {
192 open (FILE
, "<./err");
193 while ($sor=<FILE
>) {
194 if ($sor =~ /$keys\: command not found/) {
212 while ($sor=<FILE
>) {
217 $outfile=~ s/\((\d+\,\d+)\ kbit\)/$1/e;
218 print "\noriginal bitrate: $1";
220 $kept_orig_brate=~ s/(\d+)/$1/e;
224 $brate=$kept_orig_brate;
225 print " (kept as default)";
228 print " (new: $brate,0)";
234 my @temp_info=split /Clip\ info\:/, $outfile;
235 my @temp2_info=split /\n/, @temp_info[1];
236 my @temp_title=split /\ /, $temp2_info[1],3;
237 my @temp_author=split /\ /, $temp2_info[2],3;
238 my @temp_copyright=split /\ /, $temp2_info[3],3;
239 my @temp_comments=split /\ /, $temp2_info[4],3;
240 return ($temp_title[2], $temp_author[2], $temp_copyright[2], $temp2_comments[2]);
247 mplayer
=>"http://www.mplayerhq.hu",
253 $infofile=" -t '$title'";
256 $infofile.=" -a '$author'";
259 $infofile.=" -c '$comments'";
262 `mp3info "$p_name.$mtype" $infofile`;
269 foreach (@enc_files) {
271 $wav_name=~ s/(.+)\./$1/e;
273 $wav_name=$p_name.".wav";
277 print "\nConverting $_ to \"wav\" file.\n";
278 print "Using MPlayer...\n";
280 `mplayer "$_" -ao pcm -input conf="$pwd" 2>/dev/null >./1`;
281 `mv "audiodump.wav" "$wav_name"`;
286 print "\ntitle: $title";
288 print "\nauthor: $author";
290 print "\ncopyright: $copyright";
292 print "\ncomments: $comments";
294 $comments=$copyright." ".$comments."Transcoded by wma2ogg";
296 print "\n\nConverting $wav_name to \"$mtype\" file.";
298 print "\nUsing $o_type...";
300 if ($mtype eq "ogg") {
303 $infofile=" -t '$title'";
306 $infofile.=" -a '$author'";
309 $infofile.=" -c COMMENT='$comments'";
312 `"$o_type" "-$br_sw" "$brate" "-Q" "./$wav_name" $infofile "-o" "$p_name.$mtype"`;
315 if ($mtype eq "mp3" && !$needlame) {
317 `"$o_type" "$wav_name" "$p_name.$mtype" "-$br_sw" "$brate" 2>/dev/null >/dev/null`;
323 if ($mtype eq "mp3" && $needlame) {
326 `"$o_type" "-$br_sw" "$brate" "-f" "$wav_name" "$p_name.$mtype" 2>/dev/null >/dev/null`;
339 print "\n\nDone.\n\n";