Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('content-type: text/xml; charset=utf-8');
- /***************************************************************************
- * RSS READER FOR ICELANDIC TORRENT SITES *
- * Rss v0.1 - By Dabbi *
- ***************************************************************************/
- /******************* CONFIG CHANGE AS NEEDED! *****************************/
- // Url to the browse page on the site you want to scrape.
- $url_to_browse = "http://deildu.net/browse.php";
- /* These are the cookie values you need to set in order
- to have access to the browse page.*/
- $uid = "YOUR_UID";
- $pass = "YOUR_PASSHASH";
- /* Shouldnt need to change this unless you are scraping another
- website that has a different layout, this is for Deildu.net. */
- $torrent_table = 5; // Sixth table is torrent table
- $col_name = 1; // Second column is torrent name
- $col_date = 5; // Sixth column is torrent date
- $col_size = 6; // Seventh column is torrent size
- /************************* /CONFIG *****************************************/
- // Curl parameters and execution http://php.net/manual/en/book.curl.php
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, format_url($url_to_browse));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
- curl_setopt($ch, CURLOPT_COOKIE, "uid=$uid; pass=$pass");
- $http_data = curl_exec($ch);
- curl_close($ch);
- // Create a new domDocument and set it up http://php.net/manual/en/class.domdocument.php
- $dom = new domDocument;
- @$dom->loadHTML($http_data);
- $tables = $dom->getElementsByTagName('table');
- $rows = $tables->item($torrent_table)->getElementsByTagName('tr');
- // Create the rss feed
- ?>
- <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
- <channel>
- <title>Deildu.net</title>
- <link>http://deildu.net</link>
- <description>Deildu.net RSS Feed by Dabbi</description>
- <ttl>20</ttl>
- <language>en-us</language>
- <atom:link href="<?=htmlspecialchars("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);?>" rel="self" type="application/rss+xml"/>
- <?php
- $isTorrentRow = false;
- foreach($rows as $row)
- {
- $cols = $row->getElementsByTagName('td');
- $links = $row->getElementsByTagName('a');
- if($cols->item($col_name)->nodeValue == "Nafn")
- {
- $isTorrentRow = true;
- continue;
- }
- if($isTorrentRow)
- {
- $enclosureUrl = $links->item(2)->getAttribute('href');
- $link = trim(htmlspecialchars($links->item(1)->getAttribute('href')));
- $title = trim(str_replace("&", " and ", $cols->item($col_name)->nodeValue));
- // Change date to RSS friendly format
- $pubDate = date("D\, j M Y H:i:s", strtotime($cols->item($col_date)->nodeValue));
- // Length of torrentfile (Not actually, its just the size the files, but we need dis)
- $length = split(" ", trim($cols->item($col_size)->nodeValue));
- ?>
- <item>
- <title><?=$title;?></title>
- <link>http://deildu.net/<?=$link;?></link>
- <guid isPermaLink="false"><?=md5($link);?></guid>
- <pubDate><?=$pubDate;?> GMT</pubDate>
- <enclosure url="http://deildu.net/<?=trim($enclosureUrl);?>" length="<?=floor($length[0] * 1024 * 1024);?>" type="application/x-bittorrent"/>
- </item>
- <?php
- }
- }
- ?>
- </channel>
- </rss>
- <?php
- function format_url($url)
- {
- $url .= "?";
- $url .= ($_GET['q']) ? "&search=" . urlencode($_GET['q']) : null;
- $url .= ($_GET['s']) ? "&sort=" . $_GET['s'] : "&sort=added";
- $url .= ($_GET['t']) ? "&type=" . $_GET['t'] : "&type=desc";
- $url .= ($_GET['c']) ? "&cat=" . $_GET['c'] : "&cat=0" ;
- return $url;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement