#!/usr/bin/perl # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. # # Written by motyR. # Based on an irssi script by engywook. # Irssi script to auto download TL torrents based on user filters. #use strict; use warnings; use vars qw($site $botname $channel $uid $passkey $watch_dir $script_version $script_name $use_notification @AoH $tl_category $tl_release $tl_uploader $tl_idm); $site = "http://www.torrentleech.org/"; $botname = "_AnnounceBot_"; $channel = "#torrentleech"; $script_version = "0.1"; $script_name = "TL_irssi"; $use_notification = 0; # for gnome notification set to 1 else leave 0 # The fallowing 3 configurations ($uid, $passkey, $watch_dir) must be set by the user, # the $uid and $passkey should be taken from the torrentleech cokie, with firefox you could watch the cookie data # by selecting: Edit -> Preferences -> Privacy -> Show Cookies and use "torrentleech" as the filter, # $uid equals uid and $passkey equals pass, a typical cookie data should look something like this: # Cookie: last_access=767687676566; lang=en; last_browse=1241470753; uid=12345; pass=123456789; bbuserid=12345; bbpassword=5765g76sg65fg9; langid=4 # the $watch_dir is where the torrents will be downloaded to. $uid = ""; # uid $passkey = ""; # pass $watch_dir = '/home/user/torrents/'; # don't forget the last / # This is the place you can filter the downloaded torrents, # any regex expression will do but if you are not into regex # keep the syntax as the fallowing examples. # few notes about the filters: # * Category can be any type of valid torrentleech category that can be seen on this page # http://www.torrentleech.org/browse.php. # * You can have more then one item per filter type with "|" being the delimiter character # as in category => "Movies/DVD-R|Movies/XviD|Movies/HD-x264". # * To completely ignore filter type leave it blank, so in the below example # if we're leaving the uploader blank it means that any uploader would match. # * All fiters values must be quoted with "". # * In regex ^ means the begining of a line, # so ^House would match "House" but not "Desperate Housewives ". @AoH = ( #{ #category => "Movies/XviD", #filter => "480", #except => "IPOD|nuke|1080|MP4|mpeg|DD5.1|ts", #codec => "", #uploader => "", #group => "D-Z0N3|PRoDJi" #}, #{ #category => "Movies/DVD-R|Movies/XviD|Movies/HD-x264", #filter => "", #except => "IPOD|nuke|1080|MP4|mpeg|DD5.1|ts", #codec => "x264", #uploader => "cspd|Ellinas", #group => "" #}, { category => "Episodes/TV", filter => "^Reggie.Perrin", except => "IPOD|nuke|1080|720p|MP4|mpeg|DD5.1|ts", codec => "XviD", uploader => "", group => "" } ); ################################################################################# # DO NOT EDIT BELOW THIS OR I SWEAR I WILL HUNT YOU DOWN WHERE EVER YOU ARE!!! :D ################################################################################# Irssi::print "Loading $script_name-$script_version Script"; Irssi::signal_add("message public", \&getdata); sub getdata { my $server, my $msg, my $nick, my $address, my $target; ($server,$msg,$nick,$address,$target) = @_; if ($target eq $channel && $nick eq $botname) { $msg =~ s/^\s+//; # Remove trailing whitespace $msg =~ s/\s+$//; $msg =~ /.*<(.*?)>\s\sName:'(.*?)'\suploaded by\s'(.*?)'.*id=(.*)?/; $tl_category = $1; $tl_release = $2; $tl_uploader = $3; $tl_idm = $4; match(); } } sub match { my $i; for $i ( 0 .. $#AoH ) { my $key; my $category=""; my $filter=""; my $except=""; my $uploader=""; my $group=""; my $codec=""; for $key ( keys %{ $AoH[$i] } ) { if ($key =~ /category/) { $category = $AoH[$i]{$key}; } elsif ($key =~ /filter/) { $filter = $AoH[$i]{$key}; } elsif ($key =~ /except/) { $except = $AoH[$i]{$key}; } elsif ($key =~ /uploader/) { $uploader = $AoH[$i]{$key}; } elsif ($key =~ /group/) { $group = $AoH[$i]{$key}; } elsif ($key =~ /codec/) { $codec = $AoH[$i]{$key}; } else { #unknown key, ignore it } } # skip null set if (!($category || $except || $uploader || $group || $filter || $codec)) { next; } # tl_category not match category if ($category) { if ($tl_category !~ qr/$category/i) { next; } } # tl_release match except if ($except) { if ($tl_release =~ qr/$except/i) { next; } } # tl_uploader not match uploader if ($uploader) { if ($tl_uploader !~ qr/$uploader/i) { next; } } # tl_release not match group if ($uploader) { if ($tl_release !~ qr/$group/i) { next; } } # tl_release not match filter if ($filter) { if ($tl_release !~ qr/$filter/i) { next; } } # $tl_release not match codec if ($codec) { if ($tl_release !~ qr/$codec/i) {next;} } download(); last; } } sub download { Irssi::print "##############################"; Irssi::print "----> DL: $tl_release [$tl_category]"; Irssi::print "##############################"; if ($use_notification) { system("notify-send \"DL: $tl_release [$tl_category]\" &"); } my $tl_release_dot = $tl_release; $tl_release_dot =~ s/\s+/./g; my $file = $watch_dir . "$tl_release_dot" . ".torrent"; $tl_release =~ s/\s+/%20/g; my $url = " -s -k -b'uid=$uid;pass=$passkey' -o $file $site" . "download.php/" . $tl_idm . "/" . $tl_release . ".torrent"; system("curl $url &"); }