View difference between Paste ID: 2RN6ddFp and 1JmZUcTt
SHOW: | | - or go back to the newest paste.
1
/*
2-
Editted: 2020-10-05
2+
3-
Reason: Old script didn't work any more. Now using the API with JSON results.
3+
Run it like http://my.domain.com/rss.php?search=vivaldi
4
*/
5
6-
Run it like http://my.domain.com/rss.php?search=free porn
6+
7
/*
8
************************************
9
Filename: rss.php (can be anything you like)
10
Description: Uses ?search= GET parameter to search The Pirate Bay and displays results as RSS feed.
11
*************************************
12
*/
13
$PirateDomain = 'https://thepiratebay.se'; // No trailing slash please!
14
$search  = (isset($_GET['search']))? $_GET['search']:'';
15
if ($search) {
16-
$PirateAPI = 'https://apibay.org/q.php'; // No trailing slash please!
16+
	$content = file_get_contents($PirateDomain.'/search/'.$search);
17-
$PirateDomain = 'https://thepiratebay.org'; // No trailing slash please!
17+
	if (preg_match('/<table id="searchResult">.*?<\/table>/is', $content, $table)) {
18
		preg_match_all('/<div class="detName">.*?<a href="(.*?)".*?>(.*?)<\/a>.*?<a href="magnet:([^"]*).*?Uploaded (.{1,20}), Size (.{1,30}),.*?class="detDesc".*?>(.*?)<\/a>.*?<td .*?>([0-9]{1,8}).*?<td .*?>([0-9]{1,8})/is', $table[0], $matches, PREG_SET_ORDER);
19
	}
20-
	$json = file_get_contents($PirateAPI.'?q='.$search);
20+
	unset($content);
21-
	$results = json_decode($json,true);
21+
22-
	unset($json);
22+
23
header("Content-type: text/xml");
24
?>
25
<?xml version="1.0" encoding="ISO-8859-1"?>
26
<rss version="2.0">
27
    <channel>
28
        <title>Unofficial Pirate Bay RSS - <?php echo $search; ?></title>
29
        <link><?php echo $PirateDomain; ?></link>
30
        <description>Pirate Bay scraper</description>
31
        <language>en-us</language>
32
		<?php
33
		if (isset($matches)) {
34
			foreach ($matches as $match) {
35-
		foreach ($results as $result) {
35+
				echo '<item>';
36-
			echo '<item>';
36+
				echo '<title>'.$match[2].'</title>';
37-
			echo '<title>'.$result["name"].'</title>';
37+
				echo '<description>Size: '.html_entity_decode($match[5]).', Uploaded by: '.html_entity_decode($match[6]).', Seeders: '.html_entity_decode($match[7]).', Leechers: '.html_entity_decode($match[8]).'</description>';
38-
			echo '<description>Size: '.$result["size"].', Uploaded by: '.$result["username"].', Seeders: '.$result["seeders"].', Leechers: '.$result["leechers"].'</description>';
38+
				echo '<link>'.$PirateDomain.$match[1].'</link>';
39-
			echo '<link>'.$PirateDomain.'/description.php?id='.$result["id"].'</link>';
39+
				echo '<pubDate>'.html_entity_decode($match[4]).'</pubDate>';
40-
			//echo '<pubDate>'.date('r',$result["added"]).'</pubDate>';
40+
				echo '<enclosure url="http'.(isset($_SERVER['HTTPS'])? 's':'').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/rss_magnet.php?magnet='.urlencode($match[3]).'" type="application/x-bittorrent" length="10000" />';
41-
			echo '<pubDate>'.date("D, d M Y H:i:s T",$result["added"]).'</pubDate>';
41+
				echo "</item>\n";
42-
			echo '<enclosure url="http'.(isset($_SERVER['HTTPS'])? 's':'').'://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/rss_magnet.php?hash='.$result["info_hash"].'&amp;name='.urlencode($result["name"]).'" type="application/x-bittorrent" length="10000" />';
42+
			}
43-
			echo "</item>\n";
43+
44
		?>
45
    </channel>
46
</rss>
47
48
<?php
49
/*
50
************************************
51
Filename: rss_magnet.php
52
Description: Relocates magnet links (as a hack because RSS doesn't work with magnet links)
53
*************************************
54
*/
55
$magnet  = (isset($_GET['magnet']))? $_GET['magnet']:'';
56-
Magnet URL format: magnet:?xt=urn:btih:<info_hash>&dn=<download_name>&tr=<tracker url, can be repeated for multiple url's>
56+
57
	header('Location: magnet:'.urldecode($magnet));
58
} else {
59
	die('No link provided');
60-
$hash  = (isset($_GET['hash']))? $_GET['hash']:'';
60+
61-
$name  = (isset($_GET['name']))? $_GET['name']:'';
61+