LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl MP3 ID3 (https://www.linuxquestions.org/questions/programming-9/perl-mp3-id3-4175410827/)

timehandel 06-11-2012 04:06 AM

Perl MP3 ID3
 
hey ich habe hier schonmal ein prgramm geschrieben das mp3 tags ausliest und sie anzeigt, einen ordner erstellt mit dem namen des künstlers und dem album.

jetzt wollte ich eig das die mp3 datei auch in den neuen ordner verschoben wird mit dem move befehl, aber das funktioniert nicht.

kann mir einer vielleicht dabei helfen.

im code habe ich die zeile

or die "Could not move '$filename' zu '$cwd/$targetdir/':$!";

als fehlermeldung gibt es: Could not move '04 - Too Close.mp3' zu 'G:/perl/Alex Clare - The Lateness Of The Hour/':Permission denied at mkdir.pl line 62.

desweiteren wollte ich auch noch die tags der mp3 datei verändern, aber habe auch keine richtige ahnung wie ich da vorgehen soll.

Code:

#!perl

use warnings;
use strict;

use MP3::Tag;
use File::Find;
use File::Copy;
use Cwd;

my $cwd    = getcwd;                    # Arbeitsverzeichnis               
my $mp3dir = $cwd;                      # Default

print "Pfad angeben wo die MP3's sind!!! [keine Eingabe - Aktuelles Verzeichnis]\n";

while (my $input = <STDIN>) {
    last if $input !~ /\S/;            # leere Eingabe
    chomp($input);
    if (-d $input) {                    # Verzeichnis existiert?
        $mp3dir = $input;
        last;
    }
    print "Verzeichnis '$input' existiert nicht. Nochmal versuchen.\n";
}

find(\&wanted, $mp3dir);                # Achtung: Rekursive Suche

sub wanted {
    return unless /\.mp3$/i;            # alles was keine *.mp3 Endung hat wird
                                        # nicht beachtet
    my $filename = $_;
    my $fullpath = $File::Find::name; 
    return if (-d $fullpath);          # Verzeichnisse mit '.mp3' weglassen

    if (my $mp3 = MP3::Tag->new($fullpath)) {
        print "$_ (Tags: ", join(", ",$mp3->get_tags),")\n";
       
        my ($title, $track, $artist, $album, $comment, $year, $genre)
        = $mp3->autoinfo();
       
        print "* Song:    $title\n"
            . "* Track:  $track\n"
            . "* Artist:  $artist\n"
            . "* Album:  $album\n"
            . "* Comment: $comment\n";
         
        my $targetdir = make_dirname_from_tags($artist, $album);
        if (! $targetdir) {
            print "Fehler beim Erzeugen des Ordnernamens!\n";
            return;
        }
       
       
       
        if (! -d $targetdir) {          # existiert noch nicht?
            if (! mkdir("$cwd/$targetdir")) {
                warn "Kann Ordner '$cwd/$targetdir' nicht anlegen: $!";
                return;
            }           
        }
       
        #move($fullpath, "$cwd/$targetdir/$filename")
        or die "Could not move '$filename' zu '$cwd/$targetdir/':$!";
    }
   
}


sub make_dirname_from_tags {
# Hier diejenigen Zeichen in den Tags ersetzen, die für Ordner-/Dateinamen
# verboten sind.

    my @tags = @_;
    return if ! @tags;
    for my $tag (@tags) {
        $tag =~ s/[:,]/_/g;    # Zeichenklasse noch anpassen
    }
    return(join  ' - ' , @tags);
}


pan64 06-11-2012 04:12 AM

kannst du vielleicht auch auf English?

pan64 06-11-2012 04:16 AM

you have the line move .... (probably line 61) commented out, so or die will be executed anyway.
Du hast die Zeile move($fullpath, "$cwd/$targetdir/$filename") auskommentiert aber die Fehlermeldung bleibt.

timehandel 06-11-2012 04:18 AM

hey I have written a Prgramm which reads mp3 tags and displays it, created a folder with the name of the artist and album.

Now I wanted to move the mp3 file in the new folder with the move command, but that does not work.

Perhaps one can help me here.

I have the code in line

or die "Could not move '$ filename' to '$ cwd / $ targetdir /': $!";

as the error message it gives: Could not move '04 - Too Close.mp3 'to' G :/ perl / Alex Clare - The Lateness of the Hour / ': Permission denied at 62nd mkdir.pl line

I would also further modify the tags of the mp3 file, but I do not know what I should do there.

pan64 06-11-2012 04:29 AM

see above, probably you have forgotten a comment sign?

timehandel 06-11-2012 04:31 AM

no i have change it but the error message still remains


All times are GMT -5. The time now is 12:59 AM.