In desperate need for a small but customizeable RSS feed parser (deluge FlexRSS doesnt work for me), I took the perl script from the tvrss 1.8 beta and made some changes. You can get the tar ball here: tvrss-1.8beta-hacked.tar.gz.

The script doesnt work with the current feeds from tvrss anymore, I think this is because the script checks TV Show names/regexes against the URL, but the RSS feed doesnt contain them anymore. Instead, most of the feed lines contain a nice description tag at the beginning, so I made some changes, allowing to match against such a format:


<link>http://www.website.local/get/me/that/torrent</link>
<pubDate>Sun, 01 Jan 2009 23:55:23 -0800</pubDate>
<description>Show Name: This is a show name; Show Title: n/a; Season: 3; Episode: 15</description>
<enclosureurl="http://www.website.loacl/get/me/that/torrent" length="0"type="application/x-bittorrent" /></item>
<item><title>SHOW NAME 3x15 [720P - HDTV -RELEASEGROUP]</title>

The GUI now gives a hint for every line about what it thinks ("Hit": Show fetched from this line, "Miss": Line ignored because already fetched, or empty when the regex didnt match).

In addition, I changed the path where the script stores all information/files from ~/ to ~/tvrss (personal preference).

Furthermore, the script now logs all console output to the file ~/tvrss/tvrss_log.


