recluse
06-12-2002, 03:27 AM
It was both a learning experience and also had some usefulness.
#!/usr/bin/env perl
# recluse
# 20020610
# Gets a list of all my .m3u files and creates a #submenu for
# fluxbox listing them, allowing easy playlist #switching :)
use strict;
use warnings;
use File::Copy;
# Get all of the playlist files
opendir(M3UDIR, "\/home\/recluse\/audio") or die "Can't open M3UDIR\n";
my @m3uList;
foreach((readdir M3UDIR)){
if($_ =~ m/\w+\.m3u/){
push @m3uList, $_;
}
}
close M3UDIR;
# Open the fluxbox menu to read from and a tmp file to write to
my $readMenu = "/home/recluse/.fluxbox/menu";
my $writeMenu = "/home/recluse/.fluxbox/tmpMenu";
open (READMENU, "<$readMenu") or die "Can't open $readMenu for reading\n";
open (WRITEMENU, ">$writeMenu") or die "Can't open $writeMenu for reading\n";
# Remove all the old m3u entries from the menu, no need for repeats
while(<READMENU>){
if($_ !~ m/m3u/){
print WRITEMENU;
}
}
move ($writeMenu, $readMenu) or die "Move failed!$!\n";
close WRITEMENU;
close READMENU;
open (READMENU, "$readMenu") or die "Can't open $readMenu for reading\n";
open (WRITEMENU, ">$writeMenu") or die "Can't open $writeMenu for reading\n";
while(<READMENU>){
if ($_ =~ m/\[submenu\] \(music\) \{\}/){ # Write the playlists
print WRITEMENU;
foreach my $m3u (@m3uList){
print WRITEMENU " " x 12 . "\[exec\] \($m3u\) {xmms -p ~/audio/$m3u}\n";
}
}
else {print WRITEMENU "$_";} # Print the old portions of the menu
}
move ($writeMenu, $readMenu) or die "Move failed $!\n";
close READMENU;
close WRITEMENU;
#!/usr/bin/env perl
# recluse
# 20020610
# Gets a list of all my .m3u files and creates a #submenu for
# fluxbox listing them, allowing easy playlist #switching :)
use strict;
use warnings;
use File::Copy;
# Get all of the playlist files
opendir(M3UDIR, "\/home\/recluse\/audio") or die "Can't open M3UDIR\n";
my @m3uList;
foreach((readdir M3UDIR)){
if($_ =~ m/\w+\.m3u/){
push @m3uList, $_;
}
}
close M3UDIR;
# Open the fluxbox menu to read from and a tmp file to write to
my $readMenu = "/home/recluse/.fluxbox/menu";
my $writeMenu = "/home/recluse/.fluxbox/tmpMenu";
open (READMENU, "<$readMenu") or die "Can't open $readMenu for reading\n";
open (WRITEMENU, ">$writeMenu") or die "Can't open $writeMenu for reading\n";
# Remove all the old m3u entries from the menu, no need for repeats
while(<READMENU>){
if($_ !~ m/m3u/){
print WRITEMENU;
}
}
move ($writeMenu, $readMenu) or die "Move failed!$!\n";
close WRITEMENU;
close READMENU;
open (READMENU, "$readMenu") or die "Can't open $readMenu for reading\n";
open (WRITEMENU, ">$writeMenu") or die "Can't open $writeMenu for reading\n";
while(<READMENU>){
if ($_ =~ m/\[submenu\] \(music\) \{\}/){ # Write the playlists
print WRITEMENU;
foreach my $m3u (@m3uList){
print WRITEMENU " " x 12 . "\[exec\] \($m3u\) {xmms -p ~/audio/$m3u}\n";
}
}
else {print WRITEMENU "$_";} # Print the old portions of the menu
}
move ($writeMenu, $readMenu) or die "Move failed $!\n";
close READMENU;
close WRITEMENU;