# mp3.pl: mp3 frontend, Version_0.1:[final] -- 12kiodine. (!11410 bytes). # mp3.pl: by: _v9[v9@ice.org] -- for use with a console mp3 player in X-Chat(built on 1.2.1). # mp3.pl: genre(@cat) was obtained from xmms(id3_frame_content.c) index. # mp3.pl: type "/load /pathto/mp3.pl" in X-Chat or put it in ~/.xchat to auto-load on start. # mp3.pl: base vars. (1) $hd=$ENV{"HOME"}; $pmt="\02***\02"; $lsoffset=4; $oschar="0"; $public="is playing mp3\02:\02 "; $sendto=">>$hd/.xchat/mp3list"; $writeto=">$hd/.xchat/mp3list"; $getfrom="$hd/.xchat/mp3list"; $m3uto=">>$hd/mp3list.m3u"; $configr="$hd/.xchat/mp3.conf"; $configw=">$hd/.xchat/mp3.conf"; @cat=('Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B', 'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska', 'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient', 'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical', 'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel', 'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative', 'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic', 'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk', 'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta', 'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American', 'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock', 'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival', 'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock', 'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band', 'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson', 'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus', 'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba', 'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle', 'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall'); # mp3.pl: subroutines. (2) sub out{IRC::print "@_\n";} sub zout{&out("$pmt mp3\02.\02pl: @_");} sub rargs{ my $i=0;my $out; if (@_){$i=@_[0];} while (@args[$i]){$out="$out @args[$i]";$i++;} return substr($out,1,length($out)); } sub getplayer{ if (-f $configr){ open(READ, $configr) || &zout("error opening $configr."); my @read=; close(READ); if (-f @read[0]){return @read[0];} } return 1; } sub ms{ my $i=0; while (substr(@_[0],$i,1)){ if (ord(substr(@_[0],$i,1)) != 32) {return @_[0];} $i++; } return "no information."; } sub totm{ my $i=0; open(READ, $getfrom); my @read=; close(READ); while(@read[$i]){$i++;} return $i/2; } sub getm{ my $i=-2; if (@_[1] eq "file"){$i++;} open(READ, $getfrom); my @read=; close(READ); return $read[$i+$_[0]*2]; } sub mp3handler{ @args=split(/ /, shift); #@args is the equivalent of @ARGV. if (! -d "$hd/.xchat"){ my $success=mkdir "$hd/.xchat",022; if ($success){&zout("~/.xchat did not exist, created successfully.");} else {&zout("error in creation of ~/.xchat, halting.");return 1;} } if (@args[0] eq "add"){ if (!@args[1]){&zout("/mp3 \02add\02 <\02/directory/file.mp3\02>");return 1;} my $rargs=&rargs(1); if (substr($rargs,length($rargs)-4,4) ne ".mp3"){&zout("invalid mp3 file. (.mp3)");return 1;} if (! -f $rargs){&zout("no such file.");return 1;} my $i=0;my $m;my @name=split(/\//, $rargs); while (@name[$i] || @name[$i+1]){$m=@name[$i];$i++;} if (!$m){$m=$rargs;} open(READ, $sendto) || &zout("error opening $sendto."); print READ substr($m,0,length($m)-4); print READ "\n$rargs\n"; close(READ); &zout("added $rargs to your mp3 list."); } elsif (@args[0] eq "del"){ if (!@args[1] || int(@args[1]) != @args[1]){&zout("/mp3 \02del\02 [\02#\02]");return 1;} if (@args[1] > &totm() || @args[1] < 1){&zout("invalid mp3 number selected.");return 1;} my $i=0;my $j=0; open(READ, $getfrom) || &zout("error opening $getfrom."); my @read=; close(READ); open(SEND, $writeto) || &zout("error opening $writeto."); while (@read[$i]){ if (@args[1]*2-2 == $i || $j eq "1"){ if ($j eq "1"){$j--;} else {$m=@read[$i];chomp $m;$j++;} } else {print SEND "@read[$i]";} $i++; } close(SEND); &zout("deleted mp3 number: @args[1]. ($m)"); } elsif (@args[0] eq "adddir"){ if (!@args[1]){&zout("/mp3 \02adddir\02 <\02/directory\02>");return 1;} if (! -d @args[1]){&zout("no such directory.");return 1;} my $i=0;my @m=glob "@args[1]/*.mp3"; open(READ, $sendto) || &zout("error opening $sendto."); while ($m[$i]){ print READ substr($m[$i],length(@args[1])+1,length($m[$i])-length(@args[1])-5); print READ "\n$m[$i]\n"; $i++; } close(READ); &zout("added a total of $i mp3(s) from @args[1]."); } elsif (@args[0] eq "list"){ my $i=1;my $j; &zout("listing mp3 file(s)."); while ($i <= &totm()){ my $m=&getm($i, "desc");chomp $m; my $num=$lsoffset-length($i);my $nu=0;my $j; while ($num > $nu){$j="$oschar$j";$nu++;} &out("$pmt (\02$j$i\02)\02 $m"); $i++; } if ($i eq "1"){&zout("no mp3 files found.");return 1;} &zout("completed mp3 list."); } elsif (@args[0] eq "player"){ if (!@args[1]){&zout("/mp3 \02player\02 [\02/directory/player\02]");return 1;} if (! -f @args[1]){&zout("no such file.");return 1;} open(SEND, $configw) || &zout("error opening $configw."); print SEND @args[1]; close(SEND); $mp3player=@args[1]; &zout("mp3 player stored to config file, and set to: @args[1]."); } elsif (@args[0] eq "rplayer"){ $mp3player=""; if (! -f "$hd/.xchat/mp3.conf"){&zout("no mp3 config file to clear.");} else { my $success=unlink "$hd/.xchat/mp3.conf"; if ($success){&zout("cleared mp3 config file successfully.");} else {&zout("mp3 config file was cleared un-successfully.");} } } elsif (@args[0] eq "play" || @args[0] eq "pplay"){ if (!$mp3player || ! -f $mp3player){&zout("mp3 player not selected or doesn't exist.");return 1;} if (!@args[1] || int(@args[1]) != @args[1]){&zout("/mp3 \02@args[0]\02 [\02#\02]");return 1;} if (@args[1] > &totm() || @args[1] < 1){&zout("invalid mp3 number selected.");return 1;} my $mp3f=&getm(@args[1], "file");my $mp3d=&getm(@args[1], "desc");chomp $mp3d;chomp $mp3f; if (! -f $mp3f){&zout("mp3 file missing, delete this selection please.");return 1;} my $num=system("killall $mp3player;sleep 1;$mp3player \"$mp3f\"&"); if ($num > 0){&zout("error occured trying to execute your mp3 player.");} if (@args[0] eq "play"){&zout("attempting to play: \02$mp3d\02.");} else {IRC::command "/me $public\02$mp3d\02. (\02mp3.pl\02)";} } elsif (@args[0] eq "random" || @args[0] eq "prandom"){ if (&totm() < 1){&zout("no mp3 files found.");return 1;} my $rand=int(rand(&totm()))+1; my $m="play"; if (@args[0] eq "prandom"){$m="pplay";} IRC::command "/mp3 $m $rand"; } elsif (@args[0] eq "id3"){ if (!@args[1] || int(@args[1]) != @args[1]){&zout("/mp3 \02id3\02 [\02#\02]");return 1;} if (@args[1] > &totm() || @args[1] < 1){&zout("invalid mp3 number selected.");return 1;} my $rargs=&getm(@args[1], "file");my $rdesc=&getm(@args[1], "desc");chomp $rargs;chomp $rdesc; if (! -f $rargs){&zout("mp3 file missing, delete this selection please.");return 1;} else { my $success=open(READ, $rargs); if (!$success) {&zout("unable to open mp3 for ID3 read.");return 1;} while (){ if ($_ =~ /TAG/){ my @m=split(/TAG/, $_); if (@m[1]){ my $i=0; while ($i < 124){ if (ord(substr(@m[1],$i,1)) > 122){ &zout("-- \02id3 information(TAG) in $rdesc contained invalid information. (ord>122)\02 --"); close(READ); return 1; } $i++; } my $song=ms(substr(@m[1],0,30));my $group=ms(substr(@m[1],30,30));my $album=ms(substr(@m[1],60,30));my $year=ms(substr(@m[1],90,4));my $comment=ms(substr(@m[1],94,30));my $genre=ord(substr(@m[1],124,1)); if ($genre > 125){$genre=ms();} else {$genre=@cat[$genre];} &zout("-- \02id3 information on $rdesc.\02 --"); &zout("(\02song \02)\02 $song ");&zout("(\02group \02)\02 $group"); &zout("(\02album \02)\02 $album");&zout("(\02comment\02)\02 $comment"); &zout("(\02year \02)\02 $year");&zout("(\02genre \02)\02 $genre"); close(READ);return 1; } } } close(READ); &zout("unable to obtain ID3 from file. (unknown)"); } } elsif (@args[0] eq "stop"){ if (!$mp3player || ! -f $mp3player){&zout("mp3 player not selected or doesn't exist.");return 1;} &zout("attmepting to kill all(if any) active mp3 session(s)."); my $num=system("killall $mp3player&"); if ($num > 0){&zout("error occured trying to kill your mp3 player.");} } elsif (@args[0] eq "clear"){ if (! -f "$hd/.xchat/mp3list"){&zout("no mp3 file to clear.");} else { my $success=unlink "$hd/.xchat/mp3list"; if ($success){&zout("cleared mp3 file successfully.");} else {&zout("mp3 file was cleared un-successfully.");} } } elsif (@args[0] eq "makem3u"){ if (&totm() < 1){&zout("no mp3 files found.");return 1;} if (@args[1] eq "noclear" || @args[1] eq "-noclear"){&zout("using noclear option: appending to \02~/mp3list.m3u\02 (if exists).");} else { if (-f "$hd/mp3list.m3u") { my $success=unlink "$hd/mp3list.m3u"; if ($success){&zout("cleared old \02~/mp3list.m3u\02 file successfully.");} else {&zout("old mp3 file was \02~/mp3list.m3u\02 cleared un-successfully.");} } } my $i=0; open(SEND, $m3uto) || &zout("error opening $m3uto."); while (&getm($i, "file")){ print SEND &getm($i, "file"); $i++; } close(SEND); &zout("converted stored mp3 list to m3u format: \02~/mp3list.m3u\02."); } elsif (@args[0] eq "help"){ &zout("-- \02syntax help for /mp3.\02 --"); &zout("(\02add \02)\02 add a mp3 from your hard disk."); &zout("(\02del \02)\02 delete a stored mp3 numeric value."); &zout("(\02adddir \02)\02 add a entire directory."); &zout("(\02list \02)\02 list current mp3(s) in storage."); &zout("(\02play \02)\02 play a stored mp3 numeric value."); &zout("(\02pplay \02)\02 play a stored mp3 numeric value. (show active window)"); &zout("(\02player \02)\02 select a mp3 play to play your mp3(s)."); &zout("(\02rplayer\02)\02 remove the set mp3 player."); &zout("(\02random \02)\02 play a random mp3."); &zout("(\02prandom\02)\02 play a random mp3. (show active window)"); &zout("(\02clear \02)\02 clear mp3(s) in storage."); &zout("(\02stop \02)\02 kills all active mp3 session(s)."); &zout("(\02id3 \02)\02 show ID3 information on a stored mp3 numeric value."); &zout("(\02makem3u\02)\02 mp3 list -> m3u format. (use parm \"-noclear\" to append)"); &zout("(\02# \02)\02 equivalent of /mp3 play [#]."); } elsif (&totm() >= @args[0] && @args[0] > 0) {IRC::command "/mp3 play @args[0]";} else {&zout("/mp3 [\02add\02|\02del\02|\02adddir\02|\02list\02|\02play\02|\02pplay\02|\02player\02|\02rplayer\02|\02random\02|\02prandom\02|\02clear\02|\02stop\02|\02id3\02|\02makem3u\02|\02#\02|\02help\02]");} return 1; } # mp3.pl: init. (3) IRC::add_command_handler("mp3", "mp3handler"); $mp3player=&getplayer(); &zout("by _v9[v9\@ice.org], type \"\02/mp3 help\02\" for syntax help."); # mp3.pl: eof. (4)