$ diff -u tvrss.orig tvrss
--- tvrss.orig	2005-09-26 04:41:37.000000000 +0200
+++ tvrss	2009-01-12 15:57:32.000000000 +0100
@@ -8,18 +8,18 @@
 use XML::RAI;
 
 if ($ARGV[0] =~ /\-clearoptions/) {
-    if (`ls ~/.tvrss 2>&1` =~ /No such file or directory/) {
+    if (`ls ~/tvrss/.tvrss 2>&1` =~ /No such file or directory/) {
 	printf "No options to clear.\n";
 	exit;
     }
     $checkforwipe = `which wipe 2>&1`;
-    if ($checkforwipe =~ /\/.*\/wipe/) {
-	`cd $ENV{'HOME'} && wipe -s .tvrss`;
+    if ($checkforwipe =~ /\/tvrss\/.*\/wipe/) {
+	`cd $ENV{'HOME'}/tvrss && wipe -s .tvrss`;
 	printf "Options cleared.\n";
 	exit;
     } else {
-	`rm -f ~/.tvrss`;
-	`rm -f ~/.tvrssurl`;
+	`rm -f ~/tvrss/.tvrss`;
+	`rm -f ~/tvrss/.tvrssurl`;
 	printf "Options cleared.\n";
 	exit;
     }
@@ -79,8 +79,10 @@
 $console = Gtk2::TextView->new_with_buffer($console_buf);
 $console->set(editable => 0);
 $console->set_cursor_visible(0);
+# some changes to get a status indicator for downloaded/missed items
 $list = Gtk2::SimpleList->new('Title'    => 'text',
-			      'Released' => 'text',
+			      'Release Name' => 'text',
+			      'State' => 'text',
 			      'URL'      => 'text');
 $scroll = Gtk2::ScrolledWindow->new;
 $scroll->set_policy(qw/automatic automatic/);
@@ -135,6 +137,8 @@
 			    } else {
 				$filename =  $urlshift;
 				$filename =~ s/.+\/+//g;
+				# deluge somehow needs the .torrent extension
+				$filename = $filename . ".torrent";
 				$downloadtorrent = `wget --user-agent=TV_RSS_$version -nv -O $dir/$filename $urlshift 2>&1`;
 				if ($downloadtorrent =~ /\[1\]/) {  
 				    system("$client $dir/$filename >/dev/null 2>&1 &");
@@ -177,13 +181,13 @@
     $torrent =~ s/\.$//g;
     downloadtorrent($selected,0);
     $dupe = 0;
-    open(DLED,"<$ENV{'HOME'}/.tvrss_dled");
+    open(DLED,"<$ENV{'HOME'}/tvrss/.tvrss_dled");
     while () {
 	if ($_ =~ /$torrent/) { $dupe = 1; }
     }
     close(DLED);
     if ($dupe != 1) {
-	open(DLED,">>$ENV{'HOME'}/.tvrss_dled");
+	open(DLED,">>$ENV{'HOME'}/tvrss/.tvrss_dled");
 	print DLED $torrent . "\n";
 	close(DLED);
     }
@@ -344,7 +348,7 @@
 	shift;
 	$response = shift;
 	if ($response eq 'ok') {
-	    open(OPTIONS,">$ENV{'HOME'}/.tvrss") or die "Can't save options";
+	    open(OPTIONS,">$ENV{'HOME'}/tvrss/.tvrss") or die "Can't save options";
 	    $regexpsdump = Dumper($list2->{data});
 	    $regexpsdump =~ s/\s+//g;
 	    $regexpsdump =~ s/.+=//g;
@@ -404,7 +408,7 @@
     $clearhistory = Gtk2::Button->new('_Clear History');
     @{$list3->{data}} = ();
     @itemslist3 = ();
-    open(OPTIONS,"<$ENV{'HOME'}/.tvrss_dled");
+    open(OPTIONS,"<$ENV{'HOME'}/tvrss/.tvrss_dled");
     while () {
 	$item3 = $_;
 	chop($item3);
@@ -417,12 +421,12 @@
     $hbox->pack_start($vbox, 1, 1, 0);
     $dled->vbox->pack_start($hbox, 1, 1, 0);
     $clearhistory->signal_connect(clicked => sub {
-	console_text("Cleared history file $ENV{'HOME'}/.tvrss_dled\n");
+	console_text("Cleared history file $ENV{'HOME'}/tvrss/.tvrss_dled\n");
 	$checkforwipe = `which wipe 2>&1`;
-	if ($checkforwipe =~ /\/.*\/wipe/) {
-	    `cd $ENV{'HOME'} && wipe -s .tvrss_dled`;
+	if ($checkforwipe =~ /\/tvrss\/.*\/wipe/) {
+	    `cd $ENV{'HOME'}/tvrss && wipe -s .tvrss_dled`;
 	} else {
-	    `rm -f ~/.tvrss_dled`;
+	    `rm -f ~/tvrss/.tvrss_dled`;
 	}
 	@{$list3->{data}} = ();
     });
@@ -604,44 +608,67 @@
 	foreach $url(@rss_url_list)
 	{
 	if ($url !~ /^$/) {
-	    $xml = `rm -f ~/.tvrss_xml && wget --user-agent=TV_RSS_$version -nv -O ~/.tvrss_xml $url 2>&1`;
+	    $xml = `rm -f ~/tvrss/.tvrss_xml && wget --user-agent=TV_RSS_$version -nv -O ~/tvrss/.tvrss_xml $url 2>&1`;
 	    if ($xml =~ /\[1\]/) {
-		$feed = XML::RAI->parsefile("$ENV{'HOME'}/.tvrss_xml");
+		$feed = XML::RAI->parsefile("$ENV{'HOME'}/tvrss/.tvrss_xml");
 		$count = $feed->item_count();
 		console_text("RSS feed loaded $count item(s)\n");
 		foreach $item ( @{$feed->items} ) {
-		    $title = $item->title;
+
+		    # skip if line doesnt contain any 
+		    next if !($item->description);
+		    # we work with plain episode names, but we keep the release title name for the display
+		    $rel_title = $item->title;
 		    $issued = $item->issued;
 		    $link = $item->link;
-		    @itemslist = ( @itemslist, [ $title, $issued, $link ], );
+
+		    # retrieve the description, then extract Name, Season and Episode
+		    my %desc = split(/[:;]/, $item->description);
+		    my $title = $desc{"Show Name"};
+		    $title =~ s/(^\s+)|(\s+$)//;
+		    my $season = $desc{" Season"};
+		    $season =~ s/(^\s+)|(\s+$)//;
+		    my $episode = $desc{" Episode"};
+		    $episode =~ s/(^\s+)|(\s+$)//;
+
+		    # variable to get display feedback whether we already fetched that show
+		    my $state = "";
+
+		    # skip if item doesnt provide any Season/Episode
+		    next if ($episode !~ m/[0-9]+/) || ($season !~ m/[0-9]+/);
+
+		    # the real title, sanitized - we use this format to check later for duplicated
+		    $title = "$title Season $season Episode $episode";
+
 		    if ($autodl !~ /^$/) {
 			if ($autodl == 1) {
 			    if ($regexps !~ /^$/) {
 				@regexp = split(",", $regexps);
 				for ($e = 0; $e < @regexp; $e++) {
-				    if ($link =~ /$regexp[$e]/xi) {
-					if ($link =~ /\.torrent/i) {
-					    $torrent = sprintf("%s",$link);
-					    $torrent =~ s/.+\/+//;
-					    $torrent =~ s/\[.+\]//g;
-					    $torrent =~ s/\.torrent//g;
-					    $torrent =~ s/\.$//g;
-					    open(DLED,"<$ENV{'HOME'}/.tvrss_dled");
+				    # we match on the title, not the url/link anymore
+				    if ($title =~ /$regexp[$e]/xi) {
+					    open(DLED,"<$ENV{'HOME'}/tvrss/.tvrss_dled");
 					    while () {
-						if ($_ =~ /$torrent/) { goto dled; }
+						if ($_ =~ /$title/) { 
+								$state = "Miss";
+								goto dled; 
+						}
 					    }
 					    close(DLED);
 					    downloadtorrent($link,1);
-					    open(DLED,">>$ENV{'HOME'}/.tvrss_dled");  
-					    print DLED $torrent . "\n";
+					    open(DLED,">>$ENV{'HOME'}/tvrss/.tvrss_dled");  
+					    print DLED $title . "\n";
+		    			    $state = "Hit";
+					    console_text("Torrent downloaded: $title from: $link\n");
 					    close(DLED);
 					  dled:
-					}
-				    }
+					} 
 				}
 			    }   
 			}
 		    }
+		
+		  @itemslist = ( @itemslist, [ $title, $rel_title, $state,  $link ], );
 		}
 		@{$list->{data}} = ( @itemslist );
 	    }
@@ -664,7 +691,7 @@
 
 sub load_options
 {
-    open(OPTIONS,"<$ENV{'HOME'}/.tvrss") or 0;
+    open(OPTIONS,"<$ENV{'HOME'}/tvrss/.tvrss") or 0;
     while () {
 	if ($_ =~ /dir=/) { ($null,$dir) = split(/=/); chop($dir); }
 	if ($_ =~ /url=/) { ($null,$url) = split(/=/); chop($url); }
@@ -679,7 +706,7 @@
     }
     close(OPTIONS);
     
-    open(URLOPTS,"<$ENV{ 'HOME' }/.tvrssurl") or 0;
+    open(URLOPTS,"<$ENV{ 'HOME' }/tvrss/.tvrssurl") or 0;
     @data_from_dump = ();
     @{$feedlist->{data}} = ();
     foreach $temporary ()
@@ -700,7 +727,7 @@
 
 sub window_options
 {
-    open(WINOPTIONS,"<$ENV{'HOME'}/.tvrss_win");
+    open(WINOPTIONS,"<$ENV{'HOME'}/tvrss/.tvrss_win");
     while () {
 	if ($_ =~ /size=/) {
 	    ($null,$size) = split(/=/);
@@ -730,11 +757,16 @@
 
 sub timestamp
 {
-    ($sec,$min,$hour) = localtime(time);
+    # for the log, provide date information also
+    ($sec,$min,$hour,$mday,$mon,$year) = localtime(time);
+    $year += 1900;
+    $mon += 1;
     if (length($min) == 1) { $min = "0" . $min; }
     if (length($hour) == 1) { $hour = "0" . $hour; }
     if (length($sec) == 1) { $sec = "0" . $sec; }
-    return "[" . $hour . ":" . $min . ":" . $sec . "]";
+    if (length($mon) == 1) { $sec = "0" . $sec; }
+    if (length($mday) == 1) { $sec = "0" . $sec; }
+    return "[" . $year . "-" . $mon . "-" . $mday . " " . $hour . ":" . $min . ":" . $sec . "]";
 }
 
 sub console_text
@@ -742,12 +774,18 @@
     $addto = shift;
     $existing = $console_buf->get_text($console_buf->get_start_iter, $console_buf->get_end_iter, 1);
     $console_buf->set_text($existing . timestamp() . " " . $addto);
+
+    # everything that goes to the console goes to a log file aswell
+    open (OUTPUT,">>$ENV{'HOME'}/tvrss/tvrss_log") || die "Cannot open log file"; 
+    print OUTPUT $existing . timestamp() . " " . $addto . "\n";    
+    close (OUTPUT);
+	
 }
 
 sub save_urltofile
 {
 
-	open(URLOPTS,">$ENV{ 'HOME' }/.tvrssurl") or die "Can't save the feeds";
+	open(URLOPTS,">$ENV{ 'HOME' }/tvrss/.tvrssurl") or die "Can't save the feeds";
 	
 	$array_row = scalar(@{$feedlist->{data}});
 	$array_col = 1;
@@ -762,7 +800,7 @@
 
 sub quit
 {
-    open(WINOPTIONS,">$ENV{'HOME'}/.tvrss_win");
+    open(WINOPTIONS,">$ENV{'HOME'}/tvrss/.tvrss_win");
     ($paned_pos) = $vpane->get_position;
     ($width,$height) = $tvrss->get_size;
     ($root_x,$root_y) = $tvrss->get_position;
@@ -776,7 +814,7 @@
     if (`ls ~/.tvrss_xml 2>&1` !~ /No such file or directory/) {
 	$checkforwipe = `which wipe 2>&1`;
 	if ($checkforwipe =~ /\/.*\/wipe/) {
-	    `cd $ENV{'HOME'} && wipe -s .tvrss_xml`;
+	    `cd $ENV{'HOME'}/tvrss && wipe -s .tvrss_xml`;
 	} else {
 	    `rm -f ~/.tvrss_xml`;
 	}



last updated: 13-Jan-2009