LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-11-2012, 05:06 AM   #1
timehandel
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Rep: Reputation: Disabled
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);
}
 
Old 06-11-2012, 05:12 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
kannst du vielleicht auch auf English?
 
Old 06-11-2012, 05:16 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
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.
 
Old 06-11-2012, 05:18 AM   #4
timehandel
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-11-2012, 05:29 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,792

Rep: Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888Reputation: 2888
see above, probably you have forgotten a comment sign?
 
Old 06-11-2012, 05:31 AM   #6
timehandel
LQ Newbie
 
Registered: Jun 2012
Posts: 3

Original Poster
Rep: Reputation: Disabled
no i have change it but the error message still remains
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding out the bitrate in an MP3 with ID3 tag. stf92 Slackware 5 12-17-2010 02:21 AM
saving id3 tag from mp3 file fstephens Linux - Newbie 3 04-07-2007 02:52 PM
MP3 ID3 Tag/Meta Data heri0n Linux - Software 2 08-28-2006 11:45 AM
Ripping MP3's with ID3 tags... mlissner Fedora 22 08-27-2006 03:12 AM
Updating ID3 (MP3) Tags DJ747 Linux - Software 3 05-15-2005 12:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration