Skip to content

Instantly share code, notes, and snippets.

@kyv
Created October 6, 2012 17:57
Show Gist options
  • Save kyv/3845625 to your computer and use it in GitHub Desktop.
Save kyv/3845625 to your computer and use it in GitHub Desktop.
copy y convert music for mp3 player
#!/usr/bin/perl
#Copyright 2012, [email protected]
# * Licensed under the GPL Version 2 license.
use File::Copy;
use File::Basename;
my $PLS="$ARGV[0]";
my $DEST="$ARGV[1]";
my $tmp='/tmp/out.wav';
my @exts=qw(.ogg .oga .wma .m4a);
open($p, $PLS);
for (<$p>) {
chomp;
my $orig = $ENV{HOME}. "/". $_;
if ($orig =~ /.mp3$/i) {
copy("$orig", "$DEST") or die "Copy Failed $!";
}
else {
$out_file=$DEST. basename($_, @exts) . '.mp3';
system('/usr/bin/mplayer', '-ao', "pcm:file=$tmp", "$orig");
# Use lame to make an mp3
system('/usr/bin/lame', "$tmp", "$out_file");
if (unlink($tmp) == 0) {
print "$tmp deleted successfully.\n";
} else {
print "$tmp was not deleted.\n";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment