PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : perl script geht nicht richtig



Tuxist
10-07-2005, 11:43
#! /usr/bin/perl

### mp3 and wma to ogg by darklinux presents
###no warrenty

use warnings;
use strict;
use File::Find ();

main();

sub convert_to_wav
{
my $file = shift;
my $wavFile = $file;
$file =~ s/(\s)/\\$1/g;
$wavFile =~ s/\.[mp3]|[wma]|[mpc]$/\.wav/gi;
my $convert_to_wav="mplayer \"./$file\" -ao pcm -aofile \"./$wavFile\"";
my $cmd=`$convert_to_wav`;

}

sub convert_to_ogg
{
my $file = shift;
my $oggFile = $file;
$oggFile =~ s/(\s)/\\$1/g;
$oggFile =~ s/\.[mp3]|[wma]|[mpc]$/\.ogg/gi;
my $convert_to_ogg="oggenc -q 4 \"./$file\" \"./$oggFile\"";
my $cmd=`$convert_to_ogg`;

}

sub readDir
{
my $dir = shift;
my $arrayRef = shift;

print("Reading dir: $dir\n");

opendir( DIR,"$dir") || die "Could not open $dir\n";
foreach ( readdir ( DIR ) )
{
# no hidden files and no .. and .
next if ( $_ =~ /^\./ );

# another dir? just enter it and read the files too
readDir ( "$dir/$_", $arrayRef ) if ( -d $_ );

# push to array if file is readable
push ( @{$arrayRef}, "$dir/$_" ) if ( -r $_ );
}
}

sub main
{
my @files = ();
my $dir = `pwd`;
chomp($dir);
readDir ( $dir, \@files );
foreach ( @files )
{
if ( $_ =~ /\.mp3$/i || $_ =~ /\.wma$/i || $_ =~ /\.mpc$/i )
{
convert_to_wav( $_ );
convert_to_ogg( $_ );
}
}
exit 0;
}

Fehlermeldung

Reading dir: /home/jan/mukke
Reading dir: /home/jan/mukke/2005
ERROR: Cannot open input file ".//home/jan/mukke/DANZEL - Put your hands up in the air (1).mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//ho.ogge/j.oggn/.oggukke/D.oggNZEL\ -\ Put\ your\ h.oggnds\ up\ in\ the\ .oggir\ (1).oggp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//home/jan/mukke/Dj Sammy - Why.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//ho.ogge/j.oggn/.oggukke/Dj\ S.ogg.ogg.oggy\ -\ .ogghy.oggp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//home/jan/mukke/bodyrockers - i like the way you move cds - i like the way you move.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//ho.ogge/j.oggn/.oggukke/bodyrockers\ -\ i\ like\ the\ .ogg.oggy\ you\ .oggove\ cds\ -\ i\ like\ the\ .ogg.oggy\ you\ .oggove.oggp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//home/jan/mukke/gwen stefanie ft eve - gwen stafani & eve - gwen stefanie ft eve - rich girl.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//ho.ogge/j.oggn/.oggukke/g.oggen\ stef.oggnie\ ft\ eve\ -\ g.oggen\ st.oggf.oggni\ &\ eve\ -\ g.oggen\ stef.oggnie\ ft\ eve\ -\ rich\ girl.oggp3": Datei oder Verzeichnis nicht gefunden

sticky bit
10-07-2005, 13:55
1. Fehler:
$file =~ s/(\s)/\\$1/g;
Du ersetzt alle Leerzeichen mit "\ ", übergibst die Argumente an die Shell-Kommandos aber in Quotas. Bei den Programmen kommt dann eben nicht " " an sondern "\ " und das ist natürlich nicht im Pfad. Wenn Du die Argumente in Quotas übergibst musst du die Leerzeichen nicht escapen, bzw. darfst das gar nicht, also entweder die Aufrufe ändern:
my $convert_to_wav="mplayer ./$file -ao pcm -aofile ./$wavFile";
my $convert_to_ogg="oggenc -q 4 ./$file ./$oggFile";
oder, besser noch, diese Ersetzung einfach rausschmeissen...

2. Fehler:
$wavFile =~ s/\.[mp3]|[wma]|[mpc]$/\.wav/gi;
$oggFile =~ s/\.[mp3]|[wma]|[mpc]$/\.ogg/gi;
so ersetzt er jedes Vorkommen von "m", "p", "3", "w" und "a" durch "ogg" bzw. "wav", weil Du nach Klassen suchst. [abc] meint nämlich ein Zeichen das entweder "a", "b" oder "c" ist. Das $ wirkt wirkt nur auf die letzte Klasse hier. Grupperien müsste helfen. Der globale Mustervergleich macht übrigens auch keinen Sinn wenn Du eh nur aufs Ende vergleichen willst (hat aber mit dem Fehler nichts zu tun). Mach daraus mal:
$wavFile =~ s/\.(mp3|wma|mpc)$/\.wav/i;
$oggFile =~ s/\.(mp3|wma|mpc)$/\.ogg/i;

