rss-bridge/bridges/IKWYDBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
3.7 KiB
PHP
Raw Normal View History

2020-12-13 14:08:25 +03:00
<?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 = [
[
'ip' => [
2020-12-13 14:08:25 +03:00
'name' => 'IP Address',
'exampleValue' => '8.8.8.8',
2020-12-13 14:08:25 +03:00
'required' => true
],
2020-12-13 14:08:25 +03:00
'update' => [
'name' => 'Update last seen',
'type' => 'checkbox',
'title' => 'Update timestamp every time "last seen" changes'
]
]
];
2020-12-13 14:08:25 +03:00
private $name;
private $uri;
public function detectParameters($url)
{
$params = [];
$regex = '/^(https?:\/\/)?iknowwhatyoudownload\.com\/';
$regex .= '(?: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\/';
$regex .= '(?:(?: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 {
2020-12-13 14:08:25 +03:00
return self::URI;
}
}
2020-12-13 14:08:25 +03:00
public function collectData()
{
2020-12-13 14:08:25 +03:00
$ip = $this->getInput('ip');
$root = self::URI . 'en/peer/?ip=' . $ip;
$html = getSimpleHTMLDOM($root);
2020-12-13 14:08:25 +03:00
$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
2020-12-13 14:08:25 +03:00
)->innertext;
$lastSeen = $download->find(
'.date-column',
1
2020-12-13 14:08:25 +03:00
)->innertext;
$category = $download->find(
'.category-column',
0
2020-12-13 14:08:25 +03:00
)->innertext;
$torlink = $download->find(
'.name-column > div > a',
0
);
2020-12-13 14:08:25 +03:00
$tortitle = strip_tags($torlink);
$size = $download->find('td', 4)->innertext;
$title = $tortitle;
$author = $ip;
if ($this->getInput('update')) {
$timestamp = strtotime($lastSeen);
} else {
2020-12-13 14:08:25 +03:00
$timestamp = strtotime($firstSeen);
}
2020-12-13 14:08:25 +03:00
$uri = $torlink->href;
$content = 'IP address: <a href="' . $root . '">';
$content .= $ip . '</a><br>';
$content .= 'First seen: ' . $firstSeen . '<br>';
$content .= ($this->getInput('update') ? 'Last seen: ' .
$lastSeen . '<br>' : '');
$content .= ($category ? 'Category: ' .
$category . '<br>' : '');
$content .= 'Title: ' . $torlink . '<br>';
$content .= 'Size: ' . $size;
2020-12-13 14:08:25 +03:00
$item = [];
$item['uri'] = $uri;
$item['title'] = $title;
$item['author'] = $author;
$item['timestamp'] = $timestamp;
$item['content'] = $content;
if ($category) {
$item['categories'] = [$category];
}
$this->items[] = $item;
}
}
2020-12-13 14:08:25 +03:00
}