#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::FileSelect; use MP3::ID3v1Tag; my $file; my $select; my %info; my @info = qw/title artist album year genre genre_num comment/; my %mp3; #Frames deklarieren my %config; $config{main} = MainWindow->new(); $config{up} = $config{main}->Frame()->pack(-side => 'top'); $config{bottom} = $config{main}->Frame()->pack(-side => 'bottom'); $config{bottom_left} = $config{bottom}->Frame()->pack(-side => 'left'); $config{bottom_right} = $config{bottom}->Frame()->pack(-side => 'right'); $config{middle} = $config{main}->Frame()->pack(-side => 'bottom'); $config{middle_left} = $config{middle}->Frame()->pack(-side => 'left'); $config{middle_right} = $config{middle}->Frame()->pack(-side => 'right'); $config{top} = $config{main}->Frame()->pack(-side => 'top'); $config{top_left} = $config{top}->Frame()->pack(-side => 'left'); $config{top_right} = $config{top}->Frame()->pack(-side => 'right'); #Titel erzeugen $config{main}->configure(-title => "MP3 Tag Editor"); #Überschrift erzeugen $config{header} = $config{up}->Label(-text => 'MP3 Tag Editor', -font => '{Arial} 15 {underline}')->pack(); #Buttons erzeugen $config{button_save} = $config{bottom_left}->Button(-text => 'Save', -command => \&save)->pack(-side => 'left'); $config{button_exit} = $config{bottom_right}->Button(-text => 'Quit', -command => sub { $config{main}->destroy(); })->pack(-side => 'right'); $config{button_clear} = $config{bottom_right}->Button(-text => 'Clear', -command => \&clear)->pack(); #MP3 Selektion $config{top_left}->Entry(-textvariable => \$file)->pack(-side => 'top'); $config{top_right}->Button(-text => 'MP3', -command => \&mp3_select)->pack(-side => 'top'); #Hauptinhalt erzeugen foreach (@info) { $config{middle_left}->Label(-text => "$_")->pack(); $mp3{$_} = $config{middle_right}->Entry(-textvariable => \$info{$_})->pack(); } MainLoop(); sub mp3_select { $select = $config{main}->FileSelect(-directory => './'); $file= ""; $file = $select->Show; unless($file =~ /.*\.mp3/i) { $file = ""; $config{error} = $config{main}->Toplevel(); $config{error}->Label(-text => 'Kann nur MP3 Dateien öffnen !')->pack(); $config{error}->Button(-text => 'Schließen', -command => sub { $config{error}->destroy(); })->pack(-side => 'bottom'); } else { &mp3_info(); } } sub mp3_info { my $mp3_file = new MP3::ID3v1Tag($file); foreach my $info (@info) { my $tmp = "get_$info"; $info{$info} = $mp3_file->$tmp(); } } sub clear { foreach (@info) { $mp3{$_}->delete('0.0','end'); } } sub save { my $mp3_file = new MP3::ID3v1Tag($file); foreach (@info) { my $tmp = "set_$_"; my $new = $mp3{$_}->get(); $mp3_file->$tmp($new); my $save_status = $mp3_file->save(); unless($save_status) { $config{popup} = $config{main}->Toplevel(); $config{popup}->Label(-text => "Fehler beim sichern von $_")->pack(); $config{popup}->Button(-text => 'Schließen', -command => sub { $config{popup}->destroy(); })->pack(-side => 'bottom'); } } }