public function download() { $id = $this->route()->getSegment(0); $watcher = $this->_watchers->get($id); $this->result = null; if ($watcher != null) { $season_id = $this->route()->getSegment(1); $episode_id = $this->route()->getSegment(2); $watcher->load(); $ep = null; foreach ($watcher->series()->seasons as $season) { if ($season->num == $season_id) { foreach ($season->episodes as $episode) { if ($episode->num == $episode_id) { $ep = $episode; break; } } break; } } $this->episode = $ep; $newzbin = new Newzbin(); $results = $newzbin->rawSearch("{$watcher->name} {$ep->identifier()} " . $watcher->toNewzbinParams(), $watcher); if ($results != null && is_array($results) && sizeof($results) > 0) { $this->result = $watcher->findSuitableReport($results); $sabnzbd = new SABnzbd(nzbVR::instance()->settings->sabnzbd_address, nzbVR::instance()->settings->sabnzbd_apikey); $sabnzbd->send(array($this->result)); $this->episode->downloaded = true; $this->episode->downloaded_at = time(); $watcher->save(); } } }
public function check() { $this->results = array(); $type = $this->params()->get("type"); $id = null; if (sizeof($this->route()->segments()) == 1) { $id = $this->route()->getSegment(0); } $this->_watchers->last_benchmark = new WatcherBenchmark(); $this->_watchers->last_benchmark->mark("start"); foreach ($this->_watchers->watchers as $watcher) { if ($watcher != null && ($type == null || $type == "movies" && $watcher instanceof MovieWatcher || $type == "series" && $watcher instanceof SeriesWatcher || $type == "search" && $watcher instanceof SearchWatcher) && ($id == null || $watcher->id == $id)) { $this->checkWatcher($watcher); } } if ($this->results != null && sizeof($this->results) > 0) { $sabnzbd = new SABnzbd(nzbVR::instance()->settings->sabnzbd_address, nzbVR::instance()->settings->sabnzbd_apikey); $sabnzbd->send($this->results); } //$notifiers = new Notifiers(); //foreach ($this->results as $result) { // $notifiers->notification("Sent '{$result->name}' report to SABnzbd+", "Report found"); //} $notifiers = null; $this->_watchers->last_benchmark->downloads = sizeof($this->results); $this->_watchers->last_benchmark->mark("end"); $this->_watchers->save(); if ($this->picnic()->router()->outputType() == "html") { //$this->redirect("index"); } }