Tuxist
11-07-2005, 13:55
jetzt kommt:


ERROR: Multiple files specified when using stdin

sticky bit
11-07-2005, 18:45
Mal statt den Backticks system() benutzen und den Rückgabe-Wert überprüfen. Scheint ein Fehler vorzuliegen, das verwendete Kommando ausgeben, dass man sehen kann wos da hacken könnte.

Tuxist
13-07-2005, 20:53
#! /usr/bin/perl

### mp3 and wma to ogg by darklinux presents
###no warrenty

use warnings;
use strict;
use File::Find ();

main();

sub convert_to_wav
{
my $file = shift;
my $wavFile = $file;
$wavFile =~ ~ s/(\s)/\\$1/g;
$wavFile =~ s/\.(mp3|wma|mpc)$/\.wav/i;
my $convert_to_wav="mplayer ./$file -ao pcm -aofile ./$wavFile";
my $cmd=`$convert_to_wav`;

}

sub convert_to_ogg
{
my $file = shift;
my $oggFile = $file;
$oggFile =~ ~ s/(\s)/\\$1/g;
$oggFile =~ s/\.(mp3|wma|mpc)$/\.ogg/i;
my $convert_to_ogg="oggenc -q 4 ./$file ./$oggFile";
my $cmd=`$convert_to_ogg`;

}

sub readDir
{
my $dir = shift;
my $arrayRef = shift;

print("Reading dir: $dir\n");

opendir( DIR,"$dir") || die "Could not open $dir\n";
foreach ( readdir ( DIR ) )
{
# no hidden files and no .. and .
next if ( $_ =~ /^\./ );

# another dir? just enter it and read the files too
readDir ( "$dir/$_", $arrayRef ) if ( -d $_ );

# push to array if file is readable
push ( @{$arrayRef}, "$dir/$_" ) if ( -r $_ );
}
}

sub main
{
my @files = ();
my $dir = `pwd`;
chomp($dir);
readDir ( $dir, \@files );
foreach ( @files )
{
if ( $_ =~ /\.mp3$/i || $_ =~ /\.wma$/i || $_ =~ /\.mpc$/i )
{
convert_to_wav( $_ );
convert_to_ogg( $_ );
}
}
exit 0;
}
geht immer noch nicht
Fehlermeldung:


Reading dir: /backup/Musik/music5/echte musik/Bad Religion/Recipe for hate
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-12-Modern day catastrophists.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-12-Modern day catastrophists.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-06-All good soldiers.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-06-All good soldiers.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-13-Skyscraper.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-13-Skyscraper.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-07-Watch it die.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-07-Watch it die.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-02-Kerosene.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-02-Kerosene.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-01Recipe for hate.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-01Recipe for hate.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-08-Struck a nerve.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-08-Struck a nerve.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-09-My poor friend me.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-09-My poor friend me.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-10-Lookin in.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-10-Lookin in.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-14-Stealth.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-14-Stealth.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-04-Portrait of authority.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-04-Portrait of authority.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-11-Dont\ pray\ on\ me.mp3 .//backup/Musik/music5/echte\ musik/Bad\ Religion/Recipe\ for\ hate/Bad\ Religion-11-Dont pray on me.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-03-American Jesus.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-03-American Jesus.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-05-Man with a mission.mp3": Datei oder Verzeichnis nicht gefunden
ERROR: Cannot open input file ".//backup/Musik/music5/echte musik/Bad Religion/Recipe for hate/Bad Religion-05-Man with a mission.ogg": Datei oder Verzeichnis nicht gefunden

michael.sprick
13-07-2005, 23:30
Cannot open input file ".//backup/Musik/m

bist du sicher, dass das der Pfad ist? Du benutzt beim Aufrufen einen relativen Pfad und beim Durchsuchen des Verzeichnisses einen absoluten...

Wenn das nicht so gewollt war, dann ändere mal:


my $convert_to_wav="mplayer ./$file -ao pcm -aofile ./$wavFile";

in

my $convert_to_wav="mplayer $file -ao pcm -aofile $wavFile";

und


my $convert_to_ogg="oggenc -q 4 ./$file ./$oggFile"
in

my $convert_to_ogg="oggenc -q 4 $file $oggFile"

