]>
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 = ""; | |
12 | my $debug = 0; | |
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 | } | |
38 | ||
39 | if ($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 | ||
44 | if ($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 | ||
50 | if ($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 | ||
55 | if ($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 | ||
60 | if ($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 | ||
65 | if ($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 | ||
71 | if ($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 | ||
77 | if ($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 | ||
83 | sub 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 | ||
91 | sub 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 | } |