From 4d482b51d7022a1c40dcec5844bda9030d2e5247 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 15 Jan 2016 01:51:36 -0500 Subject: v2.0 :) Now does all bots concurrently --- scripts/xdcc_autoget.pl | 503 ++++++++++++++++++++++++++---------------------- 1 file changed, 271 insertions(+), 232 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 91703d2..c3e22cd 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -1,9 +1,18 @@ -# xdcc autogetter, to automate searching and downloading xdcc packs based on chosen search strings -# requires that you enable dcc_autoget and dcc_autoresume. Also requires File::Dir which can be installed with the command >>> sudo perl -MCPAN -e 'install "File::HomeDir"' -# made because torrents are watched by the feds, but xdcc lacks RSS feeds. +# xdcc autoget, to automate searching and downloading xdcc packs from xdcc bots based on chosen search strings +# +# long description: You add a bunch of xdcc bots and search terms, as well as an optional format string (for TV shows that have multiple releases or formats (basically gets appended to the end of a search after the episode #)). +# The script will go through each bot simultaneously, and download any packs it finds that matches. +# It stores the name and bot and pack number of each downloaded file to avoid redownloading, and incorporates automated (and sane default) timeouts to avoid flooding bots (and getting ignored/muted/kicked/banned). +# There is also a statusbar that you can add. +# It used to give a lot of detailed information on what was happening, but since the program now does all bots simultaneously it would be a clusterfuck, so now it gives only basic info on whether autoget is running. +# +# requires that you enable dcc_autoget and dcc_autoresume. Also requires File::Dir and Try::Tiny which can be installed with the command >>> sudo perl -MCPAN -e 'install "File::HomeDir"' && sudo perl -MCPAN -e 'install "Try::Tiny"' +# made because torrents are watched by the feds, but xdcc lacks an RSS feed equivalent. # if you encounter any problems, fix it yourself you lazy bastard (or get me to), then contact me so I can add your fix and bump that version # +# # BeerWare License. Use any part you want, but buy me a beer if you ever meet me and liked this hacked together broken PoS # Somewhat based off of DCC multiget by Kaveh Moini. +# # USE: to add the statusbar : /statusbar [name] add ag_statusbar # for help : ag_help # to run : ag_run @@ -29,16 +38,17 @@ use strict; use warnings; +use Irssi 20090331; use Irssi; use Irssi::TextUI; use Text::ParseWords; -use autodie; # die if problem reading or writing a file +use autodie; # die if problem reading or writing a file use File::HomeDir; use File::Copy; -use Irssi 20090331; +use Try::Tiny; use vars qw($VERSION %IRSSI); -$VERSION = 1.6; +$VERSION = 2.0; %IRSSI = ( name => "autoget", description => "XDCC Autoget, for automated searching and downloading of xdcc packs", @@ -51,7 +61,7 @@ $VERSION = 1.6; Irssi::settings_add_int($IRSSI{'name'}, "ag_next_delay", 10); Irssi::settings_add_int($IRSSI{'name'}, "ag_dcc_closed_retry_delay", 10); Irssi::settings_add_int($IRSSI{'name'}, "ag_bot_delay", 30); -Irssi::settings_add_int($IRSSI{'name'}, "ag_interrun_delay", 15); +Irssi::settings_add_int($IRSSI{'name'}, "ag_interrun_delay", 2); Irssi::settings_add_bool($IRSSI{'name'}, "ag_autorun", 1); Irssi::settings_add_bool($IRSSI{'name'}, "ag_episodic", 0); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); @@ -69,14 +79,12 @@ my $exedelay; #delay (in minutes) between finishing one run and starting anothe my $initflag; #flag controls whether AG starts on IRSSI boot (if in autorun), or on LOAD my $runningflag = 0; #flag keeps ag from running more than one instance of itself at a time -my $msgflag = 1; #flag controls whether bot has responded to search request -my $getmsgflag = 0; #flag keeps track of getmsg signals -my $termisepisodicflag = 0; #flag controls whether +my @msgflag = (); #flag controls whether bot has responded to search request +my @getmsgflag = (); #flag keeps track of getmsg signals my $episodicflag; #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) -my $formatflag = 1; #flag controls whether a format is appended to the end of an episodic search string -my $reqpackflag = 0; #flag to avoid multiple download requests -my $downloadflag = 0; #flag to avoid multiple download requests -my $newpackflag = 1; +my @formatflag = (); #flag controls whether a format is appended to the end of an episodic search string +my @reqpackflag = (); #flag to avoid multiple download requests +my @downloadflag = (); #flag to avoid multiple download requests my $sendprefix; #virtually universal xdcc send, cancel, and find prefixes my $cancelprefix; @@ -96,18 +104,18 @@ my @terms; #lists of search terms, bots, and pack numbers (for current bot only my @bots; my @packs; my @finished; #list of packs already downloaded and their filenames -my $statusbarmessage = "Inactive"; +my @filenames; #list of filenames of files currently being downloaded +my $statusbarmessage = "No connection"; -my $termcounter = 0; #counters for array position -my $botcounter = 0; -my $packcounter = 0; -my $episode = 1; +my @termcounter = (); #counters for array position +my @packcounter = (); +my @episode = (); my $server; #current server sub ag_init #init system { - Irssi::print "AG | Autoget initiated"; + Irssi::print "AG | Autoget V$VERSION initiated"; Irssi::print "AG | /ag_help for help"; &ag_list; if ($episodicflag) @@ -141,8 +149,10 @@ sub ag_list sub ag_initserver #init server { Irssi::signal_remove("server connected", "ag_server"); + $statusbarmessage = "Connected"; $server = $_[0]; - if (!$runningflag) {push(@totags, Irssi::timeout_add_once(5000, sub { &ag_run; }, []));} + if (!$runningflag) {Irssi::timeout_add_once(5000, sub { &ag_run; }, []);} + else {Irssi::timeout_add_once(5000, sub { $statusbarmessage = "Inactive"; }, []);} } sub ag_server #init server @@ -211,50 +221,44 @@ sub ag_clearcache #clears cache of saved packs sub ag_search #searches bots for packs { - $msgflag = 0; #unset message flag so that ag_skip knows no important message has arrived + (my $botcounter) = $_[0]; + $msgflag[$botcounter] = 0; #unset message flag so that ag_skip knows no important message has arrived if($episodicflag) #episodic searches are complicated { - my $ep = sprintf("%.2d", $episode); - $statusbarmessage = "Searching $bots[$botcounter] for \"$terms[$termcounter]\" episode $ep in $format"; - if ($format ne "" and $formatflag) + my $ep = sprintf("%.2d", $episode[$botcounter]); + if ($format ne "" and $formatflag[$botcounter]) { - ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep $format"); #first search with format - if ($episode == 1) + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]] $ep $format"); #first search with format + if ($episode[$botcounter] == 1) #if no formated version found, try again with just the search string + ep# { - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { $formatflag = 0; &ag_search; } , [])); #if no formated version found, try again with just the search string + ep# - } + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { $formatflag[$botcounter] = 0; &ag_search($botcounter); } , [])); + } else { - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); } } else { - $statusbarmessage = "Searching $bots[$botcounter] for \"$terms[$termcounter]\" episode $ep"; - ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter] $ep" ); - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]] $ep" ); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); } } else #if not episodic, just search and skip { - $statusbarmessage = "Searching $bots[$botcounter] for \"$terms[$termcounter]\""; - ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter]" ); - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip; } , [])); - } - if (!$getmsgflag) - { - $getmsgflag = 1; - Irssi::signal_add("message irc notice", "ag_getmsg"); + ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]]" ); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); } } sub ag_remtimeouts #remove timeouts to avoid multiple instances of everything { - foreach my $to (@totags) #remove timeouts and clear array + my($botcounter) = @_; + foreach my $to (@{$totags[$botcounter]}) #remove timeouts and clear array { Irssi::timeout_remove($to); } - @totags = (); + $totags[$botcounter] = (); } sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things @@ -262,27 +266,37 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this my $message = $_[1]; my $botname = $_[2]; $botname =~ tr/[A-Z]/[a-z]/; - $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname eq $bots[$botcounter] and !$msgflag) #if it's your bot + my $botcounter = 0; + foreach my $bot (@bots) { - &ag_remtimeouts; #stop any skips from happening - ag_getpacks($message); #and check for any new packs in the message - if ($#packs < 0) { push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip; } , [])); } #set up only one possible skip per search - if($#packs >= 0){ &ag_packrequest; } #if there are any packs, - $msgflag = 1; #let everyone know that the current bot has replied + $bot =~ tr/[A-Z]/[a-z]/; + if ($botname eq $bots[$botcounter]) #if it's your bot + { + &ag_remtimeouts($botcounter); #stop any skips from happening + ag_getpacks($message, $botcounter); #and check for any new packs in the message + my @packlist = @{$packs[$botcounter]}; + if ($#packlist < 0 and !$msgflag[$botcounter]) #set up only one possible skip per search + { + my $temp = $botcounter; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip($temp); } , [])); + } + if($#packlist >= 0){ &ag_packrequest($botcounter); } #if there are any packs, + $msgflag[$botcounter] = 1; #let everyone know that the current bot has replied + } + $botcounter++; } } sub ag_getpacks { - my($message) = @_; + my($message, $botcounter) = @_; my @temp = split(' ', $message); #split up the message into 'words' &ag_getfinished; + my $newpackflag = 1; foreach my $m (@temp) #find packs (#[NUMBER]: format) { - $newpackflag = 1; if ($m =~ m{#(\d+):}) { foreach my $n (@finished) #don't redownload finished packs @@ -290,22 +304,21 @@ sub ag_getpacks if ($n eq "$bots[$botcounter] $1") {$newpackflag = 0;} last if ($n eq "$bots[$botcounter] $1"); } - if($newpackflag){push(@packs, $1);} #push all new pack numbers to list of packs + if($newpackflag){push(@{$packs[$botcounter]}, $1);} #push all new pack numbers to list of packs } } - @packs = ag_uniq(@packs); #remove duplicates + @{$packs[$botcounter]} = ag_uniq(@{$packs[$botcounter]}); #remove duplicates } sub ag_packrequest #sends the xdcc send request, and retries on failure { - &ag_remtimeouts; - if (!$reqpackflag) + my($botcounter) = @_; + &ag_remtimeouts($botcounter); + if (!$reqpackflag[$botcounter]) { - $reqpackflag = 1; - Irssi::signal_add("dcc request", "ag_opendcc"); #init DCC recieve init flag - $statusbarmessage = "Getting pack #$packs[$packcounter] on $bots[$botcounter]"; - ag_message("msg $bots[$botcounter] $sendprefix $packs[$packcounter]"); - push(@totags, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag) { &ag_packrequest; } } , [])); + $reqpackflag[$botcounter] = 1; + ag_message("msg $bots[$botcounter] $sendprefix $packs[$botcounter][$packcounter[$botcounter]]"); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag[$botcounter]) { &ag_packrequest($botcounter); } } , [])); } } @@ -315,190 +328,200 @@ sub ag_opendcc #runs on DCC recieve init my ($gdcc) = @_; #current pack my $botname = $gdcc->{'nick'}; my $filename = $gdcc->{'arg'}; + my $filedownloadflag = 0; $botname =~ tr/[A-Z]/[a-z]/; - $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname eq $bots[$botcounter]) #if it's our bot, let user know, and stop any further AG pack requests until finished + foreach my $file (@filenames) + { + if ($file eq $filename) {$filedownloadflag = 1;} + } + + my $botcounter = 0; + foreach my $bot (@bots) { - Irssi::signal_add("dcc destroyed", "ag_closedcc"); - Irssi::signal_remove("dcc request", "ag_opendcc"); #stops any suplicate sends (there should only ever be one) - Irssi::signal_remove("message irc notice", "ag_getmsg"); - $getmsgflag = 0; - - &ag_remtimeouts; - $dccflag = 0; - $downloadflag = 1; - $statusbarmessage = "Downloading $filename from $botname, #$packs[$packcounter]"; - foreach my $n (@finished) #don't redownload finished packs + $bot =~ tr/[A-Z]/[a-z]/; + if ($botname eq $bot and !$filedownloadflag) #if it's our bot and the file is not already being downloaded, let user know, and stop any further AG pack requests until finished { - if ($n eq $gdcc->{'arg'}) #if file already downloaded, cancel + $getmsgflag[$botcounter] = 0; + + &ag_remtimeouts($botcounter); + $dccflag = 0; + $downloadflag[$botcounter] = 1; + foreach my $n (@finished) #don't redownload finished packs { - Irssi::signal_remove("dcc destroyed", "ag_closedcc"); - $gdcc->close; - $gdcc->{'skipped'} = $gdcc->{'size'}; - $gdcc->{'transfd'} = $gdcc->{'size'}; - ag_closedcc($gdcc); + if ($n eq $gdcc->{'arg'}) #if file already downloaded, cancel + { + Irssi::signal_remove("dcc destroyed", "ag_closedcc"); + $gdcc->close; + $gdcc->{'skipped'} = $gdcc->{'size'}; + $gdcc->{'transfd'} = $gdcc->{'size'}; + ag_closedcc($gdcc); + Irssi::signal_add("dcc destroyed", "ag_closedcc"); + } + last if ($n eq $gdcc->{'arg'}); } - last if ($n eq $gdcc->{'arg'}); + push(@filenames, $filename); } + elsif ($botname eq $bot and $filedownloadflag) + { + Irssi::signal_remove("dcc destroyed", "ag_closedcc"); + Irssi::signal_add("dcc destroyed", "ag_dummyclosedcc"); + ag_message("msg $bots[$botcounter] $cancelprefix"); + $gdcc->close; + ag_skip($botcounter); + } + $botcounter++; } } sub ag_skip { -# Irssi::print "AG | SKIP $msgflag $episodicflag $episode $#packs $packcounter $#terms $termcounter $#bots $botcounter"; - &ag_remtimeouts; #stop any other skips - $reqpackflag = 0; #allow pack requests now that transfer is finished + my($botcounter) = @_; + my @packlist = (); + try {my @packlist = @{$packs[$botcounter]} or die;} #workaround for @{} being dumb if an array inside of an array is empty + catch {}; + #Irssi::print "ag_skip $msgflag $episodicflag $episode $#packs $packcounter $#terms $termcounter $#bots $botcounter"; + &ag_remtimeouts($botcounter); #stop any other skips + $reqpackflag[$botcounter] = 0; #allow pack requests now that transfer is finished if($episodicflag) { - @packs = (); #delete and reset packlist - $packcounter = 0; + $packs[$botcounter] = (); #delete and reset packlist + $packcounter[$botcounter] = 0; - if ($msgflag) #if the bot replied, then that means there were episodes, but we already have them - { - $episode++; - &ag_search; - } - elsif ($termcounter < $#terms) #otherwise just increment terms or bots + if ($msgflag[$botcounter]) #if the bot replied, then that means there were episodes, but we already have them { - $episode = 1; - $formatflag = 1; - $termcounter++; - $packcounter = 0; - &ag_search; + $episode[$botcounter]++; + &ag_search($botcounter); } - elsif ($botcounter < $#bots) + elsif ($termcounter[$botcounter] < $#terms) #otherwise just increment terms { - $episode = 1; - $formatflag = 1; - $botcounter++; - $termcounter = 0; - $packcounter = 0; - &ag_search; + $episode[$botcounter] = 1; + $formatflag[$botcounter] = 1; + $termcounter[$botcounter]++; + $packcounter[$botcounter] = 0; + &ag_search($botcounter); } - else #if last episode on last search on last bot finished, then resets counters and starts over + else #if last episode on last search on last term finished, then resets counters and starts over { - $episode = 1; - $formatflag = 1; - $botcounter = 0; - $termcounter = 0; - $packcounter = 0; - $statusbarmessage = "Waiting $exedelay minutes"; - Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $episode[$botcounter] = 1; + $formatflag[$botcounter] = 1; + $termcounter[$botcounter] = 0; + $packcounter[$botcounter] = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); $runningflag = 0; } } - elsif ($packcounter < $#packs) + elsif ($packcounter[$botcounter] < $#packlist) { - $packcounter++; - &ag_search; + $packcounter[$botcounter]++; + &ag_search($botcounter); } - elsif ($termcounter < $#terms) + elsif ($termcounter[$botcounter] < $#terms) { - @packs = (); #delete last terms packlist - $termcounter++; - $packcounter = 0; - &ag_search; + $packs[$botcounter] = (); #delete last terms packlist + $termcounter[$botcounter]++; + $packcounter[$botcounter] = 0; + &ag_search($botcounter); } - elsif ($botcounter < $#bots) + else #if last pack on last search on last term finished, then resets counters and starts over { - @packs = (); #delete last bots packlist - $botcounter++; - $termcounter = 0; - $packcounter = 0; - &ag_search; - } - else #if last pack on last search on last bot finished, then resets counters and starts over - { - $episode = 1; - $formatflag = 1; - @packs = (); #delete last bots packlist - $botcounter = 0; - $termcounter = 0; - $packcounter = 0; - $statusbarmessage = "Waiting $exedelay minutes"; - Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); + $episode[$botcounter] = 1; + $formatflag[$botcounter] = 1; + $packs[$botcounter] = (); #delete last bots packlist + $termcounter[$botcounter] = 0; + $packcounter[$botcounter] = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); $runningflag = 0; } } +sub ag_dummyclosedcc +{ + Irssi::signal_remove("dcc destroyed", "ag_dummyclosedcc"); + Irssi::signal_add("dcc destroyed", "ag_closedcc"); +} + sub ag_closedcc { my ($dcc) = @_; #current pack my $botname = $dcc->{'nick'}; #get the bots name, and checks if it's the one we want + my $filename = $dcc->{'arg'}; $botname =~ tr/[A-Z]/[a-z]/; - $bots[$botcounter] =~ tr/[A-Z]/[a-z]/; - if ($botname eq $bots[$botcounter] and $reqpackflag) #checks if the is the bot - { - Irssi::signal_remove("dcc destroyed", "ag_opendcc"); - $reqpackflag = 0; -# if ($dccflag == 0) {Irssi::signal_add("dcc request", "ag_opendcc");} #if so, reinits DCC get signal for the next pack - $dccflag = 1; - - &ag_remtimeouts; - - if ($dcc->{'skipped'} == $dcc->{'size'}) - { - ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. - } - if ($dcc->{'transfd'} == $dcc->{'size'}) - { - ag_addfinished($dcc->{'arg'}); - } - - if($episodicflag and $dcc->{'transfd'} == $dcc->{'size'}) - { - @packs = (); #delete packlist - $packcounter = 0; - $episode++; - $statusbarmessage = "Waiting $nexdelay seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search; }, [])); - } - elsif ($dcc->{'transfd'} == $dcc->{'size'}) - { - if ($packcounter < $#packs) - { - $packcounter++; - $statusbarmessage = "Waiting $nexdelay seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_reqpack; }, [])); - } - elsif ($termcounter < $#terms) + my $botcounter = 0; + foreach my $bot (@bots) + { + $bot =~ tr/[A-Z]/[a-z]/; + + if ($botname eq $bot and $reqpackflag[$botcounter]) #checks if the is the bot + { + my $temp = $botcounter; + my @packlist = $packs[$botcounter]; + my @termlist = $terms[$botcounter]; + + @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred + $reqpackflag[$botcounter] = 0; + # if ($dccflag == 0) {Irssi::signal_add("dcc request", "ag_opendcc");} #if so, reinits DCC get signal for the next pack + $dccflag = 1; + + &ag_remtimeouts($botcounter); + + if ($dcc->{'skipped'} == $dcc->{'size'}) { - @packs = (); #delete last terms packlist - $termcounter++; - $packcounter = 0; - $statusbarmessage = "Waiting $nexdelay seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search; }, [])); + ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. } - elsif ($botcounter < $#bots) + if ($dcc->{'transfd'} == $dcc->{'size'}) { - @packs = (); #delete last bots packlist - $botcounter++; - $termcounter = 0; - $packcounter = 0; - $statusbarmessage = "Waiting $nexdelay seconds"; - push(@totags, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search; }, [])); + ag_addfinished($dcc->{'arg'}, $botcounter); + + if($episodicflag) + { + if ($packcounter[$botcounter] < $#packlist) + { + $packcounter[$botcounter]++; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &packrequest($temp); }, [])); + } + else + { + $packs[$botcounter] = (); #delete packlist + $packcounter[$botcounter] = 0; + $episode[$botcounter]++; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + } + } + else + { + if ($packcounter[$botcounter] < $#packlist) + { + $packcounter[$botcounter]++; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + } + elsif ($termcounter[$botcounter] < $#termlist) + { + $packs[$botcounter] = (); #delete last terms packlist + $termcounter[$botcounter]++; + $packcounter[$botcounter] = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + } + else #if last pack on last search on last bot finished, then resets counters and starts over + { + $packs[$botcounter] = (); + $termcounter[$botcounter] = 0; + $packcounter[$botcounter] = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); + $runningflag = 0; + } + } } - else #if last pack on last search on last bot finished, then resets counters and starts over + else { - @packs = (); - $botcounter = 0; - $termcounter = 0; - $packcounter = 0; - $statusbarmessage = "Waiting $nexdelay seconds"; - Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_run; } , []); - $runningflag = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($dcrdelay * 1000, sub { &ag_packrequest($temp); }, [])); } } - else #if not, retry transfer - { - $statusbarmessage = "File incomplete. Retrying in $nexdelay seconds"; - push(@totags, Irssi::timeout_add_once($dcrdelay * 1000, sub { &ag_packrequest; }, [])); - } + $botcounter++; } } - + sub ag_message { (my $message) = $_[0]; @@ -520,9 +543,9 @@ sub ag_bar #prints the message to the statusbar sub ag_addfinished #save finished downloads { - my $filename = $_[0]; + my ($filename, $botcounter) = @_; open(FINISHED, ">>", $cachefilename); - print FINISHED $bots[$botcounter] . " " . $packs[$packcounter] . "\n"; #print pack to file + print FINISHED $bots[$botcounter] . " " . $packs[$botcounter][$packcounter[$botcounter]] . "\n"; #print pack to file print FINISHED $filename . "\n"; #print name to file close(FINISHED); } @@ -653,16 +676,35 @@ sub ag_botrem #remove bots sub ag_run #main loop { + Irssi::signal_add("dcc request", "ag_opendcc"); #init DCC recieve init flag + Irssi::signal_add("message irc notice", "ag_getmsg"); if (!$initflag) {ag_server(Irssi::active_server());} if($runningflag == 0) { $runningflag = 1; &ag_getbots; &ag_getterms; - if($#bots < 0 or $#terms < 0) { $statusbarmessage = "No bots or no search terms."; push(@totags, Irssi::timeout_add_once(1000, sub { &ag_run; }, []));} + + if($#bots < 0 or $#terms < 0) { $statusbarmessage = "No bots or no search terms."; Irssi::timeout_add_once(1000, sub { &ag_run; }, []);} else { - &ag_search; + $statusbarmessage = "Active"; + my $botcounter = 0; + foreach my $bot (@bots) + { + $totags[$botcounter] = (); + $msgflag[$botcounter] = 1; #flag controls whether bot has responded to search request + $getmsgflag[$botcounter] = 0; #flag keeps track of getmsg signals + $formatflag[$botcounter] = 1; #flag controls whether a format is appended to the end of an episodic search string + $reqpackflag[$botcounter] = 0; #flag to avoid multiple download requests + $downloadflag[$botcounter] = 0; #flag to avoid multiple download requests + $termcounter[$botcounter] = 0; + $packcounter[$botcounter] = 0; + $episode[$botcounter] = 1; + $packs[$botcounter] = (); + &ag_search($botcounter); + $botcounter++; + } } } } @@ -671,63 +713,59 @@ sub ag_stop { Irssi::signal_remove("dcc request", "ag_opendcc"); Irssi::signal_remove("message irc notice", "ag_getmsg"); - $getmsgflag = 0; - - foreach my $to (@totags) + + my $botcounter = 0; + foreach my $bot (@bots) { - Irssi::timeout_remove($to); + &ag_remtimeouts($botcounter); #stop any skips from happening + ag_message("msg $bot $cancelprefix"); + $getmsgflag[$botcounter] = 0; + $botcounter++; + @msgflag = (); + @formatflag = (); + @reqpackflag = (); + @downloadflag = (); + @termcounter = (); + @packcounter = (); + @episode = (); } - @totags = (); - - ag_message("msg $bots[$botcounter] $cancelprefix"); if($runningflag == 1) { $runningflag = 0; $statusbarmessage = "Inactive"; } - $msgflag = 1; - $termisepisodicflag = 0; - $formatflag = 1; - $reqpackflag = 0; - $downloadflag = 0; - $newpackflag = 1; $dccflag = 0; @terms = (); @bots = (); @packs = (); @finished = (); - $termcounter = 0; $botcounter = 0; - $packcounter = 0; - $episode = 1; } sub ag_restart { - $statusbarmessage = "No connection"; + $statusbarmessage = "Inactive"; Irssi::signal_remove("dcc request", "ag_opendcc"); Irssi::signal_remove("message irc notice", "ag_getmsg"); - $getmsgflag = 0; - - foreach my $to (@totags) + + my $botcounter = 0; + foreach my $bot (@bots) { - Irssi::timeout_remove($to); + $getmsgflag[$botcounter] = 0; + &ag_remtimeouts($botcounter); + ag_message("msg $bot $cancelprefix"); + $botcounter++; } - @totags = (); - - ag_message("msg $bots[$botcounter] $cancelprefix"); if($runningflag == 1) { $runningflag = 0; } - $msgflag = 1; - $termisepisodicflag = 0; - $formatflag = 1; - $reqpackflag = 0; - $downloadflag = 0; - $newpackflag = 1; + @msgflag = (); + @formatflag = (); + @reqpackflag = (); + @downloadflag = (); $dccflag = 0; Irssi::signal_add("server connected", "ag_initserver"); } @@ -778,6 +816,7 @@ if ($initflag) {Irssi::signal_add("server connected", "ag_initserver");} Irssi::signal_add("server disconnected", "ag_restart"); Irssi::signal_add("server lag disconnect", "ag_restart"); Irssi::signal_add("setup changed", "ag_setsettings"); +Irssi::signal_add("dcc destroyed", "ag_closedcc"); Irssi::command_bind("ag_help", "ag_help"); Irssi::command_bind("ag_run", "ag_run"); -- cgit v1.2.3 From 424e6de2cea2b42c22f64e65d1ca1235d2039d1d Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 15 Jan 2016 02:14:45 -0500 Subject: minor change for code critic --- scripts/xdcc_autoget.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index c3e22cd..99af82a 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -378,7 +378,7 @@ sub ag_skip { my($botcounter) = @_; my @packlist = (); - try {my @packlist = @{$packs[$botcounter]} or die;} #workaround for @{} being dumb if an array inside of an array is empty + try {my @packlist = @{$packs[$botcounter]};} #workaround for @{} being dumb if an array inside of an array is empty catch {}; #Irssi::print "ag_skip $msgflag $episodicflag $episode $#packs $packcounter $#terms $termcounter $#bots $botcounter"; &ag_remtimeouts($botcounter); #stop any other skips @@ -745,7 +745,7 @@ sub ag_stop sub ag_restart { - $statusbarmessage = "Inactive"; + $statusbarmessage = "No Connection"; Irssi::signal_remove("dcc request", "ag_opendcc"); Irssi::signal_remove("message irc notice", "ag_getmsg"); -- cgit v1.2.3 From 8d9323364af15215369a3ccab5a983690f5dc9fd Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Fri, 15 Jan 2016 23:58:37 -0500 Subject: bugfixes and a boatload of improved features/functionality --- scripts/xdcc_autoget.pl | 142 +++++++++++++++++++----------------------------- 1 file changed, 57 insertions(+), 85 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 99af82a..a84cdaf 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -1,6 +1,8 @@ # xdcc autoget, to automate searching and downloading xdcc packs from xdcc bots based on chosen search strings # -# long description: You add a bunch of xdcc bots and search terms, as well as an optional format string (for TV shows that have multiple releases or formats (basically gets appended to the end of a search after the episode #)). +# long description: You add a bunch of xdcc bots and search terms using the provided functionality, or by adding lines to the searches.txt and bots.txt files +# For searching for episodes, a search term should use '#' as a placeholder for the episode number. +# eg., If the release of Boku no Pico you want to download uses a naming scheme such that episode 1 is "Boku no Pico - ep01 (1080p HEVC).mkv", then your search term should be "Boku no Pico - ep# (1080p HEVC).mkv" # The script will go through each bot simultaneously, and download any packs it finds that matches. # It stores the name and bot and pack number of each downloaded file to avoid redownloading, and incorporates automated (and sane default) timeouts to avoid flooding bots (and getting ignored/muted/kicked/banned). # There is also a statusbar that you can add. @@ -27,7 +29,7 @@ # to clear cache : ag_clearcache # ag_next_delay : delay between full transfers # ag_dcc_closed_retry_delay : delay after premature transfer -# ag_bot_delay: delay between request and when you "SHOULD" get it +# ag_bot_delay : delay between request and when you "SHOULD" get it # ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another # ag_autorun : whether to run on startup # ag_xdcc_send_prefix : the xdcc message before the pack # @@ -48,7 +50,7 @@ use File::Copy; use Try::Tiny; use vars qw($VERSION %IRSSI); -$VERSION = 2.0; +$VERSION = "2.0"; %IRSSI = ( name => "autoget", description => "XDCC Autoget, for automated searching and downloading of xdcc packs", @@ -67,7 +69,6 @@ Irssi::settings_add_bool($IRSSI{'name'}, "ag_episodic", 0); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_send_prefix", "xdcc send"); Irssi::settings_add_str($IRSSI{'name'}, "ag_xdcc_cancel_prefix", "xdcc cancel"); Irssi::settings_add_str($IRSSI{'name'}, "ag_find_prefix", "!find"); -Irssi::settings_add_str($IRSSI{'name'}, "ag_format", ""); Irssi::settings_add_str($IRSSI{'name'}, "ag_folder", File::HomeDir->my_home); my @totags = (); #timeout tags (need to be purged between send requests maybe) @@ -82,14 +83,12 @@ my $runningflag = 0; #flag keeps ag from running more than one instance of itse my @msgflag = (); #flag controls whether bot has responded to search request my @getmsgflag = (); #flag keeps track of getmsg signals my $episodicflag; #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) -my @formatflag = (); #flag controls whether a format is appended to the end of an episodic search string my @reqpackflag = (); #flag to avoid multiple download requests my @downloadflag = (); #flag to avoid multiple download requests my $sendprefix; #virtually universal xdcc send, cancel, and find prefixes my $cancelprefix; my $findprefix; -my $format; #format option for episodic. Can be edited if you want a certain size, eg 720p; x264; aXXo; etc my $folder; &ag_setsettings; @@ -98,8 +97,6 @@ my $botsfilename = $folder . "/bots.txt"; my $searchesfilename = $folder . "/searches.txt"; my $cachefilename = $folder . "/cache.txt"; -my $dccflag = 0; #flag so that dccs aren't mistakenly thought of belonging to AG - my @terms; #lists of search terms, bots, and pack numbers (for current bot only) my @bots; my @packs; @@ -121,7 +118,6 @@ sub ag_init #init system if ($episodicflag) { Irssi::print "AG | Episodic: Yes"; - Irssi::print "AG | Preffered format: $format"; } else {Irssi::print "AG | Episodic: No";} Irssi::print "AG | Data folder: $folder"; @@ -183,7 +179,6 @@ sub ag_help Irssi::print "ag_xdcc_send_prefix : the xdcc message before the pack #"; Irssi::print "ag_xdcc_cancel_prefix : the xdcc message to cancel a transfer"; Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; - Irssi::print "ag_format : universal string appended to the end of each search in episodic. Use if more than one format exists"; Irssi::print "ag_folder : Location for data files. ~/.irssi/ reccomended"; } @@ -223,26 +218,16 @@ sub ag_search #searches bots for packs { (my $botcounter) = $_[0]; $msgflag[$botcounter] = 0; #unset message flag so that ag_skip knows no important message has arrived - if($episodicflag) #episodic searches are complicated + if($episodicflag) { + my $searchterm; + my @words = split('#', $terms[$termcounter[$botcounter]]); my $ep = sprintf("%.2d", $episode[$botcounter]); - if ($format ne "" and $formatflag[$botcounter]) - { - ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]] $ep $format"); #first search with format - if ($episode[$botcounter] == 1) #if no formated version found, try again with just the search string + ep# - { - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { $formatflag[$botcounter] = 0; &ag_search($botcounter); } , [])); - } - else - { - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); - } - } - else - { - ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]] $ep" ); - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); - } + if ($#words > 0){$searchterm = "$words[0]$ep$words[1]";} + else {$searchterm = "$words[0] $ep";} + + ag_message("msg $bots[$botcounter] $findprefix $searchterm" ); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); } else #if not episodic, just search and skip { @@ -273,14 +258,8 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this $bot =~ tr/[A-Z]/[a-z]/; if ($botname eq $bots[$botcounter]) #if it's your bot { - &ag_remtimeouts($botcounter); #stop any skips from happening - ag_getpacks($message, $botcounter); #and check for any new packs in the message + ag_getpacks($message, $botcounter); #check for any new packs in the message my @packlist = @{$packs[$botcounter]}; - if ($#packlist < 0 and !$msgflag[$botcounter]) #set up only one possible skip per search - { - my $temp = $botcounter; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip($temp); } , [])); - } if($#packlist >= 0){ &ag_packrequest($botcounter); } #if there are any packs, $msgflag[$botcounter] = 1; #let everyone know that the current bot has replied } @@ -288,20 +267,27 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this } } -sub ag_getpacks +sub ag_getpacks #if ($m =~ m{#(\d+):}) { my($message, $botcounter) = @_; - my @temp = split(' ', $message); #split up the message into 'words' + my @temp = split(/[#,]/, $message); #split up the message into 'words' + my $timeoutscleared = 0; &ag_getfinished; my $newpackflag = 1; foreach my $m (@temp) #find packs (#[NUMBER]: format) { - if ($m =~ m{#(\d+):}) + if ($m =~ m/(\d+):(.+)/) { + if (!$timeoutscleared) #reset timeouts if any packs are found + { + &ag_remtimeouts($botcounter); + $timeoutscleared = 0; + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip($botcounter); } , [])); + } foreach my $n (@finished) #don't redownload finished packs { - if ($n eq "$bots[$botcounter] $1") {$newpackflag = 0;} + if ($n eq "$bots[$botcounter] $1" or $n eq $2) {$newpackflag = 0;} last if ($n eq "$bots[$botcounter] $1"); } if($newpackflag){push(@{$packs[$botcounter]}, $1);} #push all new pack numbers to list of packs @@ -330,11 +316,8 @@ sub ag_opendcc #runs on DCC recieve init my $filename = $gdcc->{'arg'}; my $filedownloadflag = 0; $botname =~ tr/[A-Z]/[a-z]/; - - foreach my $file (@filenames) - { - if ($file eq $filename) {$filedownloadflag = 1;} - } + + foreach my $file (@filenames){ if ($file eq $filename){ $filedownloadflag = 1; }} my $botcounter = 0; foreach my $bot (@bots) @@ -345,7 +328,6 @@ sub ag_opendcc #runs on DCC recieve init $getmsgflag[$botcounter] = 0; &ag_remtimeouts($botcounter); - $dccflag = 0; $downloadflag[$botcounter] = 1; foreach my $n (@finished) #don't redownload finished packs { @@ -362,13 +344,13 @@ sub ag_opendcc #runs on DCC recieve init } push(@filenames, $filename); } - elsif ($botname eq $bot and $filedownloadflag) + elsif ($botname eq $bot and $filedownloadflag) #don't download packs that are being downloaded by other bots { Irssi::signal_remove("dcc destroyed", "ag_closedcc"); - Irssi::signal_add("dcc destroyed", "ag_dummyclosedcc"); - ag_message("msg $bots[$botcounter] $cancelprefix"); $gdcc->close; - ag_skip($botcounter); + $gdcc->{'skipped'} = $gdcc->{'size'}; + ag_closedcc($gdcc); + Irssi::signal_add("dcc destroyed", "ag_closedcc"); } $botcounter++; } @@ -380,23 +362,26 @@ sub ag_skip my @packlist = (); try {my @packlist = @{$packs[$botcounter]};} #workaround for @{} being dumb if an array inside of an array is empty catch {}; - #Irssi::print "ag_skip $msgflag $episodicflag $episode $#packs $packcounter $#terms $termcounter $#bots $botcounter"; &ag_remtimeouts($botcounter); #stop any other skips $reqpackflag[$botcounter] = 0; #allow pack requests now that transfer is finished if($episodicflag) { - $packs[$botcounter] = (); #delete and reset packlist - $packcounter[$botcounter] = 0; - if ($msgflag[$botcounter]) #if the bot replied, then that means there were episodes, but we already have them { - $episode[$botcounter]++; - &ag_search($botcounter); + if ($packcounter[$botcounter] < $#packlist) + { + $packcounter[$botcounter]++; + &ag_packrequest($botcounter); + } + else + { + $episode[$botcounter]++; + &ag_search($botcounter); + } } elsif ($termcounter[$botcounter] < $#terms) #otherwise just increment terms { $episode[$botcounter] = 1; - $formatflag[$botcounter] = 1; $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; &ag_search($botcounter); @@ -404,7 +389,6 @@ sub ag_skip else #if last episode on last search on last term finished, then resets counters and starts over { $episode[$botcounter] = 1; - $formatflag[$botcounter] = 1; $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); @@ -414,7 +398,7 @@ sub ag_skip elsif ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - &ag_search($botcounter); + &ag_packrequest($botcounter); } elsif ($termcounter[$botcounter] < $#terms) { @@ -426,7 +410,6 @@ sub ag_skip else #if last pack on last search on last term finished, then resets counters and starts over { $episode[$botcounter] = 1; - $formatflag[$botcounter] = 1; $packs[$botcounter] = (); #delete last bots packlist $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; @@ -435,58 +418,54 @@ sub ag_skip } } -sub ag_dummyclosedcc -{ - Irssi::signal_remove("dcc destroyed", "ag_dummyclosedcc"); - Irssi::signal_add("dcc destroyed", "ag_closedcc"); -} - sub ag_closedcc { my ($dcc) = @_; #current pack my $botname = $dcc->{'nick'}; #get the bots name, and checks if it's the one we want my $filename = $dcc->{'arg'}; + my $delayoverride = 1; #speed divider for the delays before next load, to avoid flooding when cancelling a pack $botname =~ tr/[A-Z]/[a-z]/; - + my $botcounter = 0; foreach my $bot (@bots) { $bot =~ tr/[A-Z]/[a-z]/; - if ($botname eq $bot and $reqpackflag[$botcounter]) #checks if the is the bot + if ($botname eq $bot and $reqpackflag[$botcounter]) #checks if this is the bot { my $temp = $botcounter; my @packlist = $packs[$botcounter]; my @termlist = $terms[$botcounter]; - @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred $reqpackflag[$botcounter] = 0; - # if ($dccflag == 0) {Irssi::signal_add("dcc request", "ag_opendcc");} #if so, reinits DCC get signal for the next pack - $dccflag = 1; &ag_remtimeouts($botcounter); if ($dcc->{'skipped'} == $dcc->{'size'}) { - ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't actually 'get' packs if they're already downloaded, causing long stalls if left unattended. + $delayoverride = 2; #doubles the delay for next message to make up for prematurely sending xdcc cancel + ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't get and then cancel packs on its own if they're already downloaded, causing stalls if left unattended. } if ($dcc->{'transfd'} == $dcc->{'size'}) { + @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred ag_addfinished($dcc->{'arg'}, $botcounter); - + } + if ($dcc->{'skipped'} == $dcc->{'size'} or $dcc->{'transfd'} == $dcc->{'size'}) + { if($episodicflag) { if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &packrequest($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &packrequest($temp); }, [])); } else { $packs[$botcounter] = (); #delete packlist $packcounter[$botcounter] = 0; $episode[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); } } else @@ -494,28 +473,28 @@ sub ag_closedcc if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); } elsif ($termcounter[$botcounter] < $#termlist) { $packs[$botcounter] = (); #delete last terms packlist $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_search($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); } else #if last pack on last search on last bot finished, then resets counters and starts over { $packs[$botcounter] = (); $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($temp); } , [])); $runningflag = 0; } } } else { - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($dcrdelay * 1000, sub { &ag_packrequest($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($dcrdelay * 1000 * $delayoverride, sub { &ag_packrequest($temp); }, [])); } } $botcounter++; @@ -695,7 +674,6 @@ sub ag_run #main loop $totags[$botcounter] = (); $msgflag[$botcounter] = 1; #flag controls whether bot has responded to search request $getmsgflag[$botcounter] = 0; #flag keeps track of getmsg signals - $formatflag[$botcounter] = 1; #flag controls whether a format is appended to the end of an episodic search string $reqpackflag[$botcounter] = 0; #flag to avoid multiple download requests $downloadflag[$botcounter] = 0; #flag to avoid multiple download requests $termcounter[$botcounter] = 0; @@ -722,7 +700,6 @@ sub ag_stop $getmsgflag[$botcounter] = 0; $botcounter++; @msgflag = (); - @formatflag = (); @reqpackflag = (); @downloadflag = (); @termcounter = (); @@ -735,7 +712,6 @@ sub ag_stop $runningflag = 0; $statusbarmessage = "Inactive"; } - $dccflag = 0; @terms = (); @bots = (); @packs = (); @@ -763,10 +739,8 @@ sub ag_restart $runningflag = 0; } @msgflag = (); - @formatflag = (); @reqpackflag = (); @downloadflag = (); - $dccflag = 0; Irssi::signal_add("server connected", "ag_initserver"); } sub ag_reset @@ -780,7 +754,6 @@ sub ag_reset Irssi::settings_set_str("ag_xdcc_send_prefix", "xdcc send"); Irssi::settings_set_str("ag_xdcc_cancel_prefix", "xdcc cancel"); Irssi::settings_set_str("ag_find_prefix", "!find"); - Irssi::settings_set_str("ag_format", ""); Irssi::settings_set_str("ag_folder", File::HomeDir->my_home); &ag_setettings; } @@ -796,7 +769,6 @@ sub ag_setsettings $sendprefix = Irssi::settings_get_str("ag_xdcc_send_prefix"); $cancelprefix = Irssi::settings_get_str("ag_xdcc_cancel_prefix"); $findprefix = Irssi::settings_get_str("ag_find_prefix"); - $format = Irssi::settings_get_str("ag_format"); $folder = Irssi::settings_get_str("ag_folder"); } -- cgit v1.2.3 From b55123f9f0d3e9c030a3df60c6979d5c844c1ded Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sat, 16 Jan 2016 00:51:53 -0500 Subject: minor edit for code critic --- scripts/xdcc_autoget.pl | 53 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index a84cdaf..5dfbcd0 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -18,7 +18,7 @@ # USE: to add the statusbar : /statusbar [name] add ag_statusbar # for help : ag_help # to run : ag_run -# to halt at next : ag_stop +# to halt : ag_stop # to reset all settings: ag_reset # to set the server : ag_server # to add a bot : ag_botadd BOT1 BOT2 *** BOTN @@ -26,16 +26,16 @@ # to add string : ag_add "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" # to remove strings : ag_rem "[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]","[ETC]",***,"[ETC]" # to see terms and bots: ag_list -# to clear cache : ag_clearcache -# ag_next_delay : delay between full transfers -# ag_dcc_closed_retry_delay : delay after premature transfer -# ag_bot_delay : delay between request and when you "SHOULD" get it -# ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another -# ag_autorun : whether to run on startup -# ag_xdcc_send_prefix : the xdcc message before the pack # -# ag_xdcc_find_prefix : the xdcc message before the search term -# ag_bot_file : where your bot list is stored -# ag_search_file : where your search list is stored +# to clear cache : ag_clearcache +# ag_next_delay : delay between full transfers +# ag_dcc_closed_retry_delay : delay after premature transfer +# ag_bot_delay : delay between request and when you "SHOULD" get it +# ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another +# ag_autorun : whether to run on startup +# ag_xdcc_send_prefix : the xdcc message before the pack # +# ag_xdcc_find_prefix : the xdcc message before the search term +# ag_bot_file : where your bot list is stored +# ag_search_file : where your search list is stored use strict; use warnings; @@ -159,27 +159,26 @@ sub ag_server #init server sub ag_help { Irssi::print "to add the statusbar : /statusbar [name] add ag_statusbar"; - Irssi::print "for this help : ag_help"; + Irssi::print "for help : ag_help"; Irssi::print "to run : ag_run"; - Irssi::print "to halt at next : ag_stop"; + Irssi::print "to halt : ag_stop"; Irssi::print "to reset all settings: ag_reset"; - Irssi::print "to set the server : ag_server"; + Irssi::print "to set the server : ag_server "; Irssi::print "to add a bot : ag_botadd BOT1 BOT2 *** BOTN"; Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; - Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; - Irssi::print "to remove strings : ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\""; + Irssi::print "to add string : ag_add \"[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]\",\"[ETC]\",***,\"[ETC]\" "; + Irssi::print "to remove strings : ag_rem \"[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]\",\"[ETC]\",***,\"[ETC]\" "; Irssi::print "to see terms and bots: ag_list"; Irssi::print "to clear cache : ag_clearcache"; - Irssi::print "ag_next_delay : delay between full transfers"; - Irssi::print "ag_dcc_closed_retry_delay: delay after premature transfer"; - Irssi::print "ag_bot_delay : max time to wait for the bot to respond"; - Irssi::print "ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another"; - Irssi::print "ag_autorun : whether to run on startup"; - Irssi::print "ag_episodic : search ep 1, if found then search ep 2. Use for series if bot limits search results. Results may vary depending on bot and search term"; - Irssi::print "ag_xdcc_send_prefix : the xdcc message before the pack #"; - Irssi::print "ag_xdcc_cancel_prefix : the xdcc message to cancel a transfer"; - Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; - Irssi::print "ag_folder : Location for data files. ~/.irssi/ reccomended"; + Irssi::print "ag_next_delay : delay between full transfers"; + Irssi::print "ag_dcc_closed_retry_delay : delay after premature transfer"; + Irssi::print "ag_bot_delay : delay between request and when you \"SHOULD\" get it"; + Irssi::print "ag_interrun_delay : delay (in minutes, the rest seconds) between finishing a round and starting another"; + Irssi::print "ag_autorun : whether to run on startup"; + Irssi::print "ag_xdcc_send_prefix : the xdcc message before the pack #"; + Irssi::print "ag_xdcc_find_prefix : the xdcc message before the search term"; + Irssi::print "ag_bot_file : where your bot list is stored"; + Irssi::print "ag_search_file : where your search list is stored"; } sub ag_getbots #reads in bot list @@ -221,7 +220,7 @@ sub ag_search #searches bots for packs if($episodicflag) { my $searchterm; - my @words = split('#', $terms[$termcounter[$botcounter]]); + my @words = split(/#/, $terms[$termcounter[$botcounter]]); my $ep = sprintf("%.2d", $episode[$botcounter]); if ($#words > 0){$searchterm = "$words[0]$ep$words[1]";} else {$searchterm = "$words[0] $ep";} -- cgit v1.2.3 From 19a677b2919670a34b8ba1e42e6e9ec4f80de273 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sat, 16 Jan 2016 01:03:10 -0500 Subject: revert minor explanation change --- scripts/xdcc_autoget.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 5dfbcd0..bb568a6 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -166,8 +166,8 @@ sub ag_help Irssi::print "to set the server : ag_server "; Irssi::print "to add a bot : ag_botadd BOT1 BOT2 *** BOTN"; Irssi::print "to remove a bot : ag_botrem BOT1 BOT2 *** BOTN"; - Irssi::print "to add string : ag_add \"[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]\",\"[ETC]\",***,\"[ETC]\" "; - Irssi::print "to remove strings : ag_rem \"[TEXT STRING OF TV SHOW/CHINESE CARTOON/ETC]\",\"[ETC]\",***,\"[ETC]\" "; + Irssi::print "to add string : ag_add \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\" "; + Irssi::print "to remove strings : ag_rem \"[TEXT STRING OF SEARCH]\",\"[ETC]\",***,\"[ETC]\" "; Irssi::print "to see terms and bots: ag_list"; Irssi::print "to clear cache : ag_clearcache"; Irssi::print "ag_next_delay : delay between full transfers"; -- cgit v1.2.3 From e4ccf2e6b0c697b03a7fd34cba746262c602fa56 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sat, 16 Jan 2016 20:43:07 -0500 Subject: bugfix --- scripts/xdcc_autoget.pl | 54 +++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index bb568a6..7538774 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -85,6 +85,7 @@ my @getmsgflag = (); #flag keeps track of getmsg signals my $episodicflag; #flag controls whether to search episode by episode (eg instead of searching boku no pice, it'll search for boku no pico 1, then boku no pico 2, etc as long as results show up) my @reqpackflag = (); #flag to avoid multiple download requests my @downloadflag = (); #flag to avoid multiple download requests +my @skipunfinishedflag = (); #flag to tell ag_closedcc to not redownload an unfinished file my $sendprefix; #virtually universal xdcc send, cancel, and find prefixes my $cancelprefix; @@ -115,10 +116,7 @@ sub ag_init #init system Irssi::print "AG | Autoget V$VERSION initiated"; Irssi::print "AG | /ag_help for help"; &ag_list; - if ($episodicflag) - { - Irssi::print "AG | Episodic: Yes"; - } + if ($episodicflag) {Irssi::print "AG | Episodic: Yes";} else {Irssi::print "AG | Episodic: No";} Irssi::print "AG | Data folder: $folder"; } @@ -314,6 +312,7 @@ sub ag_opendcc #runs on DCC recieve init my $botname = $gdcc->{'nick'}; my $filename = $gdcc->{'arg'}; my $filedownloadflag = 0; + $botname =~ tr/[A-Z]/[a-z]/; foreach my $file (@filenames){ if ($file eq $filename){ $filedownloadflag = 1; }} @@ -324,20 +323,21 @@ sub ag_opendcc #runs on DCC recieve init $bot =~ tr/[A-Z]/[a-z]/; if ($botname eq $bot and !$filedownloadflag) #if it's our bot and the file is not already being downloaded, let user know, and stop any further AG pack requests until finished { + &ag_remtimeouts($botcounter); #stop any other skips $getmsgflag[$botcounter] = 0; - - &ag_remtimeouts($botcounter); + + my $size = $gdcc->{'size'}; + my $skipped = $gdcc->{'skipped'}; + $downloadflag[$botcounter] = 1; foreach my $n (@finished) #don't redownload finished packs { if ($n eq $gdcc->{'arg'}) #if file already downloaded, cancel { - Irssi::signal_remove("dcc destroyed", "ag_closedcc"); + ag_message("msg $bots[$botcounter] $cancelprefix" ); + ag_addfinished($gdcc->{'arg'}, $botcounter); + $skipunfinishedflag[$botcounter] = 1; $gdcc->close; - $gdcc->{'skipped'} = $gdcc->{'size'}; - $gdcc->{'transfd'} = $gdcc->{'size'}; - ag_closedcc($gdcc); - Irssi::signal_add("dcc destroyed", "ag_closedcc"); } last if ($n eq $gdcc->{'arg'}); } @@ -345,11 +345,9 @@ sub ag_opendcc #runs on DCC recieve init } elsif ($botname eq $bot and $filedownloadflag) #don't download packs that are being downloaded by other bots { - Irssi::signal_remove("dcc destroyed", "ag_closedcc"); + ag_message("msg $bots[$botcounter] $cancelprefix" ); + $skipunfinishedflag[$botcounter] = 1; $gdcc->close; - $gdcc->{'skipped'} = $gdcc->{'size'}; - ag_closedcc($gdcc); - Irssi::signal_add("dcc destroyed", "ag_closedcc"); } $botcounter++; } @@ -445,26 +443,28 @@ sub ag_closedcc $delayoverride = 2; #doubles the delay for next message to make up for prematurely sending xdcc cancel ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't get and then cancel packs on its own if they're already downloaded, causing stalls if left unattended. } - if ($dcc->{'transfd'} == $dcc->{'size'}) - { - @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred - ag_addfinished($dcc->{'arg'}, $botcounter); - } - if ($dcc->{'skipped'} == $dcc->{'size'} or $dcc->{'transfd'} == $dcc->{'size'}) + if ($dcc->{'transfd'} == $dcc->{'size'} or $skipunfinishedflag[$botcounter]) { + if (!$skipunfinishedflag[$botcounter]) + { + @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred + ag_addfinished($dcc->{'arg'}, $botcounter); + } + $skipunfinishedflag[$botcounter] = 0; #reset any skip flags if($episodicflag) { if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &packrequest($temp); }, [])); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_packrequest($temp); }, []); } else { $packs[$botcounter] = (); #delete packlist $packcounter[$botcounter] = 0; $episode[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); + Irssi::print"$bots[$botcounter] $filename ag_search()"; + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); } } else @@ -472,21 +472,21 @@ sub ag_closedcc if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); } elsif ($termcounter[$botcounter] < $#termlist) { $packs[$botcounter] = (); #delete last terms packlist $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, [])); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); } else #if last pack on last search on last bot finished, then resets counters and starts over { $packs[$botcounter] = (); $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($temp); } , [])); + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($temp); } , []); $runningflag = 0; } } @@ -675,6 +675,7 @@ sub ag_run #main loop $getmsgflag[$botcounter] = 0; #flag keeps track of getmsg signals $reqpackflag[$botcounter] = 0; #flag to avoid multiple download requests $downloadflag[$botcounter] = 0; #flag to avoid multiple download requests + $skipunfinishedflag[$botcounter] = 0; $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; $episode[$botcounter] = 1; @@ -701,6 +702,7 @@ sub ag_stop @msgflag = (); @reqpackflag = (); @downloadflag = (); + @skipunfinishedflag = (); @termcounter = (); @packcounter = (); @episode = (); -- cgit v1.2.3 From e8a25b476f79fd96abc59c619041b737ac739da9 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 17 Jan 2016 01:46:08 -0500 Subject: more goodness while we're at it --- scripts/xdcc_autoget.pl | 69 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 7 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 7538774..15d0ffb 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -116,6 +116,7 @@ sub ag_init #init system Irssi::print "AG | Autoget V$VERSION initiated"; Irssi::print "AG | /ag_help for help"; &ag_list; + &ag_getfinished; if ($episodicflag) {Irssi::print "AG | Episodic: Yes";} else {Irssi::print "AG | Episodic: No";} Irssi::print "AG | Data folder: $folder"; @@ -202,6 +203,59 @@ sub ag_getfinished #reads in finished packs list chomp(@finished); @finished = ag_uniq(@finished); close(FINISHED); + &ag_clearcache; + @finished = &ag_uniq(@finished); + @finished = nsort(@finished); #sort normally + open(FINISHED, ">", $cachefilename); + foreach my $finish (@finished) + { + print FINISHED $finish . "\n"; #print name to file + } + close(FINISHED); +} + +sub nsort { #shamelessly ripped from Sort::Naturally + my($cmp, $lc); + return @_ if @_ < 2; # Just to be CLEVER. + + my($x, $i); # scratch vars + + map + $_->[0], + + sort { + # Uses $i as the index variable, $x as the result. + $x = 0; + $i = 1; + + while($i < @$a and $i < @$b) { + last if ($x = ($a->[$i] cmp $b->[$i])); # lexicographic + ++$i; + + last if ($x = ($a->[$i] <=> $b->[$i])); # numeric + ++$i; + } + + $x || (@$a <=> @$b) || ($a->[0] cmp $b->[0]); + } + + map { + my @bit = ($x = defined($_) ? $_ : ''); + + if($x =~ m/^[+-]?(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee](?:[+-]?\d+))?\z/s) { + # It's entirely purely numeric, so treat it specially: + push @bit, '', $x; + } else { + # Consume the string. + while(length $x) { + push @bit, ($x =~ s/^(\D+)//s) ? lc($1) : ''; + push @bit, ($x =~ s/^(\d+)//s) ? $1 : 0; + } + } + + \@bit; + } + @_; } sub ag_clearcache #clears cache of saved packs @@ -269,7 +323,6 @@ sub ag_getpacks #if ($m =~ m{#(\d+):}) my($message, $botcounter) = @_; my @temp = split(/[#,]/, $message); #split up the message into 'words' my $timeoutscleared = 0; - &ag_getfinished; my $newpackflag = 1; foreach my $m (@temp) #find packs (#[NUMBER]: format) @@ -284,7 +337,9 @@ sub ag_getpacks #if ($m =~ m{#(\d+):}) } foreach my $n (@finished) #don't redownload finished packs { - if ($n eq "$bots[$botcounter] $1" or $n eq $2) {$newpackflag = 0;} + my $filename = $2; + $filename =~ tr/[ ']/[__]/; + if ($n eq "$bots[$botcounter] $1" or $n eq $filename) {$newpackflag = 0;} last if ($n eq "$bots[$botcounter] $1"); } if($newpackflag){push(@{$packs[$botcounter]}, $1);} #push all new pack numbers to list of packs @@ -313,6 +368,7 @@ sub ag_opendcc #runs on DCC recieve init my $filename = $gdcc->{'arg'}; my $filedownloadflag = 0; + $filename =~ tr/[ ']/[__]/; $botname =~ tr/[A-Z]/[a-z]/; foreach my $file (@filenames){ if ($file eq $filename){ $filedownloadflag = 1; }} @@ -325,10 +381,7 @@ sub ag_opendcc #runs on DCC recieve init { &ag_remtimeouts($botcounter); #stop any other skips $getmsgflag[$botcounter] = 0; - - my $size = $gdcc->{'size'}; - my $skipped = $gdcc->{'skipped'}; - + $downloadflag[$botcounter] = 1; foreach my $n (@finished) #don't redownload finished packs { @@ -441,12 +494,13 @@ sub ag_closedcc if ($dcc->{'skipped'} == $dcc->{'size'}) { $delayoverride = 2; #doubles the delay for next message to make up for prematurely sending xdcc cancel - ag_message("msg $bots[$botcounter] $cancelprefix"); #workaround because IRSSI doesn't get and then cancel packs on its own if they're already downloaded, causing stalls if left unattended. + if (!$skipunfinishedflag[$botcounter]) {ag_message("msg $bots[$botcounter] $cancelprefix");} #workaround to cancel packs avoiding stalls if left unattended. } if ($dcc->{'transfd'} == $dcc->{'size'} or $skipunfinishedflag[$botcounter]) { if (!$skipunfinishedflag[$botcounter]) { + $filename =~ tr/[ ']/[__]/; @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred ag_addfinished($dcc->{'arg'}, $botcounter); } @@ -524,6 +578,7 @@ sub ag_addfinished #save finished downloads my ($filename, $botcounter) = @_; open(FINISHED, ">>", $cachefilename); print FINISHED $bots[$botcounter] . " " . $packs[$botcounter][$packcounter[$botcounter]] . "\n"; #print pack to file + $filename =~ tr/[ ']/[__]/; print FINISHED $filename . "\n"; #print name to file close(FINISHED); } -- cgit v1.2.3 From 6ead5755d4a3c4ca1e7c6a9d64fe5b8bc13dd95f Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Sun, 17 Jan 2016 14:44:28 -0500 Subject: removed debugging output --- scripts/xdcc_autoget.pl | 1 - 1 file changed, 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 15d0ffb..d4dc2ca 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -517,7 +517,6 @@ sub ag_closedcc $packs[$botcounter] = (); #delete packlist $packcounter[$botcounter] = 0; $episode[$botcounter]++; - Irssi::print"$bots[$botcounter] $filename ag_search()"; Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); } } -- cgit v1.2.3 From 8c09341e65647d6aac3569944b87378c2156f725 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Mon, 18 Jan 2016 00:43:06 -0500 Subject: fix download list not being cleared on ag_stop --- scripts/xdcc_autoget.pl | 1 + 1 file changed, 1 insertion(+) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index d4dc2ca..5d77ef7 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -760,6 +760,7 @@ sub ag_stop @termcounter = (); @packcounter = (); @episode = (); + @filenames = (); } if($runningflag == 1) -- cgit v1.2.3 From 06d689cd69de98631abaa1190c5d480470b6e9a1 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Mon, 18 Jan 2016 21:49:07 -0500 Subject: bugfix for ag_stop and ag_restart --- scripts/xdcc_autoget.pl | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 5d77ef7..c7489a8 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -489,6 +489,11 @@ sub ag_closedcc $reqpackflag[$botcounter] = 0; + if (!$skipunfinishedflag[$botcounter]) + { + $filename =~ tr/[ ']/[__]/; + @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred + } &ag_remtimeouts($botcounter); if ($dcc->{'skipped'} == $dcc->{'size'}) @@ -500,8 +505,6 @@ sub ag_closedcc { if (!$skipunfinishedflag[$botcounter]) { - $filename =~ tr/[ ']/[__]/; - @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred ag_addfinished($dcc->{'arg'}, $botcounter); } $skipunfinishedflag[$botcounter] = 0; #reset any skip flags @@ -751,17 +754,17 @@ sub ag_stop { &ag_remtimeouts($botcounter); #stop any skips from happening ag_message("msg $bot $cancelprefix"); - $getmsgflag[$botcounter] = 0; $botcounter++; - @msgflag = (); - @reqpackflag = (); - @downloadflag = (); - @skipunfinishedflag = (); - @termcounter = (); - @packcounter = (); - @episode = (); - @filenames = (); } + @getmsgflag = (); + @msgflag = (); + @reqpackflag = (); + @downloadflag = (); + @skipunfinishedflag = (); + @termcounter = (); + @packcounter = (); + @episode = (); + @filenames = (); if($runningflag == 1) { @@ -780,23 +783,7 @@ sub ag_restart $statusbarmessage = "No Connection"; Irssi::signal_remove("dcc request", "ag_opendcc"); Irssi::signal_remove("message irc notice", "ag_getmsg"); - - my $botcounter = 0; - foreach my $bot (@bots) - { - $getmsgflag[$botcounter] = 0; - &ag_remtimeouts($botcounter); - ag_message("msg $bot $cancelprefix"); - $botcounter++; - } - - if($runningflag == 1) - { - $runningflag = 0; - } - @msgflag = (); - @reqpackflag = (); - @downloadflag = (); + &ag_stop(); Irssi::signal_add("server connected", "ag_initserver"); } sub ag_reset -- cgit v1.2.3 From 911f4eb9681da8ab535e3f75038fd1df8c2d6307 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Mon, 18 Jan 2016 22:19:31 -0500 Subject: minor bugfix --- scripts/xdcc_autoget.pl | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index c7489a8..8ef45f0 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -711,8 +711,6 @@ sub ag_botrem #remove bots sub ag_run #main loop { - Irssi::signal_add("dcc request", "ag_opendcc"); #init DCC recieve init flag - Irssi::signal_add("message irc notice", "ag_getmsg"); if (!$initflag) {ag_server(Irssi::active_server());} if($runningflag == 0) { @@ -745,10 +743,7 @@ sub ag_run #main loop } sub ag_stop -{ - Irssi::signal_remove("dcc request", "ag_opendcc"); - Irssi::signal_remove("message irc notice", "ag_getmsg"); - +{ my $botcounter = 0; foreach my $bot (@bots) { @@ -774,15 +769,12 @@ sub ag_stop @terms = (); @bots = (); @packs = (); - @finished = (); $botcounter = 0; } sub ag_restart { $statusbarmessage = "No Connection"; - Irssi::signal_remove("dcc request", "ag_opendcc"); - Irssi::signal_remove("message irc notice", "ag_getmsg"); &ag_stop(); Irssi::signal_add("server connected", "ag_initserver"); } @@ -828,6 +820,8 @@ Irssi::timeout_add(100, sub { Irssi::statusbars_recreate_items(); Irssi::statusb &ag_init; if ($initflag) {Irssi::signal_add("server connected", "ag_initserver");} +Irssi::signal_add("dcc request", "ag_opendcc"); +Irssi::signal_add("message irc notice", "ag_getmsg"); Irssi::signal_add("server disconnected", "ag_restart"); Irssi::signal_add("server lag disconnect", "ag_restart"); Irssi::signal_add("setup changed", "ag_setsettings"); -- cgit v1.2.3 From 53bc5df277ecbd06a07f7beda6add968a9274278 Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Tue, 19 Jan 2016 01:18:21 -0500 Subject: edits to conform to perl5 --- scripts/xdcc_autoget.pl | 81 ++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 41 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 8ef45f0..05f55d8 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -204,7 +204,6 @@ sub ag_getfinished #reads in finished packs list @finished = ag_uniq(@finished); close(FINISHED); &ag_clearcache; - @finished = &ag_uniq(@finished); @finished = nsort(@finished); #sort normally open(FINISHED, ">", $cachefilename); foreach my $finish (@finished) @@ -278,12 +277,12 @@ sub ag_search #searches bots for packs else {$searchterm = "$words[0] $ep";} ag_message("msg $bots[$botcounter] $findprefix $searchterm" ); - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { ag_skip($botcounter); } , [])); } else #if not episodic, just search and skip { ag_message("msg $bots[$botcounter] $findprefix $terms[$termcounter[$botcounter]]" ); - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { &ag_skip($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { ag_skip($botcounter); } , [])); } } @@ -294,7 +293,7 @@ sub ag_remtimeouts #remove timeouts to avoid multiple instances of everything { Irssi::timeout_remove($to); } - $totags[$botcounter] = (); + @{$totags[$botcounter]} = (); } sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this from sending useless shit that breaks things @@ -311,7 +310,7 @@ sub ag_getmsg #runs when bot sends privmsg. Avoid talking to bots to keep this { ag_getpacks($message, $botcounter); #check for any new packs in the message my @packlist = @{$packs[$botcounter]}; - if($#packlist >= 0){ &ag_packrequest($botcounter); } #if there are any packs, + if($#packlist >= 0){ ag_packrequest($botcounter); } #if there are any packs, $msgflag[$botcounter] = 1; #let everyone know that the current bot has replied } $botcounter++; @@ -331,9 +330,9 @@ sub ag_getpacks #if ($m =~ m{#(\d+):}) { if (!$timeoutscleared) #reset timeouts if any packs are found { - &ag_remtimeouts($botcounter); + ag_remtimeouts($botcounter); $timeoutscleared = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { &ag_skip($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($nexdelay * 1000, sub { ag_skip($botcounter); } , [])); } foreach my $n (@finished) #don't redownload finished packs { @@ -351,18 +350,18 @@ sub ag_getpacks #if ($m =~ m{#(\d+):}) sub ag_packrequest #sends the xdcc send request, and retries on failure { my($botcounter) = @_; - &ag_remtimeouts($botcounter); + ag_remtimeouts($botcounter); if (!$reqpackflag[$botcounter]) { $reqpackflag[$botcounter] = 1; ag_message("msg $bots[$botcounter] $sendprefix $packs[$botcounter][$packcounter[$botcounter]]"); - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag[$botcounter]) { &ag_packrequest($botcounter); } } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($botdelay * 1000, sub { if (!$downloadflag[$botcounter]) { ag_packrequest($botcounter); } } , [])); } } sub ag_opendcc #runs on DCC recieve init { - &Irssi::signal_continue; + Irssi::signal_continue; my ($gdcc) = @_; #current pack my $botname = $gdcc->{'nick'}; my $filename = $gdcc->{'arg'}; @@ -379,7 +378,7 @@ sub ag_opendcc #runs on DCC recieve init $bot =~ tr/[A-Z]/[a-z]/; if ($botname eq $bot and !$filedownloadflag) #if it's our bot and the file is not already being downloaded, let user know, and stop any further AG pack requests until finished { - &ag_remtimeouts($botcounter); #stop any other skips + ag_remtimeouts($botcounter); #stop any other skips $getmsgflag[$botcounter] = 0; $downloadflag[$botcounter] = 1; @@ -412,7 +411,7 @@ sub ag_skip my @packlist = (); try {my @packlist = @{$packs[$botcounter]};} #workaround for @{} being dumb if an array inside of an array is empty catch {}; - &ag_remtimeouts($botcounter); #stop any other skips + ag_remtimeouts($botcounter); #stop any other skips $reqpackflag[$botcounter] = 0; #allow pack requests now that transfer is finished if($episodicflag) { @@ -421,12 +420,12 @@ sub ag_skip if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - &ag_packrequest($botcounter); + ag_packrequest($botcounter); } else { $episode[$botcounter]++; - &ag_search($botcounter); + ag_search($botcounter); } } elsif ($termcounter[$botcounter] < $#terms) #otherwise just increment terms @@ -434,28 +433,28 @@ sub ag_skip $episode[$botcounter] = 1; $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; - &ag_search($botcounter); + ag_search($botcounter); } else #if last episode on last search on last term finished, then resets counters and starts over { $episode[$botcounter] = 1; $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { ag_search($botcounter); } , [])); $runningflag = 0; } } elsif ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - &ag_packrequest($botcounter); + ag_packrequest($botcounter); } elsif ($termcounter[$botcounter] < $#terms) { $packs[$botcounter] = (); #delete last terms packlist $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; - &ag_search($botcounter); + ag_search($botcounter); } else #if last pack on last search on last term finished, then resets counters and starts over { @@ -463,7 +462,7 @@ sub ag_skip $packs[$botcounter] = (); #delete last bots packlist $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($botcounter); } , [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($exedelay * 1000 * 60, sub { ag_search($botcounter); } , [])); $runningflag = 0; } } @@ -494,7 +493,7 @@ sub ag_closedcc $filename =~ tr/[ ']/[__]/; @filenames = grep { $_ ne $filename } @filenames; #remove the file from the list of files being transferred } - &ag_remtimeouts($botcounter); + ag_remtimeouts($botcounter); if ($dcc->{'skipped'} == $dcc->{'size'}) { @@ -513,14 +512,14 @@ sub ag_closedcc if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_packrequest($temp); }, []); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { ag_packrequest($temp); }, []); } else { $packs[$botcounter] = (); #delete packlist $packcounter[$botcounter] = 0; $episode[$botcounter]++; - Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { ag_search($temp); }, []); } } else @@ -528,28 +527,28 @@ sub ag_closedcc if ($packcounter[$botcounter] < $#packlist) { $packcounter[$botcounter]++; - Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { ag_search($temp); }, []); } elsif ($termcounter[$botcounter] < $#termlist) { $packs[$botcounter] = (); #delete last terms packlist $termcounter[$botcounter]++; $packcounter[$botcounter] = 0; - Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { &ag_search($temp); }, []); + Irssi::timeout_add_once($nexdelay * 1000 * $delayoverride, sub { ag_search($temp); }, []); } else #if last pack on last search on last bot finished, then resets counters and starts over { $packs[$botcounter] = (); $termcounter[$botcounter] = 0; $packcounter[$botcounter] = 0; - Irssi::timeout_add_once($exedelay * 1000 * 60, sub { &ag_search($temp); } , []); + Irssi::timeout_add_once($exedelay * 1000 * 60, sub { ag_search($temp); } , []); $runningflag = 0; } } } else { - push(@{$totags[$botcounter]}, Irssi::timeout_add_once($dcrdelay * 1000 * $delayoverride, sub { &ag_packrequest($temp); }, [])); + push(@{$totags[$botcounter]}, Irssi::timeout_add_once($dcrdelay * 1000 * $delayoverride, sub { ag_packrequest($temp); }, [])); } } $botcounter++; @@ -610,8 +609,8 @@ sub ag_parseadd #parses add arguments for storage print FILE qq{$sLine\n} unless ($hTmp{$sLine}++); } close(FILE); - &ag_getbots; - &ag_getterms; + ag_getbots; + ag_getterms; } sub ag_parserem #parses remove arguments for deletion from file @@ -655,7 +654,7 @@ sub ag_parserem #parses remove arguments for deletion from file sub ag_add #add search terms { - &ag_server; + ag_server; my @args = quotewords('\s+', 0, $_[0]); #split arguments (words in brackets not seperated) if ($#args < 0) { @@ -664,12 +663,12 @@ sub ag_add #add search terms return; } ag_parseadd($searchesfilename, @args); - &ag_list; + ag_list; } sub ag_rem #remove ssearch terms { - &ag_server; + ag_server; my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { @@ -678,12 +677,12 @@ sub ag_rem #remove ssearch terms return; } ag_parserem($searchesfilename, @args); - &ag_list; + ag_list; } sub ag_botadd #add bots { - &ag_server; + ag_server; my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { @@ -692,12 +691,12 @@ sub ag_botadd #add bots return; } ag_parseadd($botsfilename, @args); - &ag_list; + ag_list; } sub ag_botrem #remove bots { - &ag_server; + ag_server; my @args = quotewords('\s+', 0, $_[0]); if ($#args < 0) { @@ -706,7 +705,7 @@ sub ag_botrem #remove bots return; } ag_parserem($botsfilename, @args); - &ag_list; + ag_list; } sub ag_run #main loop @@ -715,8 +714,8 @@ sub ag_run #main loop if($runningflag == 0) { $runningflag = 1; - &ag_getbots; - &ag_getterms; + ag_getbots; + ag_getterms; if($#bots < 0 or $#terms < 0) { $statusbarmessage = "No bots or no search terms."; Irssi::timeout_add_once(1000, sub { &ag_run; }, []);} else @@ -735,7 +734,7 @@ sub ag_run #main loop $packcounter[$botcounter] = 0; $episode[$botcounter] = 1; $packs[$botcounter] = (); - &ag_search($botcounter); + ag_search($botcounter); $botcounter++; } } @@ -747,7 +746,7 @@ sub ag_stop my $botcounter = 0; foreach my $bot (@bots) { - &ag_remtimeouts($botcounter); #stop any skips from happening + ag_remtimeouts($botcounter); #stop any skips from happening ag_message("msg $bot $cancelprefix"); $botcounter++; } @@ -775,7 +774,7 @@ sub ag_stop sub ag_restart { $statusbarmessage = "No Connection"; - &ag_stop(); + ag_stop(); Irssi::signal_add("server connected", "ag_initserver"); } sub ag_reset -- cgit v1.2.3 From 53e2ce6eb04327659c894b0a42676ebb044604fb Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Wed, 20 Jan 2016 20:44:02 -0500 Subject: bugfix --- scripts/xdcc_autoget.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index 05f55d8..ed5e206 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -361,7 +361,7 @@ sub ag_packrequest #sends the xdcc send request, and retries on failure sub ag_opendcc #runs on DCC recieve init { - Irssi::signal_continue; + &Irssi::signal_continue; my ($gdcc) = @_; #current pack my $botname = $gdcc->{'nick'}; my $filename = $gdcc->{'arg'}; -- cgit v1.2.3 From 910eef851a0aae8d0ebd30b5c8a4bd6fe32a14ef Mon Sep 17 00:00:00 2001 From: Alex Checca Date: Wed, 20 Jan 2016 20:51:15 -0500 Subject: removed ugly try catch --- scripts/xdcc_autoget.pl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/xdcc_autoget.pl b/scripts/xdcc_autoget.pl index ed5e206..fc1d7db 100644 --- a/scripts/xdcc_autoget.pl +++ b/scripts/xdcc_autoget.pl @@ -408,9 +408,7 @@ sub ag_opendcc #runs on DCC recieve init sub ag_skip { my($botcounter) = @_; - my @packlist = (); - try {my @packlist = @{$packs[$botcounter]};} #workaround for @{} being dumb if an array inside of an array is empty - catch {}; + my @packlist = @{$packs[$botcounter]//[]}; #if $packs[botcounter] is undefined, pass an empty array reference ag_remtimeouts($botcounter); #stop any other skips $reqpackflag[$botcounter] = 0; #allow pack requests now that transfer is finished if($episodicflag) -- cgit v1.2.3