ThePirateBayBridge.php 3.8 KB

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