Tuxist
14-07-2005, 18:36
Reading dir: /backup/Musik/music5/echte musik/Bad Religion/Against The Grain
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-15-Unacceptable.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-15-Unacceptable.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-16-Quality Or Quantity.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-16-Quality Or Quantity.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-01-Modern Man.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-01-Modern Man.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-10-Against the Grain.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-10-Against the Grain.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-03-Get Off.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-03-Get Off.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-17-Walk Away.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-17-Walk Away.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-11-Operation Rescue.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-11-Operation Rescue.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-13-21st Century Digital Boy.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-13-21st Century Digital Boy.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-07-Flat Earth Society.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-07-Flat Earth Society.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-14-Misery And Famine.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-14-Misery And Famine.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-02-Turn on the Light.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-02-Turn on the Light.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-06-Anesthesia.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-06-Anesthesia.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-04-Blenderhead.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-04-Blenderhead.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-09-Entropy.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-09-Entropy.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-05-Positive Aspect of Negative Thinking.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-05-Positive Aspect of Negative Thinking.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-08-Faith Alone.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-08-Faith Alone.ogg": Datei oder Verzeichnis nicht gefunden
ERROR: Input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-12-God Song.mp3" is not a supported format
ERROR: Cannot open input file "/backup/Musik/music5/echte musik/Bad Religion/Against The Grain/Bad Religion-12-God Song.ogg": Datei oder Verzeichnis nicht gefunden
jan@work2:/backup/Musik/music5/echte musik/Bad Religion/Against The Grain$

baumgartner
17-07-2005, 14:07
wenn du willst kannst du mein skript verwenden :)

das erstellen der unterordner funkt. noch nicht richtig, dateien werden alle nach /ogg gerippt.

mfg baumi


#!/usr/bin/perl
# mp3 - ogg converter by baumi
# This Programm is liecensed under the Gnu GPL
# This programm uses mpg321 and vorbis-tools(oggenc)
# for problems mail to noSPAM! or rap1@gmx.at
# www.8ung.at/rap
#
# have a nice day
# baumi



use Term::ANSIColor qw(:constants);

$datei= "/mp3/playlist.txt";
@playlist=();
$pfad="/mp3";


# convertiert dateien
sub add_track {
my ($var, $pfad) = @_ ;
if ($var =~ /.*\.mp3/i){

$pfad =~ /\/?(.*)/;
$pfad = $1;

if (-d "ogg/$pfad"){
print RED, "Erstelle /ogg/$pfad\n",RESET;
my $cmd = "mkdir /ogg/$pfad";
system ($cmd);
}

$var =~ /\/?(.*)\.mp3/i;
my $ogg = "$1.ogg";
my $mp3 = "$1.mp3";
print "convert ", GREEN, "/$pfad/$mp3",RESET, " to",BLUE," $ogg\n",RESET ;
my $sys=" mpg321 -s '/$pfad/$mp3' -w - | oggenc - -o '/ogg/$pfad/$ogg' ";
system ($sys);
}
}





#liest den inhalt
sub read_dir {
my $pfad= shift @_;
opendir (CONF,"$pfad")
or warn "kann eingegebenes verzeichniss $pfad nicht oeffnen: $!";
my @inhalt = readdir CONF;
closedir(CONF);
@inhalt;
}



sub search_dir {
my $pfad = shift @_;
my @inhalt = @_;
foreach $datei(@inhalt){
next if $datei eq "." or $datei eq ".."; # . , .. herausfiltern
$pfad_neu = "$pfad/$datei";
if (-d $pfad_neu) {
my @inhalt = &read_dir($pfad_neu);
&add_track($_,$pfad_neu) foreach (@inhalt);
&search_dir($pfad_neu, @inhalt) foreach (@inhalt); #Ordner solange durchsuchen bis
#es keine unterverzeichnisse mehr gibt
}
}
}

sub help{
print <<END ;
-h\tthis text

mp3-2ogg /path/to ( absolut path )


END
print "For more Information visit ",GREEN," www.8ung.at/rap",RESET," [English Site is under Construktion]\n";
print "Written by Baumgartner Martin";
exit;

}



if (@ARGV){ #Kommandozeilenparameter einlesen

$pfad = $ARGV[0];
&help if ($pfad eq -h);

}
else { help;}

@inhalt = &read_dir($pfad);

&add_track($_,$pfad) foreach (@inhalt);

&search_dir($pfad,@inhalt);
#print "schreibe $pfad nach $datei\n";

baumgartner
19-07-2005, 19:09
und hats geklappt ??

Tuxist
19-07-2005, 21:39
ja löscht bloß nicht die alten mp3s

baumgartner
19-07-2005, 22:02
dass soll es auch nicht :)

mfg baumi