X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Fmpfire.cgi;h=9415dc6488dbd325dab008526e806546591bc645;hp=537f8cadf8d03cf7906891e2b2cf16fa2291be58;hb=70ccd4a7b550782fce2fd5ac7084d69a45a7720e;hpb=92cf793cf2a1e82c932f3a6eb5fe742924ffcdd5 diff --git a/html/cgi-bin/mpfire.cgi b/html/cgi-bin/mpfire.cgi index 537f8cadf8..9415dc6488 100644 --- a/html/cgi-bin/mpfire.cgi +++ b/html/cgi-bin/mpfire.cgi @@ -1,28 +1,15 @@ #!/usr/bin/perl -############################################################################### -# # -# IPFire.org - A linux based firewall # -# Copyright (C) 2007 Michael Tremer & Christian Schmidt # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### +# +# IPFire CGIs +# +# This code is distributed under the terms of the GPL +# +# (c) The IPFire Team use strict; # enable only the following on debugging purpose -#use warnings; -#use CGI::Carp 'fatalsToBrowser'; +use warnings; +use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; @@ -35,11 +22,6 @@ my %checked = (); my $message = '0'; my $errormessage = ""; -open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "No Database found"; -my @songdb = ; -close(DATEI); -@songdb = sort(@songdb); - &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); @@ -49,6 +31,44 @@ sub refreshpage{&Header::openbox( 'Waiting', 1, "; +close(DATEI); + +my @artist; my @album; my @genre; my @year; my $linecount = 0; my @currentsong = ""; my %songs; +foreach (@songdb){ + + if ( $_ =~ /mtime: / ){ + $songs{$currentsong[1]}="$currentsong[2]|$currentsong[3]|$currentsong[4]|$currentsong[5]|$currentsong[6]|$currentsong[7]|$currentsong[8]|$currentsong[9]"; + push(@artist,$currentsong[4]); + push(@album,$currentsong[6]); + push(@year,$currentsong[8]); + push(@genre,$currentsong[9]); + @currentsong = ""; + } + elsif ( $_ =~ /key: / || $_ =~ /file: / || $_ =~ /Time: / || $_ =~ /Artist: / || $_ =~ /Title: / || $_ =~ /Album: / || $_ =~ /Track: / || $_ =~ /Date: / || $_ =~ /Genre: / ){ + my @temp = split(/: /,$_); + push(@currentsong,$temp[1]); + } + else { + next; + } + } + + my %hash = map{ $_, 1 }@artist; + @artist = sort keys %hash; + my %hash = map{ $_, 1 }@album; + @album = sort keys %hash; + my %hash = map{ $_, 1 }@year; + @year = sort keys %hash; + my %hash = map{ $_, 1 }@genre; + @genre = sort keys %hash; + + my $artistcount = $#artist+1; + my $albumcount = $#album+1; + my $yearcount = $#year+1; + my $genrecount = $#genre+1; + &Header::getcgihash(\%mpfiresettings); &Header::openpage($Lang::tr{'mpfire'}, 1, ""); &Header::openbigbox('100%', 'left', '', $errormessage); @@ -60,110 +80,111 @@ if ( $mpfiresettings{'ACTION'} eq "scan" ) { delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'}; &General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings); -$message=system("/usr/local/bin/mpfirectrl scan $mpfiresettings{'SCANDIR'} $mpfiresettings{'SCANDIRDEPS'}"); +open(DATEI, "<${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden"; +my @Zeilen = ; +close(DATEI); +open(DATEI, ">${General::swroot}/mpfire/mpd.conf") || die "Datei nicht gefunden"; +foreach (@Zeilen){ +if ( $_ =~ /music_directory/){print DATEI "music_directory \"".$mpfiresettings{'MUSICDIR'}."\"\n";} +else {print DATEI $_;} +} +close(DATEI); + +$message=system("/usr/local/bin/mpfirectrl scan"); refreshpage(); } elsif ( $mpfiresettings{'ACTION'} eq ">" ){$message=system("/usr/local/bin/mpfirectrl","play","\"$mpfiresettings{'FILE'}\"");} elsif ( $mpfiresettings{'ACTION'} eq "x" ){$message=system("/usr/local/bin/mpfirectrl stop");} -elsif ( $mpfiresettings{'ACTION'} eq "||" ){$message=system("/usr/local/bin/mpfirectrl pause");} -elsif ( $mpfiresettings{'ACTION'} eq "|>" ){$message=system("/usr/local/bin/mpfirectrl resume");} +elsif ( $mpfiresettings{'ACTION'} eq "|>" ){$message=system("/usr/local/bin/mpfirectrl toggle");} +elsif ( $mpfiresettings{'ACTION'} eq "<<" ){$message=system("/usr/local/bin/mpfirectrl prev");} elsif ( $mpfiresettings{'ACTION'} eq ">>" ){$message=system("/usr/local/bin/mpfirectrl next");} -elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){$message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");} elsif ( $mpfiresettings{'ACTION'} eq "+" ){$message=system("/usr/local/bin/mpfirectrl volup 5");} elsif ( $mpfiresettings{'ACTION'} eq "-" ){$message=system("/usr/local/bin/mpfirectrl voldown 5");} elsif ( $mpfiresettings{'ACTION'} eq "++" ){$message=system("/usr/local/bin/mpfirectrl volup 10");} elsif ( $mpfiresettings{'ACTION'} eq "--" ){$message=system("/usr/local/bin/mpfirectrl voldown 10");} -elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){$message=system("/usr/local/bin/mpfirectrl playall");} -elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){$message=system("unlink ${General::swroot}/mpfire/playlist && touch ${General::swroot}/mpfire/playlist");} -elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){ -open(DATEI, ">>${General::swroot}/mpfire/playlist") || die "Could not add playlist"; -print DATEI $mpfiresettings{'FILE'}."\n"; -close(DATEI); -} +elsif ( $mpfiresettings{'ACTION'} eq "playweb" ){$message=system("/usr/local/bin/mpfirectrl","playweb","\"$mpfiresettings{'FILE'}\"");} +elsif ( $mpfiresettings{'ACTION'} eq "playlist" ){$message=system("/usr/local/bin/mpfirectrl playlist");} +elsif ( $mpfiresettings{'ACTION'} eq "emptyplaylist" ){$message=system("/usr/local/bin/mpfirectrl clearplaylist");} +elsif ( $mpfiresettings{'ACTION'} eq "addtoplaylist" ){$message=system("/usr/local/bin/mpfirectrl","playadd","\"$mpfiresettings{'FILE'}\"");} +elsif ( $mpfiresettings{'ACTION'} eq "playall" ){$message=system("/usr/local/bin/mpfirectrl playall");} elsif ( $mpfiresettings{'ACTION'} eq "playalbum" ) { -my @temp = ""; -my @album = split(/\|/,$mpfiresettings{'album'}); -my %hash = map{ $_, 1 }@album; - -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[4]}; +my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'album'}); + +foreach (keys(%songs)){ + @song = split(/\|/,$songs{$_});$song[4] =~ s/\W/ /g; + + foreach (@select){ + $_ =~ s/\W/ /g; + if ( $song[4] =~ /$_/ ){push(@temp,$song[0]);} } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; +} + +open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); -$message=system("/usr/local/bin/mpfirectrl playall"); +$message=system("/usr/local/bin/mpfirectrl playlist"); } elsif ( $mpfiresettings{'ACTION'} eq "playartist" ) { -my @temp = ""; -my @artist = split(/\|/,$mpfiresettings{'artist'}); -my %hash = map{ $_, 1 }@artist; - -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[1]}; +my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'artist'}); + +foreach (keys(%songs)){ + @song = split(/\|/,$songs{$_});$song[2] =~ s/\W/ /g; + + foreach (@select){ + $_ =~ s/\W/ /g; + if ( $song[2] =~ /$_/ ){push(@temp,$song[0]);} } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; +} + +open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); -$message=system("/usr/local/bin/mpfirectrl playall"); +$message=system("/usr/local/bin/mpfirectrl playlist"); } elsif ( $mpfiresettings{'ACTION'} eq "playyear" ) { -my @temp = ""; -my @year = split(/\|/,$mpfiresettings{'year'}); -my %hash = map{ $_, 1 }@year; - -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[5]}; +my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'year'}); + +foreach (keys(%songs)){ + @song = split(/\|/,$songs{$_});$song[6] =~ s/\W/ /g; + + foreach (@select){ + $_ =~ s/\W/ /g; + if ( $song[6] =~ /$_/ ){push(@temp,$song[0]);} } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; -print DATEI @temp; -close(DATEI); -$message=system("/usr/local/bin/mpfirectrl playall"); } -elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ) -{ -my @temp = ""; -my @genre = split(/\|/,$mpfiresettings{'genre'}); -my %hash = map{ $_, 1 }@genre; -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n") if exists $hash{$song[6]}; - } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; +open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); -$message=system("/usr/local/bin/mpfirectrl playall"); +$message=system("/usr/local/bin/mpfirectrl playlist"); } -elsif ( $mpfiresettings{'ACTION'} eq "playall" ) +elsif ( $mpfiresettings{'ACTION'} eq "playgenre" ) { -my @temp = ""; -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - push(@temp,$song[0]."\n"); +my @temp = ""; my @song = ""; my @select = split(/\|/,$mpfiresettings{'genre'}); + +foreach (keys(%songs)){ + @song = split(/\|/,$songs{$_});$song[7] =~ s/\W/ /g; + + foreach (@select){ + $_ =~ s/\W/ /g; + if ( $song[7] =~ /$_/ ){push(@temp,$song[0]);} } -open(DATEI, ">${General::swroot}/mpfire/playlist") || die "Could not add playlist"; +} + +open(DATEI, ">${General::swroot}/mpfire/playlist.m3u") || die "Could not add playlist"; print DATEI @temp; close(DATEI); -$message=system("/usr/local/bin/mpfirectrl playall"); +$message=system("/usr/local/bin/mpfirectrl playlist"); } elsif ( $mpfiresettings{'SHOWLIST'} ){delete $mpfiresettings{'__CGI__'};delete $mpfiresettings{'x'};delete $mpfiresettings{'y'};delete $mpfiresettings{'PAGE'};&General::writehash("${General::swroot}/mpfire/settings", \%mpfiresettings);refreshpage();} ############################################################################################################################ ################################### Aufbau der HTML Seite fr globale Sambaeinstellungen #################################### -$mpfiresettings{'SCANDIR'} = "/"; -$mpfiresettings{'SHOWLIST'} = "off"; +$mpfiresettings{'MUSICDIR'} = "/"; &General::readhash("${General::swroot}/mpfire/settings", \%mpfiresettings); @@ -179,9 +200,7 @@ print < - - +
$Lang::tr{'Scan for Files'}
$Lang::tr{'Scan from Directory'}
$Lang::tr{'deep scan directories'}on / - off
$Lang::tr{'Scan from Directory'}
@@ -195,6 +214,8 @@ if ( $song eq "" ){$song = "None";} my $Volume = `/usr/local/bin/mpfirectrl volume`; $Volume=~s//
/g; +my $stats = `mpc stats | tail -4`; +$stats=~s/\\/
/g &Header::openbox('100%', 'center', $Lang::tr{'mpfire controls'}); print < -= $song =- END ; -if ( $#songdb eq '-1' ) {print "
total 0 songs

";} -else {print "
total $#songdb songs

";} +my $countsongs=`/usr/local/bin/mpfirectrl stats`; +print "
".$countsongs."

"; print <
-
-
+
+
@@ -224,30 +245,14 @@ print <
$Volume +
$stats END ; &Header::closebox(); -if ( $#songdb ne '0' ){ &Header::openbox('100%', 'center', $Lang::tr{'quick playlist'}); -my @artist; my @album; my @genre; my @year; -foreach (@songdb){ - my @song = split(/\|/,$_); - push(@artist,$song[1]); push(@album,$song[4]); push(@year,$song[5]); push(@genre,$song[6]);} - my %hash = map{ $_, 1 }@artist; - @artist = sort keys %hash; - my %hash = map{ $_, 1 }@album; - @album = sort keys %hash; - my %hash = map{ $_, 1 }@year; - @year = sort keys %hash; - my %hash = map{ $_, 1 }@genre; - @genre = sort keys %hash; - my $artistcount = $#artist+1; - my $albumcount = $#album+1; - my $yearcount = $#year+1; - my $genrecount = $#genre+1; print ""; if ( $#songdb eq '-1' ) {print "";} else {print "";} @@ -306,8 +311,6 @@ print < - - + END ; my $lines=0;my $i=0;my $begin;my $end; if ( $mpfiresettings{'PAGE'} eq 'all' ){ $begin=0; - $end=$#songdb; + $end=keys(%songs); } else{ $begin=(($mpfiresettings{'PAGE'}-1) * 100); $end=(($mpfiresettings{'PAGE'} * 100)-1); } -foreach (@songdb){ +foreach (keys(%songs)){ if (!($i >= $begin && $i <= $end)){ - #print $begin."->".$i."<-".$end."\n"; +# print $begin."->".$i."<-".$end."\n"; $i++;next;} - my @song = split(/\|/,$_); + my @song = split(/\|/,$songs{$_}); + my $minutes = sprintf ("%.0f", $song[1] / 60 ); + my $seconds = $song[1] % 60; if ($lines % 2) {print "";} else {print "";} - $song[0]=~s/\/\//\//g; print <
-
- - + + - + + END ; - if ( $song[11] eq "0\n" ) {print ""; } - elsif ( $song[11] eq "1\n" ) {print ""; } - elsif ( $song[11] eq "2\n" ) {print ""; } - elsif ( $song[11] eq "3\n" ) {print ""; } - else {print ""; } $lines++; $i++; } @@ -377,16 +375,7 @@ print "
$Lang::tr{'artist'}$Lang::tr{'album'}
$Lang::tr{'artist'} - ".$artistcount."$Lang::tr{'album'} - ".$albumcount."

$Lang::tr{'Pages'}

END ; -my $pages =(int($#songdb/100)+1); +my $pages =(int(keys(%songs)/100)+1); for(my $i = 1; $i <= $pages; $i++) { print ""; if (!($i % 205)){print"
";} @@ -332,42 +335,37 @@ print <$Lang::tr{'album'}
$Lang::tr{'year'} $Lang::tr{'genre'}$Lang::tr{'length'}
$Lang::tr{'bitrate'} - $Lang::tr{'frequency'}
$Lang::tr{'mode'}
$Lang::tr{'length'}
$song[1]
$song[2]
$song[3]$song[4]$song[2]
$song[3]
$song[5]$song[4] $song[6]$song[7]:$song[8]
$song[9] - $song[10]
$song[7]$minutes:$seconds
Stereo
Joint
Stereo
Dual
Channel
Single
Channel
"; &Header::openbox('100%', 'center', $Lang::tr{'mpfire playlist'}); -open(DATEI, "<${General::swroot}/mpfire/playlist") || die "Could not open playlist"; -my @playlist = ; -close(DATEI); - -my %hash; -foreach (@songdb){ - my @song = split(/\|/,$_); - chomp($song[0]); - $hash{$song[0]}=$song[1]." - ".$song[2]." - ".$song[7].":".$song[8]; -} +my @playlist = `mpc playlist`; print < @@ -394,7 +383,7 @@ print < @@ -429,7 +418,7 @@ END foreach (@webradio){ my @stream = split(/\|/,$_); print <$stream[1] + $stream[1]
END