# Mp3 Request jIRCii Script by `butane # # Usage: /load mp3request.irc # # This addon provides the following mp3 requesting features: # # * Click on the !nick part of !nick somefilename.mp3 to request # an mp3 from an mp3 channel. # # * Using @find *pattern* in a channel will open a mp3 list window # where you can browse the songs found at your convienence. # # * Filters out a lot of the noise contained in channels with # legal mp3 trading going on. # # * Pasting text !nick filename.mp3 sets up an automatic mp3 download # queue. Once the specified nick finishes sending the first mp3 # this script will request the next one. Just keep pasting the # request text to add a song to the queue. # # Queue commands: # /clearQueue - clears the queue # /showQueue - shows the queue # /startdl - starts the downloading from the queue # # This feature was made with the idea of obtaining a list of # files from a user. Find what you want, highlight all of it, # and paste it into any jIRCii window. This script will then # take care of queuing and downloading the files. # # Changes: # 10.31.04 - added download queue feature # 07.24.04 - fixed incompatabilities with jIRCii b12 # $P_MP3_REGEX = '.*?(\!(.*?)\s(.*?\.[mM][pP]3)).*'; $P_MP3_FIND = '\@find\s(.*)'; $ATTEMPT_QUEUE = 1; # we should only attempt to queue 3 songs from a user # edit this if you think you can get away with more on request { if ($type eq "SLOTS" || $type eq "MP3") { halt; } } on input { if ($parms ismatch $P_MP3_FIND) { local('@data $activewin'); @data = matches($parms, $P_MP3_FIND); $MP3_LAST_SEARCH = @data[0]; if (!-iswindow "MP3 List") { $MP3_dialog = showSortedList("MP3 List", "__hook", @MP3_DATA, "Nickname", "Song"); } } } on msg { if ($parms ismatch $P_MP3_REGEX) { @data = matches(strip($parms), $P_MP3_REGEX); $rstring = @data[0]; $rnick = @data[1]; $rsong = @data[2]; push(@MP3_DATA, "$rnick $+ \t $+ $rsong $+ \t $+ $rstring"); if (-iswindow "MP3 List") { refreshData($MP3_dialog); } halt; } else if ($MP3_LAST_SEARCH ne "" && uc($MP3_LAST_SEARCH) isin uc($parms)) { halt; } else if ("*Total*files*found*" iswm strip($1-) || ("Slots free" isin $1- && "Que" isin $1- && "in channel for my list." isin $1-) || ("*Search Result*Matches*List*Files*Typing*" iswm $1-) || ("*Too*any*results*getting*list*recommended*" iswm $1-) || ("*Copy*and*paste*in*channel*to*request*a*file*" iswm $1-)) { halt; } } on click { local('@data $rnick $rstring $rchannel $rsong'); if ($parms ismatch $P_MP3_REGEX && charAt($item, 0) eq "!") { @data = matches($parms, $P_MP3_REGEX); $rstring = @data[0]; $rnick = @data[1]; $rsong = @data[2]; @data = getChannels($rnick); if (size(@data) >= 1) { $rchannel = @data[0]; echo("\c90$nnn Requesting\b $rsong \bfrom $rnick on $rchannel"); sendMessage($rchannel, $rstring); } } } on sclick { if ($1- eq "MP3 List") { requestFromRow($0); } } menu __hook { item "&Download Song" { requestFromRow($0); } item "&Clear List" { while (size(@MP3_DATA) > 0) { pop(@MP3_DATA); # a hack until clear(@array) works } refreshData($MP3_dialog); } } sub requestFromRow { $data = @MP3_DATA[$1]; @temp = split("\t", $data); @data = getChannels(@temp[0]); if (size(@data) >= 1) { $rchannel = @data[0]; echo($rchannel, "\c90$nnn Requesting\b " . @temp[1] . " \bfrom " . @temp[0] . " on $rchannel"); sendMessage($rchannel, @temp[2]); } } sub countFromUser { local('$dvar $count'); foreach $dvar (getAllConnections()) { if (-isdccopen $dvar && getDCCNickname($dvar) eq $1) { $count++; } } return $count; } sub getMp3Queue { if (%DCC_QUEUE[$1] eq "") { return array(); } return split('::::', %DCC_QUEUE[$1]); } sub addToMp3Queue { local('@data'); @data = getMp3Queue($1); push(@data, $2); %DCC_QUEUE[$1] = join('::::', @data); } on input { if ($1- ismatch $P_MP3_REGEX) { local('@data @data2 $rstring $rnick $rsong $rchannel'); @data = matches($1-, $P_MP3_REGEX); $rstring = @data[0]; $rnick = @data[1]; $rsong = @data[2]; if (getAddress($rnick) eq $null) { $rnick = fixNick($rnick); # annoying case sensitive issue with referencing user info... } @data2 = getChannels($rnick); if (size(@data2) >= 1) { $rchannel = @data2[0]; addToMp3Queue($rnick, "/msg $rchannel $rstring"); echo("$nnn Added $rsong $+ , will get from $rnick on $rchannel ASAP"); } halt; } } on receive_complete { handleMp3Action(fixNick($nick), 1); } on receive_failed { handleMp3Action(fixNick($nick), 1); } sub handleMp3Action { if (countFromUser($1) == 0 || $2 == 1) { local('$x @data'); @data = getMp3Queue($1); for ($x = 0; $x < $2 && size(@data) > 0; $x++) { call(shift(@data)); } %DCC_QUEUE[$1] = join('::::', @data); } } alias startdl { local('$var'); foreach $var (keys(%DCC_QUEUE)) { if (%DCC_DONE[$var] == 0 && %DCC_QUEUE[$var] ne "") { handleMp3Action($var, 3); %DCC_DONE[$var] = 3; } else if (%DCC_QUEUE[$var] eq "") { %DCC_DONE[$var] = 0; } } } alias clearQueue { foreach $var (keys(%DCC_QUEUE)) { %DCC_QUEUE[$var] = $null; } echo("$nnn cleared mp3 queue"); } alias showQueue { local('$var $var2 @data'); foreach $var (keys(%DCC_QUEUE)) { @data = getMp3Queue($var); foreach $var2 (@data) { echo("$nnn $[15]var $var2"); } } } sub fixNick { foreach $var (searchAddressList('*')) { if (lc($1) eq lc($var)) { return $var; } } return $null; } sub checkQueueFun { call("/startdl"); } if ($CHECK_TIMER eq $null) { $CHECK_TIMER = addTimer(&checkQueueFun, 60 * 1000); }