]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - config/mpfire/mpfire.pl
MPFire hinzugefĆ¼gt - CGI mpg123 Frontend
[people/pmueller/ipfire-2.x.git] / config / mpfire / mpfire.pl
CommitLineData
a28fdc01
CS
1#!/usr/bin/perl
2
3use MP3::Tag;
4use MP3::Info;
5
6require '/var/ipfire/general-functions.pl';
7require "${General::swroot}/lang.pl";
8require "${General::swroot}/header.pl";
9
10my $filename = "";
11my %songs = "";
12my $debug = 0;
13
14if ($ARGV[0] eq 'scan') {
15my $command = "find ";
16chomp $ARGV[1];
17$command .= "\"$ARGV[1]\"";
18if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";}
19$command .= " -name *.mp3";
20my @files = `$command`;
21
22&getExistingSongs();
23
24foreach (@files){
25 $filename = $_;
26 chomp($filename)
27 &getSongInfo();
28 }
29open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern";
30print DATEI %songs;
31close(DATEI);
32}
33
34if ($ARGV[0] eq 'getdb') {
35 &getExistingSongs();
36 print %songs;
37 }
38
39if ($ARGV[0] eq 'play') {
40 if ($debug){print "Yes we are called and we will play $ARGV[1]\n";}
41 system("/usr/bin/mpg123 -b 1024 --aggressive -q \"$ARGV[1]\" 2>/dev/null >/dev/null &");
42 }
43
44if ($ARGV[0] eq 'stop') {
45 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
46 if ($debug){print "Stopping $PID\n";}
47 system("kill -KILL $PID");
48 }
49
50if ($ARGV[0] eq 'volup') {
51 if ($debug){print "Increasing Volume\n";}
52 system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null");
53 }
54
55if ($ARGV[0] eq 'voldown') {
56 if ($debug){print "Decreasing Volume\n";}
57 system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null");
58 }
59
60if ($ARGV[0] eq 'playall') {
61 if ($debug){print "Playing everything\n";}
62 system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &");
63 }
64
65if ($ARGV[0] eq 'pause') {
66 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
67 if ($debug){print "Pausing Process $PID\n";}
68 system("kill -STOP $PID");
69 }
70
71if ($ARGV[0] eq 'resume') {
72 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
73 if ($debug){print "Resuming Process $PID\n";}
74 system("kill -CONT $PID");
75 }
76
77if ($ARGV[0] eq 'next') {
78 if ($debug){print "Next Song\n";}
79 my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`;
80 system("kill -SIGINT $PID");
81 }
82
83sub getSongInfo(){
84 my $mp3 = MP3::Tag->new($filename);
85 my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo();
86 my $info = get_mp3info($filename);
87 $mp3->close();
88 $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n";
89 }
90
91sub getExistingSongs(){
92 open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden";
93 my @Zeilen = <DATEI>;
94 close(DATEI);
95 foreach (@Zeilen){
96 my @Zeile = split(/\|/,$_);
97 $songs{$Zeile[0]} = "|".$Zeile[1]."|".$Zeile[2]."|".$Zeile[3]."|".$Zeile[4]."|".$Zeile[5]."|".$Zeile[6]."|".$Zeile[7]."|".$Zeile[8]."|".$Zeile[9]."|".$Zeile[10]."|".$Zeile[11]."\n";
98 }
99 }