Просмотр исходного кода

Add support for ET
Resolve issue with secondary URL fetching

Zachary Kotlarek 10 лет назад
Родитель
Сommit
168079cdad
1 измененных файлов с 108 добавлено и 15 удалено
  1. 108 15
      findTorrent.pl

+ 108 - 15
findTorrent.pl

@@ -15,7 +15,7 @@ my $TV_DIR = `~/bin/video/mediaPath` . '/TV';
 
 
 # Search parameters
 # Search parameters
 my $PROTOCOL = 'https';
 my $PROTOCOL = 'https';
-my %ENABLE_SOURCE = ('TPB' => 1, 'ISO' => 1, 'KICK' => 1, 'Z' => 0);
+my %ENABLE_SOURCE = ('TPB' => 1, 'ISO' => 1, 'KICK' => 0, 'Z' => 0, 'ET' => 1);
 
 
 # Selection parameters
 # Selection parameters
 my $MIN_COUNT        = 10;
 my $MIN_COUNT        = 10;
@@ -54,7 +54,7 @@ use Fetch;
 sub getHash($);
 sub getHash($);
 sub resolveSecondary($);
 sub resolveSecondary($);
 sub resolveTrackers($);
 sub resolveTrackers($);
-sub splitTags($$$);
+sub splitTags($$$$);
 sub findSE($);
 sub findSE($);
 sub initSources();
 sub initSources();
 sub findProxy($$);
 sub findProxy($$);
