64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
//
|
|
// Retrieve first/last rar for a release, optionally download it
|
|
//
|
|
|
|
define('FS_ROOT', realpath(dirname(__FILE__)));
|
|
require_once(FS_ROOT."/../../www/config.php");
|
|
require_once(FS_ROOT."/../../www/lib/framework/db.php");
|
|
require_once(FS_ROOT."/../../www/lib/nntp.php");
|
|
require_once(FS_ROOT."/../../www/lib/nzb.php");
|
|
require_once(FS_ROOT."/../../www/lib/nzbinfo.php");
|
|
require_once(FS_ROOT."/../../www/lib/site.php");
|
|
|
|
$nzb = new NZB();
|
|
$s = new Sites();
|
|
$site = $s->get();
|
|
$db = new DB();
|
|
$download = false;
|
|
|
|
$sql = sprintf("select guid, searchname from releases limit 1");
|
|
$rows = $db->query($sql);
|
|
|
|
foreach ($rows as $row) {
|
|
echo sprintf("Getting last rar for %s\n", $row["searchname"], $row["guid"]);
|
|
|
|
$nzbfile = $nzb->getNZBPath($row["guid"], $site->nzbpath);
|
|
$nzbInfo = new nzbInfo;
|
|
if ($nzbInfo->loadFromFile($nzbfile)) {
|
|
|
|
$ret = $nzbInfo->getFirstRar();
|
|
if ($ret) {
|
|
echo sprintf("Frst rar - %s\n", $ret["subject"]);
|
|
|
|
if ($download) {
|
|
echo sprintf("Downloading part - %s\n", $ret["firstsegment"]);
|
|
getPart($ret["groups"][0], $ret["firstsegment"], $row["guid"].".rar");
|
|
}
|
|
}
|
|
|
|
$ret = $nzbInfo->getLastRar();
|
|
if ($ret) {
|
|
echo sprintf("Last rar - %s\n", $ret["subject"]);
|
|
|
|
if ($download) {
|
|
echo sprintf("Downloading part - %s\n", $ret["firstsegment"]);
|
|
getPart($ret["groups"][0], $ret["firstsegment"], $row["guid"].".rar");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function getPart($grp, $segment, $filename) {
|
|
$nntp = new NNTP;
|
|
$nntp->doConnect();
|
|
$sampleBinary = $nntp->getMessage($grp, $segment);
|
|
$nntp->doQuit();
|
|
|
|
if ($sampleBinary === false)
|
|
echo sprintf("Could not fetch binary %s \n", $segment);
|
|
else
|
|
file_put_contents($filename, $sampleBinary);
|
|
}
|