public function updateEpInfo($show, $relid) { $this->pdo = new newznab\db\Settings(); if (empty($show['airdate']) || !strtotime($show['airdate'])) { $tvairdate = "null"; } else { $tvairdate = $this->pdo->escapestring($show['airdate']); } $this->pdo->queryExec(sprintf("update releases set seriesfull = %s, season = %s, episode = %s, tvairdate=%s where id = %d", $this->pdo->escapeString($show['seriesfull']), $this->pdo->escapeString($show['season']), $this->pdo->escapeString($show['episode']), $tvairdate, $relid)); }
/** * Write an NZB to the hard drive for a single release. * * @param int $relID The id of the release in the DB. * @param string $relGuid The guid of the release. * @param string $name The name of the release. * @param string $cTitle The name of the category this release is in. * * @return bool Have we successfully written the NZB to the hard drive? * * @access public */ public function writeNZBforReleaseId($relID, $relGuid, $name, $cTitle) { $path = $this->buildNZBPath($relGuid, $this->nzbSplitLevel, true) . $relGuid . '.nzb.gz'; $fp = gzopen($path, 'wb7'); if ($fp) { $nzb_guid = ''; gzwrite($fp, sprintf($this->_nzbHeadString, htmlspecialchars($cTitle, ENT_QUOTES, 'utf-8'), htmlspecialchars($name, ENT_QUOTES, 'utf-8'))); $binaries = $this->pdo->queryDirect($this->_binariesQuery . $relID . ' ORDER BY name'); if ($binaries instanceof \Traversable) { foreach ($binaries as $binary) { $poster = htmlspecialchars($binary['fromname'], ENT_QUOTES, 'utf-8'); if ($binary instanceof \Traversable) { foreach ($binary as $bin) { // Buffer segment writes, increases performance. $string = ''; $parts = $this->pdo->queryDirect(sprintf($this->_partsQuery, $bin['id'])); if ($parts instanceof \Traversable) { foreach ($parts as $part) { if ($nzb_guid === '') { $nzb_guid = $part['messageid']; } $string .= ' <segment bytes="' . $part['size'] . '" number="' . $part['partnumber'] . '">' . htmlspecialchars($part['messageid'], ENT_QUOTES, 'utf-8') . "</segment>\n"; } } gzwrite($fp, '<file poster="' . $poster . '" date="' . $bin['udate'] . '" subject="' . htmlspecialchars($bin['name'], ENT_QUOTES, 'utf-8') . ' (1/' . $bin['totalparts'] . ")\">\n <groups>\n <group>" . $bin['groupname'] . "</group>\n </groups>\n <segments>\n" . $string . " </segments>\n</file>\n"); } } } } gzwrite($fp, '</nzb>'); gzclose($fp); if (is_file($path)) { $this->pdo->queryExec(sprintf(' UPDATE releases SET nzbstatus = %d %s WHERE id = %d', NZB::NZB_ADDED, $nzb_guid === '' ? '' : ', nzb_guid = UNHEX( ' . $this->pdo->escapestring(md5($nzb_guid)) . ' )', $relID)); // Chmod to fix issues some users have with file permissions. chmod($path, 0777); return true; } else { echo "ERROR: {$path} does not exist.\n"; } } return false; }
function create_guids($live, $delete = false) { $pdo = new Settings(); $consoletools = new \ConsoleTools(['ColorCLI' => $pdo->log]); $timestart = TIME(); $relcount = $deleted = $total = 0; $relrecs = false; if ($live == "true") { $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC")); } else { if ($live == "limited") { $relrecs = $pdo->queryDirect(sprintf("SELECT id, guid FROM releases WHERE nzbstatus = 1 AND nzb_guid IS NULL ORDER BY id DESC LIMIT 10000")); } } if ($relrecs) { $total = $relrecs->rowCount(); } if ($total > 0) { echo $pdo->log->header("Creating nzb_guids for " . number_format($total) . " releases."); $releases = new \Releases(['Settings' => $pdo]); $nzb = new \NZB($pdo); $releaseImage = new \ReleaseImage($pdo); $reccnt = 0; if ($relrecs instanceof \Traversable) { foreach ($relrecs as $relrec) { $reccnt++; $nzbpath = $nzb->getNZBPath($relrec['guid']); if ($nzbpath !== false) { $nzbfile = Utility::unzipGzipFile($nzbpath); if ($nzbfile) { $nzbfile = @simplexml_load_string($nzbfile); } if (!$nzbfile) { if (isset($delete) && $delete == 'delete') { //echo "\n".$nzb->NZBPath($relrec['guid'])." is not a valid xml, deleting release.\n"; $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); $deleted++; } continue; } $binary_names = []; foreach ($nzbfile->file as $file) { $binary_names[] = $file["subject"]; } if (count($binary_names) == 0) { if (isset($delete) && $delete == 'delete') { //echo "\n".$nzb->NZBPath($relrec['guid'])." has no binaries, deleting release.\n"; $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); $deleted++; } continue; } asort($binary_names); foreach ($nzbfile->file as $file) { if ($file["subject"] == $binary_names[0]) { $segment = $file->segments->segment; $nzb_guid = md5($segment); $pdo->queryExec("UPDATE releases set nzb_guid = UNHEX(" . $pdo->escapestring($nzb_guid) . ") WHERE id = " . $relrec["id"]); $relcount++; $consoletools->overWritePrimary("Created: [" . $deleted . "] " . $consoletools->percentString($reccnt, $total) . " Time:" . $consoletools->convertTimer(TIME() - $timestart)); break; } } } else { if (isset($delete) && $delete == 'delete') { //echo $pdo->log->primary($nzb->NZBPath($relrec['guid']) . " does not have an nzb, deleting."); $releases->deleteSingle(['g' => $relrec['guid'], 'i' => $relrec['id']], $nzb, $releaseImage); } } } } if ($relcount > 0) { echo "\n"; } echo $pdo->log->header("Updated " . $relcount . " release(s). This script ran for " . $consoletools->convertTime(TIME() - $timestart)); } else { echo $pdo->log->info('Query time: ' . $consoletools->convertTime(TIME() - $timestart)); exit($pdo->log->info("No releases are missing the guid.")); } }