Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IKWYDBridge] New bridge #1874

Merged
merged 4 commits into from
Dec 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[IKWYDBridge] New bridge
DevonHess authored Nov 18, 2020
commit 33804d1ad3a35de797f56ae3a16c663aca42d168
121 changes: 121 additions & 0 deletions bridges/IKWYDBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
class IKWYDBridge extends BridgeAbstract {
const MAINTAINER = 'DevonHess';
const NAME = 'I Know What You Download';
const URI = 'https://iknowwhatyoudownload.com/';
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Returns torrent downloads and distributions ' .
'for an IP address';
const PARAMETERS = array(
array(
'ip' => array(
'name' => 'IP Address',
'required' => true
),
'update' => array(
'name' => 'Update last seen',
'type' => 'checkbox',
'title' => 'Update timestamp every time ' .
'"last seen" changes'
)
)
);
private $name;
private $uri;

public function detectParameters($url) {
$params = array();

$regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' .
'(?:en|ru)\/peer\/\?ip=(\d+\.\d+\.\d+\.\d+)/';
if(preg_match($regex, $url, $matches) > 0) {
$params['ip'] = urldecode($matches[2]);
return $params;
}

$regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/' .
'(?:(?:en|ru)\/peer\/)?/';
if(preg_match($regex, $url, $matches) > 0) {
$params['ip'] = $_SERVER['REMOTE_ADDR'];
return $params;
}

return null;
}

public function getName() {
if($this->name) {
return $this->name;
}
else {
return self::NAME;
}
}

public function getURI() {
if($this->uri) {
return $this->uri;
}
else {
return self::URI;
}
}

public function collectData() {
$ip = $this->getInput('ip');
$root = self::URI . 'en/peer/?ip=' . $ip;
$html = getSimpleHTMLDOM($root)
or returnServerError('Could not request ' . self::URI);

$this->name = 'IKWYD: ' . $ip;
$this->uri = $root;

foreach($html->find('.table > tbody > tr') as $download) {
$download = defaultLinkTo($download, self::URI);
$firstSeen = $download->find('.date-column',
0)->innertext;
$lastSeen = $download->find('.date-column',
1)->innertext;
$category = $download->find('.category-column',
0)->innertext;
$torlink = $download->find('.name-column > div > a',
0);
$tortitle = strip_tags($torlink);
$size = $download->find('td', 4)->innertext;

$title = $tortitle;
$author = 'IKWYD';
if($this->getInput('update')) {
$timestamp = strtotime($lastSeen);
}
else {
$timestamp = strtotime($firstSeen);
}

$uri = $torlink->href;
$content =
'IP address: <a href="' . $root . '">' . $ip .
'</a><br>' .
'First seen: ' . $firstSeen . '<br>' .
($this->getInput('update') ?
'Last seen: ' . $lastSeen . '<br>' : '') .
($category ?
'Category: ' . $category . '<br>' : '') .
'Title: ' . $torlink .
'<br>' .
'Size: ' . $size;

$item = array();
$item['uri'] = $uri;
$item['title'] = $title;
$item['author'] = $author;
$item['timestamp'] = $timestamp;
$item['content'] = $content;
if($category) {
$item['categories'] = array($category);
}
$this->items[] = $item;
}
}
}