#!/usr/bin/perl #H# This script will use Perl/TK to pop up a play list editor for the #H# song currently playing in xmms. No params needed. # print out help info if requested if ($ARGV[0] ne "") { open (SELF, $0); while () { if ($_ =~ /^#H# /) { $_ =~ s/^#H# //; print $_; } } exit; } use Tk; use DBI; $DB= DBI->connect("DBI:mysql:music:asylum.sanitarium.net" . ";mysql_read_default_file=/home/asylum/kmk/.my.cnf", kmk, $password); # Find out the fully qualified file name that is currently playing in xmms. # Note that the file doesn't have to actually be playing just the currently open file. #$FQFN=`xmmsctrl print %F`; $FQFN=`audtool current-song-filename | sed -e 's/^file...//' -e 's/%20/ /g'`; chomp $FQFN; $FQFN =~ s/'/\\'/g; # Chop up the FQFN into a path and a filename. @PathParts=split (/\//,$FQFN); $NumPathParts=$#PathParts; $Path=""; $Loop=0; foreach $PathPart (@PathParts) { if ($Loop == $NumPathParts) { $FileName=$PathPart; } else { $Path="$Path/$PathPart"; } $Loop++; } $Path =~ s/\/\//\//g; # No extensions in the db $FileName =~ s/\.mp3$//; $FileName =~ s/\.flac$//; $FileName =~ s/\.ac3$//; $FileName =~ s/\.ogg$//; $FileName =~ s/\.aac$//; # Get the file info from the db... $QueryString="select ID, PlayLists, FileName from tunes where Path='$Path' and FileName like '$FileName'"; #print "$QueryString\n"; $QueryHandle=$DB->prepare($QueryString); $QueryHandle->execute; while (@Data=$QueryHandle->fetchrow_array) { ($ID, $PlayLists, $FileName)=@Data; #print ("$ID:$PlayLists:$FileName\n"); } # Set to no playlists by default. $ISchick_metal=0; $ISdeath_metal=0; $ISgood_riffs=0; $ISGTA=0; $ISheavy_metal=0; $IShardcore_rock=0; $ISalternative_rock=0; $ISatheist=0; $IShardcore_techno=0; $ISpatriotic=0; $ISpower_metal=0; $ISxmas=0; $ISie=0; $ISopenbsd=0; # Set up the current playlists... if ($PlayLists =~ /80s/) { $IS80s=1; } if ($PlayLists =~ /alternative_rock/) { $ISalternative_rock=1; } if ($PlayLists =~ /atheist/) { $ISatheist=1; } if ($PlayLists =~ /chick_metal/) { $ISchick_metal=1; } if ($PlayLists =~ /death_metal/) { $ISdeath_metal=1; } if ($PlayLists =~ /game_music/) { $ISgame_music=1; } if ($PlayLists =~ /good_riffs/) { $ISgood_riffs=1; } if ($PlayLists =~ /GTA/) { $ISGTA=1; } if ($PlayLists =~ /heavy_metal/) { $ISheavy_metal=1; } if ($PlayLists =~ /hardcore_rock/) { $IShardcore_rock=1; } if ($PlayLists =~ /hardcore_techno/) { $IShardcore_techno=1; } if ($PlayLists =~ /ie/) { $ISie=1; } if ($PlayLists =~ /openbsd/) { $ISopenbsd=1; } if ($PlayLists =~ /patriotic/) { $ISpatriotic=1; } if ($PlayLists =~ /power_metal/) { $ISpower_metal=1; } if ($PlayLists =~ /xmas/) { $ISxmas=1; } # now for some Tk stuff... # make window $mw = MainWindow->new; # set the font $mw->fontCreate('textfont', -family => 'moulinrouge', -size => 18); # set the default colors $mw->setPalette(background => 'Black', foreground => 'White'); # set the window title $mw->title("Playlist Editor"); # Display the filename that we are working on $mw->Button(-wraplength => 800, -foreground => 'Green', -background => 'Dark Blue', -activeforeground => 'Green', -activebackground => 'Dark Blue', -text => $FileName, -font => 'textfont', -relief => 'ridge', -borderwidth => 8 ) ->pack; # Display a list of possible play lists with check boxes $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"80s", -variable=>\$IS80s, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Alternative Rock", -variable=>\$ISalternative_rock, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Atheist", -variable=>\$ISatheist, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Chick Metal", -variable=>\$ISchick_metal, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Death Metal", -variable=>\$ISdeath_metal, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Game Music", -variable=>\$ISgame_music, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Good Riffs", -variable=>\$ISgood_riffs, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"GTA Music", -variable=>\$ISGTA, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Hard Rock", -variable=>\$IShardcore_rock, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Hardcore Techno", -variable=>\$IShardcore_techno, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Heavy Metal", -variable=>\$ISheavy_metal, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Iced Earth", -variable=>\$ISie, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"OpenBSD", -variable=>\$ISopenbsd, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Patriotic", -variable=>\$ISpatriotic, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Power Metal", -variable=>\$ISpower_metal, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); $mw->Checkbutton(-selectcolor => 'Green', -activebackground => 'Blue', -activeforeground => 'Red', -relief => 'flat', -font => 'textfont', -text=>"Xmas", -variable=>\$ISxmas, -onvalue=>1, -offvalue=>0)->pack(-anchor => 'w'); # Make a frame to hold the OK and Abort buttons $Frame=$mw->Frame->pack(-side => 'bottom'); # Simply exit if the Abort button is hit $Frame->Button(-activeforeground => 'Black', -background => 'Dark Red', -activebackground => 'Red', -font => 'textfont', -text=>"Abort", -command=>sub { exit } )->pack(-side => 'left'); # Run a bunch of code to manipulate and save the new playlist if the OK button is hit $Frame->Button(-activeforeground => 'Black', -background => 'Dark Green', -activebackground => 'Green', -font => 'textfont', -text=>"OK", -command=>sub { $NewPlayLists=""; if ($IS80s == 1) { $NewPlayLists="$NewPlayLists 80s"; } if ($ISalternative_rock == 1) { $NewPlayLists="$NewPlayLists alternative_rock"; } if ($ISatheist == 1) { $NewPlayLists="$NewPlayLists atheist"; } if ($ISchick_metal == 1) { $NewPlayLists="$NewPlayLists chick_metal"; } if ($ISdeath_metal == 1) { $NewPlayLists="$NewPlayLists death_metal"; } if ($ISgame_music == 1) { $NewPlayLists="$NewPlayLists game_music"; } if ($ISgood_riffs == 1) { $NewPlayLists="$NewPlayLists good_riffs"; } if ($ISGTA == 1) { $NewPlayLists="$NewPlayLists GTA"; } if ($IShardcore_rock == 1) { $NewPlayLists="$NewPlayLists hardcore_rock"; } if ($IShardcore_techno == 1) { $NewPlayLists="$NewPlayLists hardcore_techno"; } if ($ISheavy_metal == 1) { $NewPlayLists="$NewPlayLists heavy_metal"; } if ($ISie == 1) { $NewPlayLists="$NewPlayLists ie"; } if ($ISopenbsd == 1) { $NewPlayLists="$NewPlayLists openbsd"; } if ($ISpatriotic == 1) { $NewPlayLists="$NewPlayLists patriotic"; } if ($ISpower_metal == 1) { $NewPlayLists="$NewPlayLists power_metal"; } if ($ISxmas == 1) { $NewPlayLists="$NewPlayLists xmas"; } $NewPlayLists =~ s/ / /g; $NewPlayLists =~ s/^ //; $NewPlayLists =~ s/ $//; $UpdateString="update tunes set PlayLists='$NewPlayLists' where ID=$ID"; #print ("$UpdateString\n"); $UpdateHandle=$DB->prepare($UpdateString); $UpdateHandle->execute; exit; } )->pack(-side => 'bottom'); # Silly command that MUST be here for ANY Tk stuff to do ANYTHING. MainLoop;