@@ -575,7 +575,7 @@ foreach my $content (@html_content) {
 	if ($content =~ /\<title\>The Pirate Bay/i) {
 	if ($content =~ /\<title\>The Pirate Bay/i) {
 
 
 		# Find TR elements from TPB
 		# Find TR elements from TPB
-		my @trs = splitTags($content, 'TR', 'TH');
+		my @trs = splitTags($content, 'TR', 'TH', undef());
 		foreach my $tr (@trs) {
 		foreach my $tr (@trs) {
 
 
 			# Find the show title
 			# Find the show title
@@ -645,7 +645,7 @@ foreach my $content (@html_content) {
 	} elsif ($content =~ /\<title\>[^\<\>]*\bisoHunt\b[^\<\>]*\<\/title\>/i) {
 	} elsif ($content =~ /\<title\>[^\<\>]*\bisoHunt\b[^\<\>]*\<\/title\>/i) {
 
 
 		# Find each TR element from ISOHunt
 		# Find each TR element from ISOHunt
-		my @trs = splitTags($content, 'TR', 'TH');
+		my @trs = splitTags($content, 'TR', 'TH', undef());
 		foreach my $tr (@trs) {
 		foreach my $tr (@trs) {
 
 
 			# Split each TD element from the row
 			# Split each TD element from the row
@@ -699,7 +699,7 @@ foreach my $content (@html_content) {
 				$leaches = $1;
 				$leaches = $1;
 			}
 			}
 
 
-			# Fetch the detail page for the URL
+			# Build the detail page URL
 			my $url = $SOURCES->{'ISO'}->{'protocol'} . '://' . $SOURCES->{'ISO'}->{'host'} . '/torrent_details/' . $id;
 			my $url = $SOURCES->{'ISO'}->{'protocol'} . '://' . $SOURCES->{'ISO'}->{'host'} . '/torrent_details/' . $id;
 
 
 			if ($DEBUG) {
 			if ($DEBUG) {
@@ -723,7 +723,7 @@ foreach my $content (@html_content) {
 	} elsif ($content =~ /Kickass\s*Torrents\<\/title\>/i) {
 	} elsif ($content =~ /Kickass\s*Torrents\<\/title\>/i) {
 
 
 		# Find each TR element from Kickass
 		# Find each TR element from Kickass
-		my @trs = splitTags($content, 'TR', 'TH');
+		my @trs = splitTags($content, 'TR', 'TH', undef());
 		foreach my $tr (@trs) {
 		foreach my $tr (@trs) {
 
 
 			# Split each TD element from the row
 			# Split each TD element from the row
@@ -813,7 +813,7 @@ foreach my $content (@html_content) {
 		my $hs = HTML::Strip->new();
 		my $hs = HTML::Strip->new();
 
 
 		# Find each DL element from Torrentz
 		# Find each DL element from Torrentz
-		my @dls = splitTags($content, 'DL', undef());
+		my @dls = splitTags($content, 'DL', undef(), undef());
 		foreach my $dl (@dls) {
 		foreach my $dl (@dls) {
 
 
 			# Skip ads
 			# Skip ads
@@ -879,6 +879,77 @@ foreach my $content (@html_content) {
 			push(@tors, \%tor);
 			push(@tors, \%tor);
 		}
 		}
 
 
+	} elsif ($content =~ /ExtraTorrent\.cc The World\'s Largest BitTorrent System\<\/title\>/i) {
+
+		# Find TR elements from ET
+		my @trs = splitTags($content, 'TR', undef(), '\/torrent\/');
+		foreach my $tr (@trs) {
+
+			# Find the show title
+			my ($title) = $tr =~ /title\=\"Download\s+([^\"]*)\s+torrent\"/i;
+			if (!defined($title) || length($title) < 1) {
+				if ($DEBUG) {
+					print STDERR "Unable to find show title in TR\n\t" . $tr . "\n";
+				}
+				next;
+			}
+			$title =~ s/^\s+//;
+
+			# Extract the season and episode numbers
+			my ($fileSeason, $episode) = findSE($title);
+
+			# Extract the ID
+			my ($id) = $tr =~ /\<a\s+href\=\"\/torrent\/(\d+)\/[^\"]*\"/i;
+			if (!defined($id) || length($id) < 1) {
+				if ($DEBUG) {
+					print STDERR "Skipping TR with no ID\n";
+				}
+				next;
+			}
+
+			# Count the sum of seeders and leachers
+			my $seeds   = 0;
+			my $leaches = 0;
+			if ($tr =~ /\<td\s+class=\"sy\">(\d+)\<\/td\>/) {
+				$seeds = $1;
+			}
+			if ($tr =~ /\<td\s+class=\"ly\">(\d+)\<\/td\>/) {
+				$leaches = $1;
+			}
+
+			# Extract the size (from separate column or inline)
+			my $size = 0;
+			my $unit = 'M';
+			if ($tr =~ /\<td\>(\d+(?:\.\d+)?)\&nbsp\;(G|M)B\<\/td\>/) {
+				$size = $1;
+				$unit = $2;
+			}
+			if ($unit eq 'G') {
+				$size *= 1024;
+			}
+			$size = int($size);
+
+			# Build the detail page URL
+			my $url = $SOURCES->{'ET'}->{'protocol'} . '://' . $SOURCES->{'ET'}->{'host'} . '/torrent/' . $id . '/';
+
+			if ($DEBUG) {
+				print STDERR 'Found file (' . $title . '): ' . $url . "\n";
+			}
+
+			# Save the extracted data
+			my %tor = (
+				'title'   => $title,
+				'season'  => $fileSeason,
+				'episode' => $episode,
+				'seeds'   => $seeds,
+				'leaches' => $leaches,
+				'size'    => $size,
+				'url'     => $url,
+				'source'  => 'ET'
+			);
+			push(@tors, \%tor);
+		}
+
 	} elsif ($content =~ /Database\s+maintenance/i) {
 	} elsif ($content =~ /Database\s+maintenance/i) {
 		if ($DEBUG) {
 		if ($DEBUG) {
 			print STDERR "Source down for maintenance\n";
 			print STDERR "Source down for maintenance\n";
@@ -1102,12 +1173,12 @@ foreach my $episode (keys(%tors)) {
 	my @sorted = sort { $b->{'adj_count'} <=> $a->{'adj_count'} } @{ $tors{$episode} };
 	my @sorted = sort { $b->{'adj_count'} <=> $a->{'adj_count'} } @{ $tors{$episode} };
 	my $max = undef();
 	my $max = undef();
 	foreach my $tor (@sorted) {
 	foreach my $tor (@sorted) {
-		if (!$tor->{'hash'} || $EXCLUDES{ $tor->{'hash'} }) {
-			print STDERR 'Double-skipping file: Excluded hash (' . $tor->{'hash'} . '): ' . $tor->{'title'} . "\n";
-			next;
-		}
 		if (!defined($max) || $tor->{'adj_count'} > $max) {
 		if (!defined($max) || $tor->{'adj_count'} > $max) {
 			if ($urls{$episode} = resolveSecondary($tor)) {
 			if ($urls{$episode} = resolveSecondary($tor)) {
+				if (!$tor->{'hash'} || $EXCLUDES{ $tor->{'hash'} }) {
+					print STDERR 'Double-skipping file: Excluded hash (' . $tor->{'hash'} . '): ' . $tor->{'title'} . "\n";
+					next;
+				}
 				$max = $tor->{'adj_count'};
 				$max = $tor->{'adj_count'};
 			}
 			}
 			if ($DEBUG) {
 			if ($DEBUG) {
@@ -1168,7 +1239,7 @@ sub resolveSecondary($) {
 	my ($tor) = @_;
 	my ($tor) = @_;
 
 
 	# Fetch the torrent-specific page and extract the magent link
 	# Fetch the torrent-specific page and extract the magent link
-	if ($tor->{'source'} eq 'ISO') {
+	if ($tor->{'source'} eq 'ISO' || $tor->{'source'} eq 'ET') {
 		if ($DEBUG) {
 		if ($DEBUG) {
 			print STDERR 'Secondary fetch with URL: ' . $tor->{'url'} . "\n";
 			print STDERR 'Secondary fetch with URL: ' . $tor->{'url'} . "\n";
 			$fetch->file('/tmp/findTorrent-secondary.html');
 			$fetch->file('/tmp/findTorrent-secondary.html');
@@ -1281,8 +1352,8 @@ sub resolveTrackers($) {
 
 
 }
 }
 
 
-sub splitTags($$$) {
-	my ($content, $tag, $header) = @_;
+sub splitTags($$$$) {
+	my ($content, $tag, $header, $match) = @_;
 
 
 	# Find each tag element
 	# Find each tag element
 	my @out = ();
 	my @out = ();
@@ -1305,6 +1376,14 @@ sub splitTags($$$) {
 			next;
 			next;
 		}
 		}
 
 
+		# Skip non-matches
+		if (defined($match) && !($part =~ m/${match}/i)) {
+			if ($DEBUG > 2) {
+				print STDERR 'Skipping non-match line: ' . $part . "\n\n";
+			}
+			next;
+		}
+
 		# Save good tags
 		# Save good tags
 		push(@out, $part);
 		push(@out, $part);
 	}
 	}
@@ -1343,12 +1422,14 @@ sub findSE($) {
 		$season  = undef();
 		$season  = undef();
 		$episode = undef();
 		$episode = undef();
 	} elsif ($episode =~ /^20\d{2}\-\d{2}\-\d{2}$/) {
 	} elsif ($episode =~ /^20\d{2}\-\d{2}\-\d{2}$/) {
+
 		# Episode-by-date
 		# Episode-by-date
 		$season = int($season);
 		$season = int($season);
 	} else {
 	} else {
+
 		# Catchall
 		# Catchall
 		# This will warn and return undef() (which is valid) on error
 		# This will warn and return undef() (which is valid) on error
-		$season = int($season);
+		$season  = int($season);
 		$episode = int($episode);
 		$episode = int($episode);
 	}
 	}
 	return ($season, $episode);
 	return ($season, $episode);
@@ -1409,6 +1490,18 @@ sub initSources() {
 		}
 		}
 	}
 	}
 
 
+	# ExtraTorrent
+	if ($ENABLE_SOURCE{'ET'}) {
+		my @proxies = ('http://extratorrent.cc/search/?search=', 'http://etmirror.com/search/?search=', 'http://etproxy.com/search/?search=', 'http://extratorrentlive.com/search/?search=');
+		my $source = findProxy(\@proxies, '/search/');
+		if ($source) {
+			$source->{'weight'}        = 0.75;
+			$source->{'quote'}         = 1;
+			$source->{'search_suffix'} = '&new=1&x=0&y=0&srt=seeds&order=desc';
+			$sources{'ET'}             = $source;
+		}
+	}
+
 	# Sanity check
 	# Sanity check
 	if (scalar(keys(%sources)) < 1) {
 	if (scalar(keys(%sources)) < 1) {
 		die("No sources available\n");
 		die("No sources available\n");