##### WHATauto - an irssi auto-download script ##### # Version 1.1.6 By mlapaglia & gravey13 (7-19-2009) # Regular Expressions provided by oorza # Original download routines provided by pssimon # # run "/load ~/WHATauto.pl" in IRSSI to start script. # copy it to "~/.irssi/scripts/autorun" to make it autoload with IRSSI. # # Once loaded into irssi, this script waits for releases from Drone in #what.cd-announce. # When found, the script checks them against user-created download criteria, and downloads # the .torrent file accordingly. # # General commands can be found by typing "%help" # Administrative commands can be found by typing "%admin help" # ################################################### ################################################### ############### BEGIN CONFIGURATION ############### ################################################### # Variables are handled the same as notification filters. # All variables except for @artistFilter and @tagFilter _MUST_ be populated for this script to work. ############ OUTPUT OPTIONS ############# # Default location for downloaded .torrents - "/home/mlapaglia/test" # Torrents will go here if a specific directory isn't specified below my $torrentDir = "/home/rhodan/private/rtorrent/watch/"; # Percentage of hard drive space required in order to download .torrents # Only applies to the What.CD autodownloader my $freePercent = 5; # Folder data is stored in, for showing free space - ("/home/Downloads/"); my $drive = "/home/rhodan/"; ########################################## ################ IRC Info ################ #AS OF VERSION 1.1.4, WhatBot will now obey you based on your address, not nick. To find your address, #identify yourself with drone, then type /whois and find you should see your address, formatted similar to below. ###################################### # IRC addresses the script will obey, cannot be live altered. - ('81126@mlapaglia.vip.what.cd', '122433@gravey13.elite.what.cd'); # Users listed here do NOT need to be in @nickFilter or @adminNickFilter. my @nickOwner = ('181800@rhodan.member.what.cd'); # IRC addresses the script will obey. - ('81126@mlapaglia.vip.what.cd', '122433@gravey13.elite.what.cd'); my @nickFilter = (""); # IRC administrative addresses the script will obey. - ("81126@mlapaglia.vip.what.cd", "122433@gravey13.elite.what.cd"); # Users in this list must also be in @nickFilter, and can change filter and authorization settings my @adminNickFilter = (""); # IRC channels the script should accept commands in - ("#WhatBot"); my @chanFilter = ("#WhatBot", "#whatbot"); ######################################### ### WHAT.CD LOGIN INFO - **REQUIRED** ### # username and password to download What.cd .torrents # if password has special characters, it must be in single quotes my $usernameWHAT = "rhodan"; my $passwordWHAT = 'hunter2'; # IRC pass - found in your profile my $ircPassWHAT = "hunter2"; # IRC Nick password - to identify with NickServ my $nickPassWHAT = "hunter2"; ######################################### ######### WHAT.CD AUDIO FILTERS ######### ##Leave each filter empty to "skip" it ## #@activateMusic = (0|1); Use to turn on/off music downloading my $activateMusic = 1; #@artistFilter = ("Augustana", "The Killers", "Phoenix"); my @artistFilter = (); #@tagFilter = ("rock", "post.rock", "metal", "progressive.metal", "death.metal", "alternative", "hip.hop", "jpop", "house"); my @tagFilter = (); #@formatFilter = ("MP3" "FLAC", "Ogg", "APE", "AAC", "AC3", "WavPack", "DTS", "ALAC"); my @formatFilter = ("MP3"); #@qualityFilter = (192, "APS (VBR)", "V2 (VBR)", "V1 (VBR)", 256, "APX (VBR)", "V0 (VBR)", "q8.x (VBR)", 320, "Lossless", "24bit Lossless", "Other"); my @qualityFilter = ("V0 (VBR)"); #@sourceFilter = ("CD", "DVD", "Vinyl", "Soundboard", "SACD", "DAT", "Cassette", "WEB"); my @sourceFilter = (); #@yearFilter = (1990, 1991, 1992, 1993); WILDCARDS DO NOT WORK, SORRY my @yearFilter = (2009); # $sceneFilter = (1|0); my $sceneFilter = 0; #####FLAC FILTERS###### # $logFilter = (1|0); Only applies to FLAC releases. my $logFilter = 0; # $logPercentFilter = (0-100); $logfilter must be set to 1. # Set to 0 to download all torrents with logs. Anything above given percent will be downloaded. my $logPercentFilter = 0; # $cueFilter = (1|0); my $cueFilter = 0; ######################################### #### WHAT.CD EBOOK/SOFTWARE FILTERS ##### ## Leave each filter open to "skip" it ## # @activateEbook = (0|1); Use to turn on/off ebook downloading my $activateEbook = 0; # @titleFilter = ("superman", "marvel") my @ebookTitleFilter = (); # @ebooktagsFilter = ("tutorial", "adobe", "ebook") my @ebookTagFilter = (); ######################################### ########### OTHER LOGIN IDs ############# # To specify a different watch directory to download .torrents to, fill in the appropriate path # ex: my $watchSCT = "/home/gravey/watch" #username and password to download Waffles .torrents my $usernameWAFFLES = ""; my $passwordWAFFLES = ''; my $watchWAFFLES = ""; # username and password to download ScT .torrents my $usernameSCT = ""; my $passwordSCT = ''; my $watchSCT = ""; # username and password to download SCC .torrents my $usernameSCC = ""; my $passwordSCC = ''; my $watchSCC = ""; #username and password to download HDbits .torrents my $usernameHDbits = ""; my $passwordHDbits = ''; my $watchHDbits = ""; #username and password to download x264 .torrents my $usernamex264 = ""; my $passwordx264 = ''; my $watchx264 = ""; #username and password to download RevTT .torrents my $usernameRevTT = ""; my $passwordRevTT = ''; my $watchRevTT = ""; #username and password to download STMusic .torrents my $usernameSTMUSIC = ""; my $passwordSTMUSIC = ''; my $watchSTMUSIC = ""; #username and password to download Goem .torrents my $usernameGoem = ""; my $passwordGoem = ''; my $watchGoem = ""; #username and password to download SDbits .torrents my $usernameSDbits = ""; my $passwordSDbits = ''; my $watchSDbits = ""; #username and password to download TehConnection .torrents my $usernameTC = ""; my $passwordTC = ''; my $watchTC = ""; #username and password to download Libble .torrents my $usernameLibble = ""; my $passwordLibble = ''; my $watchLibble = ""; #username and password to download Bit-HDTV .torrents my $usernameBitHDTV = ""; my $passwordBitHDTV = ''; my $watchBitHDTV = ""; #username and password to download TorrentDamage .torrents my $usernameTD = ""; my $passwordTD = ''; my $watchTD = ""; #username and password to download PTN .torrents my $usernamePTN = ""; my $passwordPTN = ''; my $watchPTN = ""; ########################################## ################################################# ############### END CONFIGURATION ############### ################################################# use strict; use Irssi; use Irssi::Irc; use threads; use WWW::Mechanize; use Filesys::DiskSpace; use HTML::Entities; use vars qw($VERSION %IRSSI); $VERSION="1.1.6"; %IRSSI = ( authors=> 'mlapaglia & gravey', name=> 'WHATauto', description=> 'an irssi auto-download script', license=> 'GPL', ); # Irssi settings Irssi::settings_set_int('cmds_max_at_once', 20); Irssi::settings_set_int('cmd_queue_speed', 0); # Log data (sets how many torrents the script has seen and downloaded) my $seen = 0; my $downloaded = 0; # Print script error if any What.CD information is left empty if (!$usernameWHAT || !$passwordWHAT || !$ircPassWHAT|| !$torrentDir) { Irssi::print (" "); Irssi::print ("****************************************"); Irssi::print ("** ERROR: What.CD username, password, and IRC pass, and torrent watch directory required."); Irssi::print ("** Please provide this information in the configuration."); Irssi::print ("** username: $usernameWHAT, password: $passwordWHAT, IRCkey: $ircPassWHAT, torrent director: $torrentDir"); Irssi::print ("****************************************"); Irssi::print (" "); } else { Irssi::print ("-------------------------------------"); Irssi::print ("*Configured Filters:"); Irssi::print ("---Music---"); Irssi::print ("||Music Activated: $activateMusic"); Irssi::print ("||Torrent Directory: $torrentDir"); Irssi::print ("||Artist Filter: @artistFilter"); Irssi::print ("||Tag Filter: @tagFilter"); Irssi::print ("||Format Filter: @formatFilter"); Irssi::print ("||Quality Filter: @qualityFilter"); Irssi::print ("||Source Filter: @sourceFilter"); Irssi::print ("||Year Filter: @yearFilter"); Irssi::print ("||Scene Filter: $sceneFilter | FLAC log Filter: $logFilter | FLAC percent Filter: $logPercentFilter | CUE Filter: $cueFilter"); Irssi::print ("---Ebook/Software/Comics---"); Irssi::print ("||Ebook Activated: $activateEbook"); Irssi::print ("||Title Filter: @ebookTitleFilter"); Irssi::print ("||Tag Filter: @ebookTagFilter"); Irssi::print ("-------------------------------------"); } ############### #subroutine executes every time a channel is joined sub channel_joined { my @chanlist = @_; my $channel = $chanlist[0]->{name}; my $server = $chanlist[0]->{server}; chanBlock($channel, $server); } ############### #subroutine executes every time a new connection is made sub event_connected { my ($server) = @_; print Dumper $server->{address}; if ($server->{address} eq "irc.what-network.net") { threads->new(\&initalize_what, $server)->detach(); } } ############### # What.CD connection established sub initalize_what { my ($server) = @_; $server->send_raw("PRIVMSG NickServ :identify $nickPassWHAT"); sleep(2); $server->send_raw("PRIVMSG drone :enter #what.cd-announce $usernameWHAT $ircPassWHAT"); sleep(2); $server->command("JOIN #WhatBot"); } ############### #subroutine executes when channel invite is received sub message_invite { my ($server, $channel, $nick, $address) = @_; if (isOwner($address)) { $server->command("JOIN $channel"); } } ############### #subroutine for each private message received #splitting each message into it's own thread. sub event_privmsg { #inputting message from irssi my ($data, $message, $nick, $address) = @_; #stripping off leading channel identification my ($target, $text) = split(/ :/, $message, 2); #continue if message is from Drone. if($target eq "#what.cd-announce" && $nick eq "Drone") { #if the message matches the known music release string, break message into component parts for comparison. #This regular expression brought to you by the sheer awesomeness oorza. Thanks! if($text =~ m!(.+) - (.+) \[([0-9]+)\] - (MP3|FLAC|Ogg|AAC|AC3|DTS) / ((24bit)? ?Lossless|[Vxq\.0-9|APS]{1,5}( \(VBR\))?) / (Log)? ?/? ?([\-0-9]+\%)? ?/? ?(Cue)? ?/? ?(CD|DVD|Vinyl|Soundboard|SACD|Cassette|DAT|WEB) ?/? ?(Scene)? - http://what\.cd/torrents\.php\?id=([0-9]+) / http://what\.cd/torrents\.php\?action=download&id=([0-9]+) - (.+)!) { $seen++; #Don't download if music filter isn't activated if(!$activateMusic) { return; } #Dont't download if disk space gets below set amount if(checkSpace() != 1) { return; } #Assign the values pulled from the regex my ($artist, $album, $year, $format, $quality, $log, $logPercent, $cue, $source, $scene, $torrentID, $downloadID, @tags) = ($1, $2, $3, $4, $5, $8, $9, $10, $11, $12, $13, $14, split /, /, $15); print "*Detected announce: $artist - $album \[$year\] - $format / $quality / $log / $logPercent / $source"; #Check each filter for matches in format, quality, source, year, and artist. if(filter("format", $format, @formatFilter) && filter("quality", $quality, @qualityFilter) && filter("source", $source, @sourceFilter) && filter("year", $year, @yearFilter) && filter("artist", $artist, @artistFilter)) { #if log filter is present, but doesn't match the given release, exit. if ($logFilter && $format eq "FLAC" && !$log) { print "||Didn't detect match in log: log not present"; return; } elsif ($logFilter && $log) { print "||Detected match in log: log present"; if ($logPercentFilter != 0 && $logPercentFilter > $logPercent) { print "||Didn't detect match in log percentage: $logPercent"; return; } elsif ($logPercentFilter != 0 && $logPercentFilter <= $logPercent) { print "||Detected match in log percentage: $logPercent"; } } if ($cueFilter && $format eq "FLAC" && !$cue) { print "||Didn't detect match in cue: cue not present"; return; } elsif($cueFilter && $cue) { print "||Detected match in cue: cue present"; } if ($sceneFilter && !$scene) { print "||Didn't detect match in scene: $scene"; return; } elsif($sceneFilter && $scene) { print "||Detected match in scene: $scene"; } if(@tagFilter) { foreach my $filter1(@tagFilter) { foreach my $filter2(@tags) { if(lc($filter2) eq lc($filter1)) { print "||Detected match in tags: @tags"; $downloaded++; my $t = threads->new(\&downloadWHAT, 1, $downloadID, $torrentDir); $t->detach(); return; } } } print "||Didn't detect match in tags: @tags"; print "-------------------------------------"; return; } else { print "||Tag filter not defined: @tags"; $downloaded++; my $t = threads->new(\&downloadWHAT, 1, $downloadID, $torrentDir); $t->detach(); } } } #if the message matches the known e-book and software release string, break message into component parts for comparison. elsif($text =~ m!(.+) - http://what\.cd/torrents\.php\?id=([0-9]+) / http://what\.cd/torrents\.php\?action=download&id=([0-9]+) - (.+)!) { $seen++; #Don't download if the ebook filter isn't activated if(!$activateEbook) { return; } my ($title, $torrentID, $downloadID, @tags) = ($1, $2, $3, split /, /, $4); print "Detected e-book/software announce: $title - @tags"; if(filter("title", $title, @ebookTitleFilter)) { if(@ebookTagFilter) { foreach my $filter1(@ebookTagFilter) { foreach my $filter2(@tags) { if($filter2 eq $filter1) { print "||Detected match in tags: @tags"; $downloaded++; my $t = threads->new(\&downloadWHAT, 1, $downloadID, $torrentDir); $t->detach(); return; } } } print "||Didn't detect match in tags: @tags"; print "-------------------------------------"; } else { print "||Tag filter not defined: @tags"; $downloaded++; my $t = threads->new(\&downloadWHAT, 1, $downloadID, $torrentDir); $t->detach(); print "-------------------------------------"; } } } } ##################### #IRC LISTEN COMMANDS# ##################### else { #If private message, $target contains our nick, so we #change $target to $nick in order to reply via PM if (!$data->ischannel($target)) { $target = $nick; } #Decide the authorization required whether message is through channel or PM if( (chanPass($target,@chanFilter) && nickPass($address, @nickFilter) ) || ($target eq $nick && nickPass($address, @nickFilter)) ) { ##################### ##DOWNLOAD COMMANDS## ##################### if($text =~ /^%download (.*)/i) { #################### #%download WAFFLES command if($1 =~ /^WAFFLES ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from Waffles.fm now"); downloadWAFFLES($1, $torrentDir, $data, $target); } } #################### #%download STMUSIC command elsif($1 =~ /^STMUSIC ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from STMusic now"); downloadSTMUSIC($1, $torrentDir, $data, $target); } } #################### #%download SCT command elsif($1 =~ /^SCT ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from SCT now"); downloadSCT($1, $torrentDir, $data, $target); } } #################### #%download SCC command elsif($1 =~ /^SCC ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from SCC now"); downloadSCC($1, $torrentDir, $data, $target); } } #################### #%download WHAT command elsif($1 =~ /^WHAT ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from What.cd now"); downloadWHAT(0, $1, $torrentDir, $data, $target); } } #################### #%download Hdbits command elsif($1 =~ /^HDBITS ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from HDbits now"); downloadHDbits($1, $torrentDir, $data, $target); } } #################### #%download x264 command elsif($1 =~ /^X264 ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from x264 now"); downloadx264($1, $torrentDir, $data, $target); } } #################### #%download RevTT command elsif($1 =~ /^REVTT ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from RevTT now"); downloadRevTT($1, $torrentDir, $data, $target); } } #################### #%download Goem command elsif($1 =~ /^GOEM ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from Goem now"); downloadGoem($1, $torrentDir, $data, $target); } } #################### #%download SDbits command elsif($1 =~ /^SDBITS ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from SDbits now"); downloadSDbits($1, $torrentDir, $data, $target); } } #################### #%download TC command elsif($1 =~ /^TC ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from TC now"); downloadTC($1, $torrentDir, $data, $target); } } #################### #%download Libble command elsif($1 =~ /^LIBBLE ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from Libble now"); downloadLibble( $1, $torrentDir, $data, $target); } } #################### #%download Libble command elsif($1 =~ /^BITHDTV ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from Bit-HDTV now"); downloadBitHDTV($1, $torrentDir, $data, $target); } } #################### #%download TD command elsif($1 =~ /^TD ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from TD now"); downloadTD($1, $torrentDir, $data, $target); } } #################### #%download PTN command elsif($1 =~ /^PTN ([0-9]+)/i) { if($1 > 1000000000) { $data->command("msg $target Trying to crash me now, eh?") } else { $data->command("msg $target Downloading $1 from PTN now"); downloadPTN($1, $torrentDir, $data, $target); } } else { $data->command("msg $target Download Syntax: %download "); $data->command("msg $target ex. %download WAFFLES 103856"); } } ##################### ###GENERALCOMMANDS### ##################### #%stats command elsif($text =~ /^%stats/i) { $data->command("msg $target I have seen $seen announces and downloaded $downloaded announces matching search criteria"); } #################### #%time command elsif($text =~ /^%time/i) { my $time = showTime(); $data->command("msg $target *Current System Time: $time"); } #################### #%current command elsif($text =~ /^%current/i) { $data->command("msg $target *Current Configuration:--------------"); $data->command("msg $target ---Music---"); $data->command("msg $target ||Music Activated: $activateMusic"); $data->command("msg $target ||Artist Filter: @artistFilter"); $data->command("msg $target ||Tag Filter: @tagFilter"); $data->command("msg $target ||Format Filter: @formatFilter"); $data->command("msg $target ||Quality Filter: @qualityFilter"); $data->command("msg $target ||Source Filter: @sourceFilter"); $data->command("msg $target ||Year Filter: @yearFilter"); $data->command("msg $target ||Scene Filter: $sceneFilter | FLAC log Filter: $logFilter | FLAC percent Filter: $logPercentFilter | CUE Filter: $cueFilter"); $data->command("msg $target ---Ebook/Software/Comics---"); $data->command("msg $target ||Ebook Activated: $activateEbook"); $data->command("msg $target ||Title Filter: @ebookTitleFilter"); $data->command("msg $target ||Tag Filter: @ebookTagFilter"); $data->command("msg $target -------------------------------------"); } #################### #%free command elsif($text =~ /^%free/i) { my ($avail, $free) = showFree(); $data->command("msg $target **Free Space on $drive: $avail GB ($free %)"); } #################### #%version command elsif($text =~ /^%version/i) { $data->command("msg $target WHATauto - version $VERSION by mlapaglia & gravey"); } #################### #%help command elsif($text =~ /^%help/i) { $data->command("msg $target WHATauto - a Multi-purpose IRSSI download script"); $data->command("msg $target %filter help | %admin help | %download help"); $data->command("msg $target Other commands: %stats %current %time %free %join %part"); } #################### #%join command elsif($text =~ /^%join #(.*)/i) { if (isOwner($address)) { $data->command("JOIN #$1"); } } #################### #%part command elsif($text =~ /^%part #(.*)/i) { if (isOwner($address)) { $data->command("PART #$1"); } } ##################### ###FILTER COMMANDS### ##################### elsif($text =~ /%filter (.*)/i && nickPass($address, @nickFilter)) { if($1 =~ /^add (.*)/i) { if($1 =~ /^artist (.*)/i) { push(@artistFilter, $1); $data->command( "msg $target added $1 to artists"); } elsif($1 =~ /^tag (.*)/i) { push(@tagFilter, $1); $data->command( "msg $target added $1 to tags"); } elsif($1 =~ /^format (.*)/i) { push(@formatFilter, $1); $data->command( "msg $target added $1 to formats"); } elsif($1 =~ /^quality (.*)/i) { push(@qualityFilter, $1); $data->command( "msg $target added $1 to qualities"); } elsif($1 =~ /^source (.*)/i) { push(@sourceFilter, $1); $data->command( "msg $target added $1 to sources"); } elsif($1 =~ /^year ([0-9]+)/i) { push(@yearFilter, $1); $data->command( "msg $target added $1 to years"); } elsif($1 =~ /^scene/i) { $sceneFilter = 1; $data->command( "msg $target toggled scene to $1"); } elsif($1 =~ /^log/i) { $logFilter = 1; $data->command( "msg $target toggled log to $1"); } elsif($1 =~ /^logpercent/i) { $logPercentFilter = 1; $data->command( "msg $target toggled log percent to $1"); } elsif($1 =~ /^cue/i) { $cueFilter = 1; $data->command( "msg $target toggled cue to $1"); } else { $data->command( "msg $target FAIL! Try %filter help"); } } elsif($1 =~ /del (.*)/i) { my $count = 0; if($1 =~ /^artist (.*)/i) { foreach(@artistFilter) { if($_ eq $1) { splice(@artistFilter,$count); $data->command( "msg $target removed $1 from artists"); return; } $count++; } } elsif($1 =~ /^tag (.*)/i) { foreach(@tagFilter) { if($_ eq $1) { splice(@tagFilter,$count); $data->command( "msg $target removed $1 from tags"); return; } $count++; } } elsif($1 =~ /^format (.*)/i) { foreach(@formatFilter) { if($_ eq $1) { splice(@formatFilter,$count); $data->command( "msg $target removed $1 from formats"); return; } $count++; } } elsif($1 =~ /^quality (.*)/i) { foreach(@qualityFilter) { if($_ eq $1) { splice(@qualityFilter,$count); $data->command( "msg $target removed $1 from qualities"); return; } $count++; } } elsif($1 =~ /^source (.*)/i) { foreach(@sourceFilter) { if($_ eq $1) { splice(@sourceFilter,$count); $data->command( "msg $target removed $1 from sources"); return; } $count++; } } elsif($1 =~ /^year ([0-9]+)/i) { foreach(@yearFilter) { if($_ eq $1) { splice(@yearFilter,$count); $data->command( "msg $target removed $1 years"); return; } $count++; } } elsif($1 =~ /^scene/i) { $sceneFilter = 0; } elsif($1 =~ /^log/i) { $logFilter = 0; } elsif($1 =~ /^logpercent/i) { $logPercentFilter = 0; } elsif($1 =~ /^cue/i) { $cueFilter = 0; } else { $data->command( "msg $target FAIL! Try %filter help"); } } else { $data->command("msg $target Filter Syntax: %filter [add|del] [artist|tag|format|quality|source|year] [filter]"); } } ##################### ####ADMIN COMMANDS### ##################### elsif($text =~ /^%admin (.*)/i && nickPass($address, @nickFilter)) { my $count = 0; if($1 =~ /^print/i) { $data->command("msg $target Users with authorization: @nickFilter"); $data->command("msg $target Users with admin authorization: @adminNickFilter"); } elsif($1 =~ /^add (.*)/i) { push(@nickFilter, $1); $data->command("msg $target successfully added $1 to auth list"); } elsif($1 =~ /^del (.*)/i) { foreach(@nickFilter) { if($_ eq $1) { splice(@nickFilter, $count, 0); last; } $count++; } $data->command("msg $target successfully removed $1 from auth list"); } elsif($1 =~ /^adminAdd (.*)/i) { push(@adminNickFilter, $1); $data->command("msg $target successfully added $1 to admin auth list"); } elsif($1 =~ /^adminDel (.*)/i) { foreach(@adminNickFilter) { if($_ eq $1) { splice(@adminNickFilter, $count, 0); last; } $count++; } $data->command("msg $target successfully removed $1 from admin auth list"); } elsif($1 =~ /^watchDir (.*)/i) { $torrentDir = $1; $data->command("msg $target successfully changed watch folder to: $1"); } elsif($1 =~ /^musicToggle ([0-1])/i) { $activateMusic = $1; $data->command("msg $target music auto-downloading set to: $1"); } elsif($1 =~ /^ebookToggle ([0-1])/i) { $activateEbook = $1; $data->command("msg $target ebook/software auto-downloading set to: $1"); } else { $data->command("msg $target Filter Syntax: %admin [adminAdd|adminDel|add|del|watchDir|musicToggle|ebookToggle] [username|foldername|0|1]"); } } } } } ############### #Checks for channel authorization sub chanPass { my ($test, @filter) = @_; foreach (@filter) { if ($test eq $_) { return 1; } } return 0; } ############### #Checks for user address authorization sub nickPass { my ($address, @filter) = @_; foreach (@nickOwner) { if ($address eq $_) { return 1; } } foreach (@filter) { if ($address eq $_) { return 1; } } return 0; } ############### #Returns the current date and time properly formatted. sub showTime { my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(); my $year = 1900 + $yearOffset; my $theTime = "$hour:$minute:$second, $weekDays[$dayOfWeek] $months[$month] $dayOfMonth, $year"; return $theTime; } ############### #Returns the amount and percentage of disk space remaining sub showFree { my ($fs_type, $fs_desc, $used, $avail, $fused, $favail) = df "$drive"; my $free = sprintf("%.2f",$avail / ($avail+$used) * 100); $avail = sprintf("%.2f",$avail / 1024000); return($avail, $free); } ############### #Warns about low disk space via text message sub checkSpace { my ($avail, $free) = showFree(); if ($free < $freePercent) { print "***Server space at $free%***"; return 0; } else { return 1; } } ############### #Loop through each filter, looking for the given item. If #item is found, return true. If not, return false. sub filter { my ($name, $item, @filter) = @_; #if there is no filter present, skip if (!@filter) { print "||No Filter for $name, skipping."; return 1; } foreach (@filter) { if( $_ eq $item) { print "||Detected match in $name: $_"; return 1; } } print "||Didn't detect match in $name: $item"; print "-------------------------------------"; return 0; } ############### #automatically leaves channel if it's an official channel (no bots allowed) sub chanBlock { my ($channel, $server) = @_; my @chanBlocks = ("#what.cd", "#what.cd-help", "#pu+", "#tm+", "#elite"); foreach (@chanBlocks) { if ($_ eq $channel) { Irssi::print("*** WARNING: Bots are not allowed in $channel. Now leaving..."); $server->command("PART $channel"); } } } ############### #Checks for user address authorization sub isOwner { my ($address) = @_; foreach (@nickOwner) { if ($address eq $_) { return 1; } } return 0; } ############### #Download subroutine for What.cd #Credits to pssimon for this subroutine. sub downloadWHAT { my ($isAuto, $downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new( autocheck => 1 ); #login to site $mech->get("http://what.cd/login.php"); $mech->submit_form( form_number => 0, fields => { username => "$usernameWHAT", password => "$passwordWHAT", } ); my $answer = 1; #actual download command my $response = $mech->get("http://what.cd/torrents.php?action=download&id=$downloadID"); if( my $disposition = $response->{_headers}->{"content-disposition" } ) { $disposition =~ /filename="(.*)"$/; if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } else { #wait 8 seconds for tracker to register torrent before it gets added if($isAuto) { sleep 8; } $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { $server->command( "msg $target **$downloadID does not exist on What.cd**." ); print "**$1 download FAILED**"; print "-------------------------------------"; $answer = 0; } #logout of site $mech->get("http://what.cd/"); $mech->follow_link(url_regex => qr/logout\.php/); return $answer; } ############### #Download subroutine for WAFFLES sub downloadWAFFLES { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://www.waffles.fm/w/index.php?title=Special:UserLogin&returnto=Main_Page"); $mech->submit_form( form_number => 0,fields => { 'wpName' => "$usernameWAFFLES", 'wpPassword' => "$passwordWAFFLES", } ); #actual download command my $answer = 1; $mech->get("https://www.waffles.fm/details.php?id=$downloadID"); print Dumper $mech; if(my $link = $mech->find_link(url_regex => qr/(download\.php.+uid=[0-9]+)/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on Waffles.fm**." ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("https://www.waffles.fm/logout.php"); return $answer; } ############### #Download subroutine for STMUSIC sub downloadSTMUSIC { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://www.stmusic.org/login.php"); $mech->submit_form( form_number => 0, fields => { username => "$usernameSTMUSIC", password => "$passwordSTMUSIC", } ); my $answer = 1; $mech->get("http://www.stmusic.org/details.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php\/[0-9]+\/(.*?torrent)/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on STMusic**." ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("http://www.stmusic.org/logout.php"); return $answer; } ############### #Download subroutine for ScT sub downloadSCT { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://www.scenetorrents.org/login.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernameSCT", password => "$passwordSCT", } ); #actual download command my $answer = 1; $mech->get("https://www.scenetorrents.org/details.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php(.+)=([a-z0-9]+)/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on SCT**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("https://scenetorrents.org/logout.php"); return $answer; } ############### #Download subroutine for SCC sub downloadSCC { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://www.sceneaccess.org/login.php"); $mech->submit_form( form_number => 0, fields => { username => "$usernameSCC", password => "$passwordSCC", } ); #actual download command my $answer = 1; $mech->get("https://www.sceneaccess.org/details.php?id=$downloadID"); $mech->dump_forms(); $mech->dump_links(); if(my $link = $mech->find_link(url_regex => qr/download(big)?2\.php.*?torrent/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on SCC**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("https://sceneaccess.org/logout.php"); return $answer; } ############### #Download subroutine for HDbits sub downloadHDbits { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://hdbits.org/login.php"); $mech->submit_form( form_number => 0, fields => { uname => "$usernameHDbits", password => "$passwordHDbits", } ); #actual download command my $answer = 1; $mech->get("https://hdbits.org/details.php\?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download.php\?id=[0-9]+/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on HDbits**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("https://hdbits.org/logout.php"); return $answer; } ############### #Download subroutine for x264 sub downloadx264 { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://x264.me/"); $mech->submit_form( form_number => 0, fields => {username => "$usernamex264", password => "$passwordx264", } ); my $answer = 1; $mech->get("http://x264.me/details.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php\/[1-9]+\/(.*?torrent)/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on x264**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("http://x264.me/logout.php"); return $answer; } ############### #Download subroutine for RevTT sub downloadRevTT { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://www.revolutiontt.net/login.php"); $mech->submit_form( form_number => 0, fields => { username => "$usernameRevTT", password => "$passwordRevTT", } ); my $answer = 1; $mech->get("https://www.revolutiontt.net/details.php?id=$downloadID"); $mech->dump_forms(); if(my $link = $mech->find_link(url_regex => qr/download\.php\/[0-9]+\/.*passkey=[0-9a-z]+/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on RevTT**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("https://www.revolutiontt.net/logout.php"); return $answer; } ############### #Download subroutine for goem sub downloadGoem { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://goem.org/login.php"); $mech->dump_forms(); $mech->submit_form( form_number => 0, fields => {username => "$usernameGoem", password => "$passwordGoem", } ); my $answer = 1; $mech->get("http://goem.org/details.php?id=$downloadID"); if (my $link = $mech->find_link(url_regex => qr/download\.php\/[1-9]+\/(.*?torrent)/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on Goem**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("http://goem.org/logout.php"); return $answer; } ############### #Download subroutine for SDbits sub downloadSDbits { my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://www.sdbits.org/login.php"); $mech->submit_form( form_number => 0, fields => {uname => "$usernameSDbits", password => "$passwordSDbits",}); my $answer = 1; $mech->get("http://sdbits.org/details.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php.*?torrent/)) { $mech->get($link); my $name = $link->text(); if(-e "$torrentDir/$name") { if(-e "$torrentDir/$name") { if($server) { $server->command( "msg $target **$name already exists."); } } } else { $mech->save_content("$torrentDir/$name"); if($server) { $server->command( "msg $target **$name downloaded successfully." ); } print "**$name downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on SDbits**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("http://www.sdbits.org/logout.php"); return $answer; } ############### #Download subroutine for TC sub downloadTC{ my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("https://tehconnection.eu/login.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernameTC", password => "$passwordTC", } ); my $answer = 1; #actual download command my $response = $mech->get("https://tehconnection.eu/torrents.php?action=download&id=$downloadID"); my $disposition = $response->{_headers}->{"content-disposition"}; if($disposition =~ /^attachment; Filename="(.*)"$/) { if(-e "$torrentDir/$1") { if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } } else { $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { $server->command( "msg $target **$downloadID does not exist on TC**." ); print "**$1 download FAILED**"; print "-------------------------------------"; $answer = 0; } #logout of site $mech->get("https://tehconnection.eu/"); $mech->follow_link(url_regex => qr/logout\.php/); return $answer; } ############### #Download subroutine for Libble sub downloadLibble{ my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://libble.com/login.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernameLibble" ,password => "$passwordLibble", } ); my $answer = 1; #actual download command my $response = $mech->get("http://libble.com/torrents.php?action=download&id=$downloadID"); my $disposition = $response->{_headers}->{"content-disposition"}; if($disposition =~ /^attachment; Filename="(.*)"$/) { if(-e "$torrentDir/$1") { if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } } else { $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { $server->command( "msg $target **$downloadID does not exist on Libble**." ); print "**$1 download FAILED**"; print "-------------------------------------"; $answer = 0; } #logout of site $mech->get("http://libble.com/"); $mech->follow_link(url_regex => qr/logout\.php/); return $answer; } ############### #Download subroutine for Bit-HDTV sub downloadBitHDTV{ my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://www.bit-hdtv.com/login.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernameBitHDTV", password => "$passwordBitHDTV", } ); my $answer = 1; $mech->get("http://www.bit-hdtv.com/details.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php\/[0-9]+\/.*?torrent/)) { #bithdtv doesn't perform content-disposition correctly, grab unicode name from filename instead $mech->get($link); $link->url() =~ qr/download\.php\/[0-9]+\/(.*?torrent)/; if(-e "$torrentDir/$1") { if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } } else { $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on Bit-HDTV**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site (no auth key to grab) $mech->get("http://www.bit-hdtv.com/logout.php"); return $answer; } ############### #Download subroutine for TD sub downloadTD{ my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://www.torrent-damage.net/login.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernameTD", password => "$passwordTD", } ); my $answer = 1; $mech->get("http://www.torrent-damage.net/torrents.php?action=download&id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download\.php\/[0-9]+\/.*?torrent/)) { $mech->get($link); $link->url =~ /download\.php\/[0-9]+\/(.*?torrent)/; if(-e "$torrentDir/$1") { if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } } else { $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on TD**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } #logging out of site $mech->get("http://www.torrent-damage.net/"); $mech->follow_link(url_regex => qr/logout\.php/); return $answer; } ############### #Download subroutine for PTN sub downloadPTN{ my ($downloadID, $torrentDir, $server, $target) = @_; my $mech = WWW::Mechanize->new (autocheck => 1); #login to site $mech->get("http://www.piratethe.net/login10.php"); $mech->submit_form( form_number => 0, fields => {username => "$usernamePTN", password => "$passwordPTN", } ); my $answer = 1; $mech->get("http://www.piratethe.net/detailsost.php?id=$downloadID"); if(my $link = $mech->find_link(url_regex => qr/download.php\/[0-9]+\/(.*torrent)/)) { $mech->get($link); $link->url =~ qr/download.php\/[0-9]+\/(.*torrent)/; if(-e "$torrentDir/$1") { if(-e "$torrentDir/$1") { if($server) { $server->command( "msg $target **$1 already exists."); } } } else { $mech->save_content("$torrentDir/$1"); if($server) { $server->command( "msg $target **$1 downloaded successfully." ); } print "**$1 downloaded successfully."; print "-------------------------------------"; } } else { if($server) { $server->command( "msg $target **$downloadID does not exist on PTN**" ); } print "**$downloadID download FAILED**"; print "-------------------------------------"; $answer = 0; } $mech->get("http://www.piratethe.net/logout.php"); } Irssi::signal_add_first("event connected", "event_connected"); Irssi::signal_add("message invite", "message_invite"); Irssi::signal_add("channel joined", "channel_joined"); Irssi::signal_add("event privmsg", "event_privmsg");