ThePirateBayBridge.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * RssBridgeThePirateBay
  4. * Returns results for the keywords. You can put several list of keywords by separating them with a semicolon (e.g. "one show;another show")
  5. * 2014-05-25
  6. *
  7. * @name The Pirate Bay
  8. * @homepage https://thepiratebay.se/
  9. * @description Returns results for the keywords. You can put several list of keywords by separating them with a semicolon (e.g. "one show;another show")
  10. * @maintainer mitsukarenai
  11. * @update 2014-05-26
  12. * @use1(q="first list;second list;...")
  13. */
  14. class ThePirateBayBridge extends BridgeAbstract{
  15. public function collectData(array $param){
  16. function parseDateTimestamp($element){
  17. $guessedDate = $element->find('font',0)->plaintext;
  18. $guessedDate = explode("Uploaded ",$guessedDate)[1];
  19. $guessedDate = explode(",",$guessedDate)[0];
  20. if (count(explode(":",$guessedDate)) == 1)
  21. {
  22. $guessedDate = strptime($guessedDate, '%m-%d&nbsp;%Y');
  23. $timestamp = mktime(0, 0, 0,
  24. $guessedDate['tm_mon'] + 1, $guessedDate['tm_mday'], 1900+$guessedDate['tm_year']);
  25. }
  26. else if (explode("&nbsp;",$guessedDate)[0] == 'Today')
  27. {
  28. $guessedDate = strptime(explode("&nbsp;",$guessedDate)[1], '%H:%M');
  29. $timestamp = mktime($guessedDate['tm_hour'], $guessedDate['tm_min'], 0,
  30. date('m'), date('d'), date('Y'));
  31. }
  32. else if (explode("&nbsp;",$guessedDate)[0] == 'Y-day')
  33. {
  34. $guessedDate = strptime(explode("&nbsp;",$guessedDate)[1], '%H:%M');
  35. $timestamp = mktime($guessedDate['tm_hour'], $guessedDate['tm_min'], 0,
  36. date('m',time()-24*60*60), date('d',time()-24*60*60), date('Y',time()-24*60*60));
  37. }
  38. else
  39. {
  40. $guessedDate = strptime($guessedDate, '%m-%d&nbsp;%H:%M');
  41. $timestamp = mktime($guessedDate['tm_hour'], $guessedDate['tm_min'], 0,
  42. $guessedDate['tm_mon'] + 1, $guessedDate['tm_mday'], date('Y'));
  43. }
  44. return $timestamp;
  45. }
  46. if (!isset($param['q']))
  47. $this->returnError('You must specify keywords (?q=...)', 400);
  48. $keywordsList = explode(";",$param['q']);
  49. foreach($keywordsList as $keywords){
  50. $html = file_get_html('https://thepiratebay.se/search/'.rawurlencode($keywords).'/0/3/0') or $this->returnError('Could not request TPB.', 404);
  51. if ($html->find('table#searchResult', 0) == FALSE)
  52. $this->returnError('No result for query '.$keywords, 404);
  53. foreach($html->find('tr') as $element) {
  54. $item = new \Item();
  55. $item->uri = 'https://thepiratebay.se/'.$element->find('a.detLink',0)->href;
  56. $item->id = $item->uri;
  57. $item->timestamp = parseDateTimestamp($element);
  58. $item->title = $element->find('a.detLink',0)->plaintext;
  59. $item->seeders = (int)$element->find('td',2)->plaintext;
  60. $item->leechers = (int)$element->find('td',3)->plaintext;
  61. $item->content = $element->find('font',0)->plaintext.'<br>seeders: '.$item->seeders.' | leechers: '.$item->leechers.'<br><a href="'.$element->find('a',3)->href.'">download</a>';
  62. if(!empty($item->title))
  63. $this->items[] = $item;
  64. }
  65. }
  66. }
  67. public function getName(){
  68. return 'The Pirate Bay';
  69. }
  70. public function getURI(){
  71. return 'https://thepiratebay.se/';
  72. }
  73. public function getCacheDuration(){
  74. return 3600; // 1 hour
  75. }
  76. }