-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
69 lines (55 loc) · 2.16 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class TorrentSearchAnidex {
private $qurl = "https://anidex.info/rss/?q=";
private $unit_map = array(
"KB" => 1024,
"MB" => 1048576,
"GB" => 1073741824,
);
public function __construct() {
}
private function format_size($size, $unit) {
$multiplier = $this->unit_map[$unit];
$size = floatval($size) * $multiplier;
return $size;
}
private function format_datetime($datetime) {
$timestamp = strtotime($datetime);
$converted_datetime = date("Y-m-d H:i", $timestamp);
return $converted_datetime;
}
public function prepare($curl, $query) {
$url = $this->qurl . urlencode($query);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
}
public function parse($plugin, $response) {
$regexp = "<item>.*".
"<category>(?P<category>.*)</category>.*".
"<title>(?P<title>.*)</title>.*".
"<link>(?P<download>https://anidex.info/dl/(?P<id>\d*))</link>.*". // download (torrent file)
"<description><!\[CDATA\[.*\| Size: (?P<size>[\d.]+) (?P<unit>[KMG]B) \|.*</description>.*".
"<pubDate>(?P<date>.*)</pubDate>.*". // date
"<guid>.*</guid>.*".
"</item>.*";
$count = 0;
if (preg_match_all("|$regexp|siU", $response, $matches, PREG_SET_ORDER)) {
foreach ($matches as $match) {
$title = $match["title"];
$download = $match["download"];
$size = $this->format_size($match["size"], $match["unit"]);
$datetime = $this->format_datetime($match["date"]);
$page = "https:\/\/anidex.info/?page=torrent&id=%s" . $match["id"];
$hash = $count;
$seeds = 0; // FIXME
$leechs = 0; // FIXME
$category = $match["category"];
$plugin->addResult($title, $download, $size, $datetime, $page, $hash, $seeds, $leechs, $category);
$count++;
}
}
return $count;
}
}
?>