Advertisement
Guest User

Untitled

a guest
Apr 26th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.18 KB | None | 0 0
  1. <?php
  2. header('content-type: text/xml; charset=utf-8');
  3. /***************************************************************************
  4. *                RSS READER FOR ICELANDIC TORRENT SITES                    *
  5. *                           Rss v0.1 - By Dabbi                            *
  6. ***************************************************************************/
  7.  
  8. /******************* CONFIG CHANGE AS NEEDED! *****************************/
  9. // Url to the browse page on the site you want to scrape.
  10. $url_to_browse = "http://deildu.net/browse.php";
  11.  
  12. /* These are the cookie values you need to set in order
  13.    to have access to the browse page.*/
  14. $uid = "YOUR_UID";
  15. $pass = "YOUR_PASSHASH";
  16.  
  17. /* Shouldnt need to change this unless you are scraping another
  18.    website that has a different layout, this is for Deildu.net. */
  19. $torrent_table = 5; // Sixth table is torrent table
  20. $col_name = 1; // Second column is torrent name
  21. $col_date = 5; // Sixth column is torrent date
  22. $col_size = 6; // Seventh column is torrent size
  23.  
  24. /************************* /CONFIG *****************************************/
  25.  
  26. // Curl parameters and execution http://php.net/manual/en/book.curl.php
  27. $ch = curl_init();
  28. curl_setopt($ch, CURLOPT_URL, format_url($url_to_browse));
  29. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  30. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
  31. curl_setopt($ch, CURLOPT_COOKIE, "uid=$uid; pass=$pass");
  32. $http_data = curl_exec($ch);
  33. curl_close($ch);
  34.  
  35. // Create a new domDocument and set it up http://php.net/manual/en/class.domdocument.php
  36. $dom = new domDocument;
  37. @$dom->loadHTML($http_data);
  38. $tables = $dom->getElementsByTagName('table');
  39. $rows = $tables->item($torrent_table)->getElementsByTagName('tr');
  40.  
  41. // Create the rss feed
  42. ?>
  43. <rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  44.         <channel>
  45.                 <title>Deildu.net</title>
  46.                 <link>http://deildu.net</link>
  47.                 <description>Deildu.net RSS Feed by Dabbi</description>
  48.                 <ttl>20</ttl>
  49.                 <language>en-us</language>
  50.                 <atom:link href="<?=htmlspecialchars("http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);?>" rel="self" type="application/rss+xml"/>
  51. <?php
  52. $isTorrentRow = false;
  53. foreach($rows as $row)
  54. {
  55.         $cols = $row->getElementsByTagName('td');
  56.         $links = $row->getElementsByTagName('a');
  57.        
  58.         if($cols->item($col_name)->nodeValue == "Nafn")
  59.         {
  60.                 $isTorrentRow = true;
  61.                 continue;
  62.         }
  63.  
  64.         if($isTorrentRow)
  65.         {
  66.                         $enclosureUrl = $links->item(2)->getAttribute('href');
  67.                         $link = trim(htmlspecialchars($links->item(1)->getAttribute('href')));
  68.                         $title = trim(str_replace("&", " and ", $cols->item($col_name)->nodeValue));
  69.                        
  70.                         // Change date to RSS friendly format
  71.                         $pubDate = date("D\, j M Y H:i:s", strtotime($cols->item($col_date)->nodeValue));
  72.                        
  73.                         // Length of torrentfile (Not actually, its just the size the files, but we need dis)
  74.                         $length = split(" ", trim($cols->item($col_size)->nodeValue));
  75.         ?>
  76.                         <item>
  77.                                 <title><?=$title;?></title>
  78.                                 <link>http://deildu.net/<?=$link;?></link>
  79.                                 <guid isPermaLink="false"><?=md5($link);?></guid>
  80.                                 <pubDate><?=$pubDate;?> GMT</pubDate>
  81.                                 <enclosure url="http://deildu.net/<?=trim($enclosureUrl);?>" length="<?=floor($length[0] * 1024 * 1024);?>" type="application/x-bittorrent"/>
  82.                         </item>
  83.                
  84.         <?php
  85.         }              
  86. }
  87. ?>
  88.         </channel>
  89. </rss>
  90. <?php
  91. function format_url($url)
  92. {
  93.         $url .= "?";
  94.         $url .= ($_GET['q']) ? "&search=" . urlencode($_GET['q']) : null;
  95.         $url .= ($_GET['s']) ? "&sort=" . $_GET['s'] : "&sort=added";
  96.         $url .= ($_GET['t']) ? "&type=" . $_GET['t'] : "&type=desc";
  97.         $url .= ($_GET['c']) ? "&cat=" . $_GET['c'] : "&cat=0" ;
  98.         return $url;
  99. }
  100. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement