tfeserver: Blog de tfe

html, scripts et tout un tas de trucs...

Download

Contenu du fichier de /eztv_scripts/eztv_tpb.pl (télécharger eztv_tpb.pl)
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
use HTML::Entities;
use Date::Manip;
use URI::Escape;


Date_Init("TZ=EST");

my $browser = LWP::UserAgent->new;
$browser->timeout(30);
my $errors=0;

my $cache="/home/tfe/bin/shows.txt";
#my $cache="/home/tfe/bin/shows.txt";
my $file_path="/home/tfe/public_html/cache/eztv/";
#my $file_path="/home/tfe/bin/";
#my $url = 'http://thepiratebay.org/search/eztv%20%search_string%/0/99/0';
my $url = 'http://thepiratebay.org/search/eztv%20%search_string%/%page%/7/100,200,300,400,600/';
my %month = (
    'January'       => "01",
    'February'      => "02",
    'March'         => "03",
    'April'         => "04",
    'May'           => "05",
    'June'          => "06",
    'July'          => "07",
    'August'        => "08",
    'September'     => "09",
    'October'       => "10",
    'November'      => "11",
    'December'      => "12");
        

open(MYCACHE,">/home/tfe/bin/log");
print MYCACHE "\n\n";
print MYCACHE scalar localtime();
print MYCACHE "\n";

open(INFO,$cache);
while(<INFO>)
{
	chomp();
	my $name = $_;
	my $html="";
	my $xml="";
	my $content="";
	my $torr_name = $name;
	$torr_name =~s/\W+/_/g;

	if(!$name) { $name=""; }
	$html.= "<html>
		<head>
		<title>$name - alternative eztv RSS feed .</title>
		<link rel=\"stylesheet\" type=\"text/css\" href=\"/eztv.css\" />
		</head>
		<body>
		<div class=\"page\">
		<h1>Ezrss alt for $name<a href=\"/cgi-bin/eztv.pl?name=$name\"><img width=\"32\" height=\"32\" src=\"/images/rss.png\" alt=\"rss link\" /></a></h1>
		<ul>
		";


	$xml.= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
		<rss version=\"2.0\">
		<channel>
		<title>Dynamic rss from eztv.it search</title>
		<link>http://eztv.ptain.info</link>
		<ttl>30</ttl>
		<description>EZTV RSS feed for selected show/news</description>
		";

	for(my $page=0;$page<4;$page++)
	{
		print "PAGEEE $page\n";

		print MYCACHE "Id:  $name\n";
		print "ok fetch $name\n";

# Format, name, id




		my $response;
		print "Fetching  errors occured: $errors\n";

		if($errors<100)
		{
			my $url_link = $url;
			$url_link=~s/%search_string%/$name/;
			$url_link=~s/%page%/$page/;
			print MYCACHE "Fetching $url_link\n";
			$response = $browser->get ( $url_link);
		}
		if(!$response || !$response->is_success)
		{
			print "ERROR!\n";
			$errors++;
		}
		else
		{
			$content = $response->content;
		}


		if($content ne "")
		{
			my $last_added_on = "";
			my $last_added_on_html = "";
			while($content=~ /(<td.*?class="detName.*?<\/tr>)/sg)
			{
				my $torr_data = $1;
				my $link ="";
				my $title="";
				if($torr_data=~ /<a href="\/torrent\/\d+\/$torr_name.*?>(.*?)</i)
				{
					$title =$1;
				}
				if($torr_data=~ /<a href="(.*?)" title="Download this torrent"/)
				{
					$link=$1;
				}
				if($torr_data !~/user\/eztv/)
				{
					$link="";
				}
				if($title ne "")
				{
					print MYCACHE "TITLE $title / $link\n";
					print MYCACHE "DATA($torr_name) $torr_data\n\n";
					$link = uri_unescape($link);

					$html.= "<li>$title ( <a href=\"$link\">Torrent</a> )</li>\n";
					print MYCACHE "HTMLtemp $html\n";
					if($link =~ /^(.*)\/([^?]+)$/)
					{
						$link  = $1."/".uri_unescape($2);
					}

					$xml.= "<item>
						<title><![CDATA[$title]]></title>
						<pubDate>$last_added_on</pubDate>
						<link><![CDATA[$link]]></link>
						<description><![CDATA[$title - $link]]></description>
						</item>";
				}
			}
			$html.= "</ul></div><p><a href=\"/cgi-bin/eztv_list.pl\">Back to eztv rss feeds</a></p></body></html>\n";
			print MYCACHE "HTMLfinal $html\n";
			$xml.= "</channel></rss>\n";
		}
		else
		{
			print MYCACHE "Error fetching\n";
			flush MYCACHE;
		}
	}

	if($name !~ /\//)
	{
		open(WRITE,">$file_path$name.html");
		print WRITE $html;
		close(WRITE);
		open(WRITE,">$file_path$name.xml");
		print WRITE $xml;
		close(WRITE);

		print MYCACHE "Writing to $file_path$name\n";
		open(WRITE,">$file_path".lc($name).".html");
		print WRITE $html;
		close(WRITE);
		open(WRITE,">$file_path".lc($name).".xml");
		print WRITE $xml;
		close(WRITE);
	}

	print MYCACHE "Write $name : ".length($html)." y ".length($xml)."\n";
	flush MYCACHE;
}
close MYCACHE;