-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRssPlugin.php
More file actions
64 lines (53 loc) · 1.94 KB
/
RssPlugin.php
File metadata and controls
64 lines (53 loc) · 1.94 KB
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
<?php
namespace Phlexget\RssPlugin;
use Phlexget\Event\Task;
use Phlexget\Plugin\AbstractPlugin;
use SimplePie;
class RssPlugin extends AbstractPlugin
{
public static function getSubscribedEvents()
{
return array(
'phlexget.input' => array('onPhlexgetInput', 0),
);
}
public function onPhlexgetInput(Task $task)
{
$config = $task->getConfig();
if (!isset($config['rss'])) {
return;
}
$task->getOutput()->writeln('<comment>Rss Plugin</comment>:');
$buzz = $this->get('buzz');
$torrents = array();
foreach ($config['rss'] as $rss) {
$cache = $this->get('cache');
$key = 'input.rss.' . md5($rss);
$data = $cache->fetch($key);
if (!$data = $cache->fetch($key)) {
$task->getOutput()->writeln(sprintf(' - Loading rss <info>%s</info> from internet.', $rss));
$response = $buzz->get($rss);
$data = $response->getContent();
$cache->save($key, $data, 24 * 3600);
} else {
$task->getOutput()->writeln(sprintf(' - Loading rss <info>%s</info> from cache.', $rss));
}
$simplepie = new SimplePie();
$simplepie->set_raw_data($data);
$simplepie->enable_cache(false);
$simplepie->init();
foreach ($simplepie->get_items() as $item) {
$torrents[] = array(
'title' => $item->get_title(),
'description' => $item->get_description(),
'date' => $item->get_date(),
'link' => $item->get_enclosure(0)->get_link(),
'size' => $item->get_enclosure(0)->get_length(),
);
}
$task['torrents'] = isset($task['torrents']) ?
array_merge($task['torrents'], $torrents) :
$torrents;
}
}
}