-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathKickassProvider.php
95 lines (84 loc) · 2.28 KB
/
KickassProvider.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Axon\Search\Provider;
use Nomnom\Nomnom;
use Symfony\Component\DomCrawler\Crawler;
use Axon\Search\Model\Torrent;
/**
* @author Ramon Kleiss <ramonkleiss@gmail.com>
*/
class KickassProvider extends AbstractProvider
{
/**
* @var string
*/
const DEFAULT_HOST = 'kickass.to';
/**
* @var string
*/
const DEFAULT_PATH = '/usearch';
/**
* {@inheritDoc}
*/
public function getName()
{
return 'Kickass';
}
/**
* {@inheritDoc}
*/
public function getCanonicalName()
{
return 'kickass';
}
/**
* @param string $query
* @param integer|null $page
*
* @return string
*/
public function getUrl($query, $page)
{
if (is_integer($page)) {
return sprintf(
'http://%s%s/%s/%s/?field=seeders&order=desc',
self::DEFAULT_HOST,
self::DEFAULT_PATH,
$query,
$page
);
} else {
return sprintf(
'http://%s%s/%s/?field=seeders&order=desc',
self::DEFAULT_HOST,
self::DEFAULT_PATH,
$query
);
}
}
/**
* @param string $rawResponse
*
* @return Torrent[]
*/
protected function transformResponse($rawResponse)
{
$crawler = new Crawler(gzdecode($rawResponse));
return $crawler->filter('tr[id^="torrent_"]')->each(function ($node) {
$magnet = $node->filter('a.imagnet')->attr('href');
preg_match('/btih:([0-9A-Za-z]+)&/', $magnet, $matches);
$hash = $matches[1];
$size = $node->filter('td.nobr')->text();
preg_match('/([0-9\.]+) ([A-Za-z]+)/', $size, $matches);
$size = $matches[1];
$unit = $matches[2];
$converter = new Nomnom($size);
$torrent = new Torrent();
$torrent->setName($node->filter('a.cellMainLink')->text());
$torrent->setHash($hash);
$torrent->setSize($converter->from($unit)->to('B'));
$torrent->setSeeds($node->filter('td.green')->text());
$torrent->setPeers($node->filter('td.red')->text());
return $torrent;
});
}
}