2014-05-26 21:45:10 +04:00
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
class ThePirateBayBridge extends BridgeAbstract {
|
2014-05-26 21:45:10 +04:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'mitsukarenai';
|
|
|
|
const NAME = 'The Pirate Bay';
|
2019-08-27 01:55:36 +03:00
|
|
|
const URI = 'https://thepiratebay.org/';
|
2017-02-11 18:16:56 +03:00
|
|
|
const 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"). Category based search needs the category number as input. User based
|
|
|
|
search takes the Uploader name. Search can be done in a specified category';
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const PARAMETERS = array( array(
|
|
|
|
'q' => array(
|
2017-08-26 20:28:52 +03:00
|
|
|
'name' => 'keywords/username/category, separated by semicolons',
|
2017-02-11 18:16:56 +03:00
|
|
|
'exampleValue' => 'first list;second list;…',
|
|
|
|
'required' => true
|
|
|
|
),
|
|
|
|
'crit' => array(
|
|
|
|
'type' => 'list',
|
|
|
|
'name' => 'Search type',
|
|
|
|
'values' => array(
|
|
|
|
'search' => 'search',
|
|
|
|
'category' => 'cat',
|
|
|
|
'user' => 'usr'
|
|
|
|
)
|
|
|
|
),
|
2017-08-26 20:28:52 +03:00
|
|
|
'catCheck' => array(
|
2017-02-11 18:16:56 +03:00
|
|
|
'type' => 'checkbox',
|
2017-08-26 20:28:52 +03:00
|
|
|
'name' => 'Specify category for keyword search ?',
|
2017-02-11 18:16:56 +03:00
|
|
|
),
|
|
|
|
'cat' => array(
|
|
|
|
'name' => 'Category number',
|
|
|
|
'exampleValue' => '100, 200… See TPB for category number'
|
|
|
|
),
|
|
|
|
'trusted' => array(
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'name' => 'Only get results from Trusted or VIP users ?',
|
|
|
|
),
|
|
|
|
));
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData(){
|
2014-05-26 21:45:10 +04:00
|
|
|
|
2017-08-26 20:28:52 +03:00
|
|
|
$catBool = $this->getInput('catCheck');
|
2017-07-29 20:28:00 +03:00
|
|
|
if($catBool) {
|
2016-10-02 16:09:51 +03:00
|
|
|
$catNum = $this->getInput('cat');
|
2016-10-02 17:05:58 +03:00
|
|
|
}
|
2016-09-30 12:07:43 +03:00
|
|
|
$critList = $this->getInput('crit');
|
2017-02-11 18:16:56 +03:00
|
|
|
|
|
|
|
$trustedBool = $this->getInput('trusted');
|
|
|
|
$keywordsList = explode(';', $this->getInput('q'));
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach($keywordsList as $keywords) {
|
|
|
|
switch($critList) {
|
2017-02-11 18:16:56 +03:00
|
|
|
case 'search':
|
2017-07-29 20:28:00 +03:00
|
|
|
if($catBool == false) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$html = getSimpleHTMLDOM(
|
|
|
|
self::URI .
|
|
|
|
'search/' .
|
|
|
|
rawurlencode($keywords) .
|
|
|
|
'/0/3/0'
|
|
|
|
) or returnServerError('Could not request TPB.');
|
|
|
|
} else {
|
|
|
|
$html = getSimpleHTMLDOM(
|
|
|
|
self::URI .
|
|
|
|
'search/' .
|
|
|
|
rawurlencode($keywords) .
|
|
|
|
'/0/3/' .
|
|
|
|
rawurlencode($catNum)
|
|
|
|
) or returnServerError('Could not request TPB.');
|
2016-10-02 16:09:51 +03:00
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
break;
|
|
|
|
case 'cat':
|
|
|
|
$html = getSimpleHTMLDOM(
|
|
|
|
self::URI .
|
|
|
|
'browse/' .
|
|
|
|
rawurlencode($keywords) .
|
|
|
|
'/0/3/0'
|
|
|
|
) or returnServerError('Could not request TPB.');
|
|
|
|
break;
|
|
|
|
case 'usr':
|
|
|
|
$html = getSimpleHTMLDOM(
|
|
|
|
self::URI .
|
|
|
|
'user/' .
|
|
|
|
rawurlencode($keywords) .
|
|
|
|
'/0/3/0'
|
|
|
|
) or returnServerError('Could not request TPB.');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($html->find('table#searchResult', 0) == false)
|
|
|
|
returnServerError('No result for query ' . $keywords);
|
2016-09-30 12:07:43 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
foreach($html->find('tr') as $element) {
|
2014-05-26 21:45:10 +04:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
if(!$trustedBool
|
|
|
|
|| !is_null($element->find('img[alt=VIP]', 0))
|
2017-07-29 20:28:00 +03:00
|
|
|
|| !is_null($element->find('img[alt=Trusted]', 0))) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$item = array();
|
2019-08-27 02:18:43 +03:00
|
|
|
$item['uri'] = self::URI . $element->find('a.detLink', 0)->href;
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['id'] = self::URI . $element->find('a.detLink', 0)->href;
|
2019-10-03 22:46:24 +03:00
|
|
|
$item['timestamp'] = $this->parseDateTimestamp($element);
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['author'] = $element->find('a.detDesc', 0)->plaintext;
|
|
|
|
$item['title'] = $element->find('a.detLink', 0)->plaintext;
|
2019-08-27 02:18:43 +03:00
|
|
|
$item['magnet'] = $element->find('a', 3)->href;
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['seeders'] = (int)$element->find('td', 2)->plaintext;
|
|
|
|
$item['leechers'] = (int)$element->find('td', 3)->plaintext;
|
|
|
|
$item['content'] = $element->find('font', 0)->plaintext
|
|
|
|
. '<br>seeders: '
|
|
|
|
. $item['seeders']
|
|
|
|
. ' | leechers: '
|
|
|
|
. $item['leechers']
|
|
|
|
. '<br><a href="'
|
|
|
|
. $item['id']
|
2019-09-06 11:55:15 +03:00
|
|
|
. '">info page</a><br><a href="'
|
2019-08-27 02:18:43 +03:00
|
|
|
. $item['magnet']
|
|
|
|
. '">magnet link</a>';
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
if(isset($item['title']))
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-12-11 14:11:03 +03:00
|
|
|
}
|
2014-12-08 21:39:57 +03:00
|
|
|
}
|
2019-10-03 22:46:24 +03:00
|
|
|
|
|
|
|
private function parseDateTimestamp($element){
|
|
|
|
$guessedDate = $element->find('font', 0)->plaintext;
|
|
|
|
$guessedDate = explode('Uploaded ', $guessedDate)[1];
|
|
|
|
$guessedDate = explode(',', $guessedDate)[0];
|
|
|
|
|
|
|
|
if(count(explode(':', $guessedDate)) == 1) {
|
|
|
|
$guessedDate = strptime($guessedDate, '%m-%d %Y');
|
|
|
|
$timestamp = mktime(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
$guessedDate['tm_mon'] + 1,
|
|
|
|
$guessedDate['tm_mday'],
|
|
|
|
1900 + $guessedDate['tm_year']
|
|
|
|
);
|
|
|
|
} elseif(explode(' ', $guessedDate)[0] == 'Today') {
|
|
|
|
$guessedDate = strptime(
|
|
|
|
explode(' ', $guessedDate)[1], '%H:%M'
|
|
|
|
);
|
|
|
|
|
|
|
|
$timestamp = mktime(
|
|
|
|
$guessedDate['tm_hour'],
|
|
|
|
$guessedDate['tm_min'],
|
|
|
|
0,
|
|
|
|
date('m'),
|
|
|
|
date('d'),
|
|
|
|
date('Y')
|
|
|
|
);
|
|
|
|
} elseif(explode(' ', $guessedDate)[0] == 'Y-day') {
|
|
|
|
$guessedDate = strptime(
|
|
|
|
explode(' ', $guessedDate)[1], '%H:%M'
|
|
|
|
);
|
|
|
|
|
|
|
|
$timestamp = mktime(
|
|
|
|
$guessedDate['tm_hour'],
|
|
|
|
$guessedDate['tm_min'],
|
|
|
|
0,
|
|
|
|
date('m', time() - 24 * 60 * 60),
|
|
|
|
date('d', time() - 24 * 60 * 60),
|
|
|
|
date('Y', time() - 24 * 60 * 60)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$guessedDate = strptime($guessedDate, '%m-%d %H:%M');
|
|
|
|
$timestamp = mktime(
|
|
|
|
$guessedDate['tm_hour'],
|
|
|
|
$guessedDate['tm_min'],
|
|
|
|
0,
|
|
|
|
$guessedDate['tm_mon'] + 1,
|
|
|
|
$guessedDate['tm_mday'],
|
|
|
|
date('Y'));
|
|
|
|
}
|
|
|
|
return $timestamp;
|
|
|
|
}
|
2014-05-26 21:45:10 +04:00
|
|
|
}
|