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';
|
2018-11-05 20:17:46 +03:00
|
|
|
const URI = 'https://thepiratebay.wf/';
|
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-02-11 18:16:56 +03:00
|
|
|
function parseDateTimestamp($element){
|
2017-02-14 19:28:07 +03:00
|
|
|
$guessedDate = $element->find('font', 0)->plaintext;
|
2017-02-11 18:16:56 +03:00
|
|
|
$guessedDate = explode('Uploaded ', $guessedDate)[1];
|
|
|
|
$guessedDate = explode(',', $guessedDate)[0];
|
2014-12-08 21:39:57 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if(count(explode(':', $guessedDate)) == 1) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$guessedDate = strptime($guessedDate, '%m-%d %Y');
|
|
|
|
$timestamp = mktime(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
$guessedDate['tm_mon'] + 1,
|
|
|
|
$guessedDate['tm_mday'],
|
|
|
|
1900 + $guessedDate['tm_year']
|
|
|
|
);
|
2017-07-29 20:28:00 +03:00
|
|
|
} elseif(explode(' ', $guessedDate)[0] == 'Today') {
|
2017-02-11 18:16:56 +03:00
|
|
|
$guessedDate = strptime(
|
|
|
|
explode(' ', $guessedDate)[1], '%H:%M'
|
|
|
|
);
|
2014-12-08 21:39:57 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$timestamp = mktime(
|
|
|
|
$guessedDate['tm_hour'],
|
|
|
|
$guessedDate['tm_min'],
|
|
|
|
0,
|
|
|
|
date('m'),
|
|
|
|
date('d'),
|
|
|
|
date('Y')
|
|
|
|
);
|
2017-07-29 20:28:00 +03:00
|
|
|
} elseif(explode(' ', $guessedDate)[0] == 'Y-day') {
|
2017-02-11 18:16:56 +03:00
|
|
|
$guessedDate = strptime(
|
2017-02-14 19:28:07 +03:00
|
|
|
explode(' ', $guessedDate)[1], '%H:%M'
|
2017-02-11 18:16:56 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
$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-12-08 21:39:57 +03: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();
|
|
|
|
$item['uri'] = $element->find('a', 3)->href;
|
|
|
|
$item['id'] = self::URI . $element->find('a.detLink', 0)->href;
|
|
|
|
$item['timestamp'] = parseDateTimestamp($element);
|
|
|
|
$item['author'] = $element->find('a.detDesc', 0)->plaintext;
|
|
|
|
$item['title'] = $element->find('a.detLink', 0)->plaintext;
|
|
|
|
$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']
|
|
|
|
. '">info page</a>';
|
2014-12-08 21:39:57 +03:00
|
|
|
|
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
|
|
|
}
|
2014-05-26 21:45:10 +04:00
|
|
|
}
|