I sent a patch to the maintainer but he
has not responded to me. So.. I've no idea if he just
hasn't seen it or it's not good.
Took me a while
to un-obfuscate it. (I'm a perl newbie who just
got a book and started
reading)
===================
PATCH==================
---
/tmp/rss-torrentflux0.9c.pl 2007-03-24
17:23:52.000000000 +0800
+++
rss-torrentflux0.9c.pl.mine 2007-03-24
17:27:48.000000000 +0800
@@ -25,7 +25,7
@@
use strict;
use vars
qw/$torrentflux_url $torrentflux_user
-
$torrentflux_password @rssfeeds @regexp
@seentorrents/;
+ $torrentflux_password
@rssfeeds @regexp $downloc @seentorrents/
;
##########################################################################
####################
Options you really should set
####################
@@ -51,6 +51,7
@@
#
'^24');
# Matches every Title beginning
with 24
@regexp = ();
+$downloc =
'~/tf_rss_dl/';
##########################################################################
#############
You shouldn't need to edit anything below here
#############
##########################################################################
@@
-68,6 +69,8 @@
'n|nostart'
=> \$nostart,
) and
!$help;
+# Enable this to view the coming/going
of LWP
+#use LWP::Debug qw(+);
use
LWP::Simple;
use XML::RSS;
use
WWW::Mechanize;
@@ -75,8 +78,12 @@
my $mech
= WWW::Mechanize->new();
my $rss = new
XML::RSS;
-my $response =
$mech->get($torrentflux_url);
-die
($response->status_line) unless
($response->is_success());
+sub connect_home()
{
+ my $response =
$mech->get($torrentflux_url);
+
die ($response->status_line) unless
($response->is_success());
+
}
+
+connect_home();
for
($mech->forms()) {
if
($_->attr('name') eq 'theForm') {
@@ -90,7 +97,7
@@
die ('Could possibly not login to
TorrentFlux!') unless
($mech->form_name('form_url'));
# Get
list of downloaded torrents
-if (open(TORRENTS,
'<', $ENV{HOME}.'/.seentorrents')) {
+if
(open(TORRENTS, '<', $downloc.'/.seentorrents'))
{
push(@seentorrents,$_)
while(<TORRENTS>);
chomp(@seentorrents);
close(TORRENTS);
@@ -107,8 +114,12 @@
ITEM: foreach my $item (@{$rss->{'items'}})
{
my $title =
$item->{'title'};
my
$url = $item->{'link'};
+
my $desc =
$item->{'description'};
my $filename = $url;
-
$filename =~ s!^.*/!!;
+
+#
print "title --> $title\n
url--> $url\n desc-->$desc\n
filename-->$filename\n\n";
+
+
$filename =~ s!^.*/!!;
for (@regexp) {
if ($title =~ /$_/i)
{
# Check if download has already started
@@
-116,13 +127,28 @@
next ITEM if
($filename eq $_);
}
print "Found new Match:
$title\n" if ($verbose);
-
# Add URL to Torrentflux
-
$mech->submit_form(form_name=>'form_url',
-
fields => {url_upload =>
$url,});
+
+
$title =~ s/ /_/g; #
Replace empty spaces with underscores
(Globally)
+
$title =~ s/\(/_/g; # Replace
open bracket with underscores (Globally)
+
$title =~ s/\)/_/g; # Replace closing bracket with
underscores (Globally)
+
$title =~
s/-/_/g; # Replace hypens with underscores
(Globally)
+
$title =~ s/__/_/g; # Replace
double hypens with underscores (Globally)
+
my $lfile = $downloc.$title.'.torrent';
+
my $status = getstore($url,$lfile);
+
if ($verbose) {
+
print("Successfully Downloaded
$title\n") if is_success($status);
+
}
+
+
# Add URL to Torrentflux
+
$mech->submit_form(form_name=>'form_file',
+
fields => {upload_file =>
$lfile,});
if ($mech->content() !~ /ERROR/)
{
# Start Download
if (!$nostart) {
-
my
$response =
$mech->get($torrentflux_url.'index.php?torrent='.$filename
);
+
my $response =
$mech->get($torrentflux_url.'startpop.php?torrent='.$title
.'.torrent');
+
$mech->submit();
+
#print
"$response->status_line\n";
+
#print
"$response->is_success()\n";
die ($response->status_line) unless
($response->is_success());
}
push(@seentorrents,
$filename);
@@ -130,12 +156,14 @@
} else
{
print " Failed to add torrent to
TorrentFlux. Will try again next time.\n" if
($verbose);
}
+
+
connect_home();
}
}
}
}
# Update
~/.seentorrents
-open(TORRENTS,
'>',$ENV{HOME}.'/.seentorrents') or die 'Could not
write to ~/.seentorrents';
+open(TORRENTS,
'>',$downloc.'/.seentorrents') or die "Could not
write to $downloc/.seentorrents
";
print TORRENTS
join("\n",@seentorrents);
close(TORRENTS);
===========
END PATCH===========
I've only tested it on
eztvefnet.org's RSS Feeds. So, not sure if it will work
at other places.
Oh yeah. the 5 lines of regex
can be collapsed into 1 line, but I'm lazy to go look
for that (other) patch I did. Majority of the regexes
are needed because when you upload to TF, the file gets
stripped of any offending '()' and "-" etc. So it gave
stumped me for a while on why it would successfully
upload into TF but fails to start it. (Cos the uploaded
name and the RSS's name are different!!)
Oh.. one
other thing, it doesn't remove the DL'ed files, you
might need to add code if you want to automatically
delete it after getting it into TF.
Report any
fixes and stuff.
Been working fine since Last
Sat.