]>
Commit | Line | Data |
---|---|---|
a28fdc01 CS |
1 | #!/usr/bin/perl |
2 | ||
3 | use MP3::Tag; | |
4 | use MP3::Info; | |
5 | ||
6 | require '/var/ipfire/general-functions.pl'; | |
7 | require "${General::swroot}/lang.pl"; | |
8 | require "${General::swroot}/header.pl"; | |
9 | ||
10 | my $filename = ""; | |
11 | my %songs = ""; | |
8871b9f2 | 12 | my $debug = 0; |
a28fdc01 CS |
13 | |
14 | if ($ARGV[0] eq 'scan') { | |
15 | my $command = "find "; | |
16 | chomp $ARGV[1]; | |
17 | $command .= "\"$ARGV[1]\""; | |
18 | if ($ARGV[2] eq 'off'){$command .= " -maxdepth 1";} | |
19 | $command .= " -name *.mp3"; | |
20 | my @files = `$command`; | |
21 | ||
22 | &getExistingSongs(); | |
23 | ||
24 | foreach (@files){ | |
25 | $filename = $_; | |
26 | chomp($filename) | |
27 | &getSongInfo(); | |
28 | } | |
29 | open(DATEI, ">${General::swroot}/mpfire/db/songs.db") || die "Kann Datenbank nicht speichern"; | |
30 | print DATEI %songs; | |
31 | close(DATEI); | |
32 | } | |
33 | ||
34 | if ($ARGV[0] eq 'getdb') { | |
35 | &getExistingSongs(); | |
36 | print %songs; | |
37 | } | |
bac7231b | 38 | elsif ($ARGV[0] eq 'play') { |
8871b9f2 | 39 | &checkplaylist(); |
a28fdc01 CS |
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 | } | |
bac7231b | 43 | elsif ($ARGV[0] eq 'stop') { |
8871b9f2 CS |
44 | my $PID = `ps -ef \| grep wget \| grep EXTM3U \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; |
45 | if ( $PID ne '' ){ | |
46 | if ($debug){print "Stopping $PID\n";} | |
47 | system("kill -KILL $PID"); | |
48 | my $PID = `ps -ef \| grep "mpg123 -b 1024 --aggressive -Zq -" \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; | |
49 | if ($debug){print "Killing Process $PID\n";} | |
50 | system("kill -KILL $PID"); | |
51 | } | |
52 | else{ | |
53 | my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; | |
54 | if ($debug){print "Stopping $PID\n";} | |
55 | system("kill -KILL $PID"); | |
56 | } | |
a28fdc01 | 57 | } |
bac7231b | 58 | elsif ($ARGV[0] eq 'volup') { |
a28fdc01 CS |
59 | if ($debug){print "Increasing Volume\n";} |
60 | system("/usr/bin/amixer set Master $ARGV[1]%+ 2>/dev/null >/dev/null"); | |
61 | } | |
bac7231b | 62 | elsif ($ARGV[0] eq 'voldown') { |
a28fdc01 CS |
63 | if ($debug){print "Decreasing Volume\n";} |
64 | system("/usr/bin/amixer set Master $ARGV[1]%- 2>/dev/null >/dev/null"); | |
65 | } | |
bac7231b | 66 | elsif ($ARGV[0] eq 'playall') { |
8871b9f2 | 67 | &checkplaylist(); |
a28fdc01 CS |
68 | if ($debug){print "Playing everything\n";} |
69 | system("/usr/bin/mpg123 -b 1024 --aggressive -Zq@ /var/ipfire/mpfire/playlist 2>/dev/null >/dev/null &"); | |
70 | } | |
bac7231b | 71 | elsif ($ARGV[0] eq 'pause') { |
8871b9f2 | 72 | my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; |
a28fdc01 CS |
73 | if ($debug){print "Pausing Process $PID\n";} |
74 | system("kill -STOP $PID"); | |
75 | } | |
bac7231b | 76 | elsif ($ARGV[0] eq 'resume') { |
8871b9f2 | 77 | my $PID = `ps -ef \| grep mpg123 \| grep playlist \| head -1 \| grep -v "sh -c" \| awk '{ print \$2 }'`; |
a28fdc01 CS |
78 | if ($debug){print "Resuming Process $PID\n";} |
79 | system("kill -CONT $PID"); | |
80 | } | |
bac7231b | 81 | elsif ($ARGV[0] eq 'next') { |
a28fdc01 CS |
82 | if ($debug){print "Next Song\n";} |
83 | my $PID = `ps -ef | grep mpg123 | grep playlist | head -1 | awk '{ print \$2 }'`; | |
84 | system("kill -SIGINT $PID"); | |
85 | } | |
bac7231b CS |
86 | elsif ($ARGV[0] eq 'song') { |
87 | my $song = `lsof -nX \| grep mpg123 \| grep REG \| grep mem | grep mp3 \| grep -v "sh -c"`; | |
a2d5130f CS |
88 | my @song = split(/\//,$song); |
89 | my $i = @song; | |
bac7231b CS |
90 | if ( $i == 0 ){ |
91 | my $song = `ps -ef \| grep wget \| grep EXTM3U \| grep -v "sh -c"`; | |
8871b9f2 CS |
92 | my @song = split(/,/,$song); |
93 | print $song[1]; | |
a2d5130f | 94 | } |
bac7231b CS |
95 | else { print $song[$i-1];} |
96 | } | |
97 | elsif ($ARGV[0] eq 'playweb') { | |
a2d5130f | 98 | &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); |
8871b9f2 | 99 | |
a2d5130f CS |
100 | if ($proxysettings{'UPSTREAM_PROXY'}) { |
101 | if ($proxysettings{'UPSTREAM_USER'}) { | |
8871b9f2 CS |
102 | &checkm3uproxy(); |
103 | if ($debug){print "Playing webstream\n";} | |
104 | system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &"); | |
a2d5130f | 105 | } |
8871b9f2 CS |
106 | else { |
107 | &checkm3uproxyuser(); | |
108 | if ($debug){print "Playing webstream\n";} | |
109 | system("wget -qO - `wget -qO - http://$proxysettings{'UPSTREAM_PROXY'}$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &");} | |
a2d5130f | 110 | } else { |
8871b9f2 CS |
111 | &checkm3u(); |
112 | if ($debug){print "Playing webstream\n";} | |
113 | system("wget -qO - `wget -qO - http://$ARGV[1]` | mpg123 -b 1024 --aggressive -Zq - 2>/dev/null >/dev/null &"); | |
a2d5130f CS |
114 | } |
115 | } | |
a2d5130f | 116 | |
a28fdc01 CS |
117 | sub getSongInfo(){ |
118 | my $mp3 = MP3::Tag->new($filename); | |
119 | my ($title, $track, $artist, $album, $comment, $year, $genre) = $mp3->autoinfo(); | |
120 | my $info = get_mp3info($filename); | |
121 | $mp3->close(); | |
122 | $songs{$filename} = "|".$artist."|".$title."|".$track."|".$album."|".$year."|".$genre."|".$info->{MM}."|".$info->{SS}."|".$info->{BITRATE}."|".$info->{FREQUENCY}."|".$info->{MODE}."\n"; | |
123 | } | |
124 | ||
125 | sub getExistingSongs(){ | |
126 | open(DATEI, "<${General::swroot}/mpfire/db/songs.db") || die "Keine Datenbank vorhanden"; | |
127 | my @Zeilen = <DATEI>; | |
128 | close(DATEI); | |
129 | foreach (@Zeilen){ | |
130 | my @Zeile = split(/\|/,$_); | |
131 | $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"; | |
132 | } | |
133 | } | |
8871b9f2 CS |
134 | |
135 | sub checkplaylist(){ | |
136 | my $Datei = "/var/ipfire/mpfire/playlist"; | |
137 | my @Info = stat($Datei); | |
138 | if ( $Info[7] eq '' ){print "There is no playlist";exit(1);} | |
139 | } | |
140 | ||
141 | sub checkm3u(){ | |
142 | my $Datei = system("wget -q --spider http://$ARGV[1]"); | |
143 | if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);} | |
144 | } | |
145 | ||
146 | sub checkm3uproxy(){ | |
147 | my $Datei = system("wget -q --spider http://$ARGV[1]"); | |
148 | if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);} | |
149 | } | |
150 | ||
151 | sub checkm3uproxyuser(){ | |
152 | my $Datei = system("wget -q --spider http://$ARGV[1]"); | |
153 | if ( $Datei ne '0' ){print "We are unable to get the stream";exit(1);} | |
154 | } |