示例#1
0
 } else {
     $poster = $postername[0];
 }
 if (empty($postdate[0])) {
     $posteddate = $date = date("Y-m-d H:i:s");
 } else {
     $posteddate = $postdate[0];
 }
 $category = $categorize->determineCategory($cleanName, $groupID);
 // A 1% variance in size is considered the same size when the subject and poster are the same
 $minsize = $totalsize * 0.99;
 $maxsize = $totalsize * 1.01;
 // Look for match on name, poster and size
 $dupecheck = $pdo->queryOneRow(sprintf('SELECT id, guid FROM releases WHERE name = %s AND fromname = %s AND size BETWEEN %s AND %s', $pdo->escapeString($subject), $pdo->escapeString($poster), $pdo->escapeString($minsize), $pdo->escapeString($maxsize)));
 if ($dupecheck === false) {
     $relid = $releases->insertRelease(['name' => $pdo->escapeString($subject), 'searchname' => $pdo->escapeString($cleanName), 'totalpart' => $totalFiles, 'group_id' => $groupID, 'guid' => $pdo->escapeString($relguid), 'postdate' => $pdo->escapeString($posteddate), 'fromname' => $pdo->escapeString($poster), 'size' => $pdo->escapeString($totalsize), 'categoryid' => $category, 'isrenamed' => 1, 'reqidstatus' => 0, 'preid' => 0, 'nzbstatus' => NZB::NZB_ADDED]);
 }
 if ($relid === false || $dupecheck === false) {
     $nzbSkipped++;
     @unlink($nzbFile);
     flush();
 }
 if (copyNZBforImport($relguid, $nzba, $nzb, $pdo)) {
     if ($relid !== false) {
         $nzbCount++;
     }
     if ($nzbCount % 100 == 0 && $nzbCount != 0) {
         $seconds = TIME() - $time;
         $nzbsperhour = number_format(round($nzbCount / $seconds * 3600), 0);
     }
     if ($nzbCount >= $maxtoprocess && $maxtoprocess != 0) {
                    foreach ($nzbInfo->groups as $group) {
                        $group = (string) $group;
                        if (array_key_exists($group, $siteGroups)) {
                            $groupID = $siteGroups[$group];
                            $groupName = $group;
                            break;
                        }
                    }
                    if ($groupID == -1) {
                        $retval .= "Missing Group for NZB : " . $browserpostednames[$nzbFile] . " - " . join(", ", $nzbInfo->groups) . "<br/>";
                        continue;
                    }
                    $relguid = md5(uniqid());
                    $name = $releases->cleanReleaseName(str_replace(".nzb", "", $browserpostednames[$nzbFile]));
                    $catId = $cat->determineCategory($groupName, $name);
                    $relid = $releases->insertRelease($name, $nzbInfo->filecount, $groupID, $relguid, $catId, "", date("Y-m-d H:i:s", $nzbInfo->postedlast), $nzbInfo->poster, "", $page->site);
                    $db->exec(sprintf("update releases set totalpart = %d, size = %s, completion = %d, GID=%s where ID = %d", $nzbInfo->filecount, $nzbInfo->filesize, $nzbInfo->completion, $db->escapeString($nzbInfo->gid), $relid));
                    $nzbfilename = $nzb->getNZBPath($relguid, $page->site->nzbpath, true);
                    $fp = _gzopen($nzbfilename, "w");
                    if ($fp) {
                        gzwrite($fp, $nzbInfo->toNzb());
                        gzclose($fp);
                        $retval .= sprintf(" Imported %s<br/>", $name);
                    }
                }
            }
        }
    }
    $page->smarty->assign('output', $retval);
}
$page->title = "Import Nzbs";
示例#3
0
    /**
     * Create releases from complete collections.
     *
     * @param int|string $groupID (optional)
     *
     * @return int
     * @access public
     */
    public function createReleases($groupID)
    {
        $startTime = time();
        $group = $this->groups->getCBPTableNames($this->tablePerGroup, $groupID);
        $categorize = new \Categorize(['Settings' => $this->pdo]);
        $returnCount = $duplicate = 0;
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->header("Process Releases -> Create releases from complete collections."));
        }
        $this->pdo->ping(true);
        $collections = $this->pdo->queryDirect(sprintf('
				SELECT %s.*, groups.name AS gname
				FROM %s
				INNER JOIN groups ON %s.group_id = groups.id
				WHERE %s %s.filecheck = %d
				AND filesize > 0 LIMIT %d', $group['cname'], $group['cname'], $group['cname'], !empty($groupID) ? ' group_id = ' . $groupID . ' AND ' : ' ', $group['cname'], self::COLLFC_SIZED, $this->releaseCreationLimit));
        if ($this->echoCLI && $collections !== false) {
            echo $this->pdo->log->primary($collections->rowCount() . " Collections ready to be converted to releases.");
        }
        if ($collections instanceof \Traversable) {
            $preDB = new \PreDb(['Echo' => $this->echoCLI, 'Settings' => $this->pdo]);
            foreach ($collections as $collection) {
                $cleanRelName = $this->pdo->escapeString(utf8_encode(str_replace(['#', '@', '$', '%', '^', '§', '¨', '©', 'Ö'], '', $collection['subject'])));
                $fromName = $this->pdo->escapeString(utf8_encode(trim($collection['fromname'], "'")));
                // Look for duplicates, duplicates match on releases.name, releases.fromname and releases.size
                // A 1% variance in size is considered the same size when the subject and poster are the same
                $dupeCheck = $this->pdo->queryOneRow(sprintf("\n\t\t\t\t\t\tSELECT id\n\t\t\t\t\t\tFROM releases\n\t\t\t\t\t\tWHERE name = %s\n\t\t\t\t\t\tAND fromname = %s\n\t\t\t\t\t\tAND size BETWEEN '%s'\n\t\t\t\t\t\tAND '%s'", $cleanRelName, $fromName, $collection['filesize'] * 0.99, $collection['filesize'] * 1.01));
                if ($dupeCheck === false) {
                    $cleanedName = $this->releaseCleaning->releaseCleaner($collection['subject'], $collection['fromname'], $collection['filesize'], $collection['gname']);
                    if (is_array($cleanedName)) {
                        $properName = $cleanedName['properlynamed'];
                        $preID = isset($cleanerName['predb']) ? $cleanerName['predb'] : false;
                        $isReqID = isset($cleanerName['requestid']) ? $cleanerName['requestid'] : false;
                        $cleanedName = $cleanedName['cleansubject'];
                    } else {
                        $properName = true;
                        $isReqID = $preID = false;
                    }
                    if ($preID === false && $cleanedName !== '') {
                        // try to match the cleaned searchname to predb title or filename here
                        $preMatch = $preDB->matchPre($cleanedName);
                        if ($preMatch !== false) {
                            $cleanedName = $preMatch['title'];
                            $preID = $preMatch['preid'];
                            $properName = true;
                        }
                    }
                    $releaseID = $this->releases->insertRelease(['name' => $cleanRelName, 'searchname' => $this->pdo->escapeString(utf8_encode($cleanedName)), 'totalpart' => $collection['totalfiles'], 'group_id' => $collection['group_id'], 'guid' => $this->pdo->escapeString($this->releases->createGUID($cleanRelName)), 'postdate' => $this->pdo->escapeString($collection['date']), 'fromname' => $fromName, 'size' => $collection['filesize'], 'categoryid' => $categorize->determineCategory($cleanedName, $collection['group_id']), 'isrenamed' => $properName === true ? 1 : 0, 'reqidstatus' => $isReqID === true ? 1 : 0, 'preid' => $preID === false ? 0 : $preID, 'nzbstatus' => \NZB::NZB_NONE]);
                    if ($releaseID !== false) {
                        // Update collections table to say we inserted the release.
                        $this->pdo->queryExec(sprintf('
								UPDATE %s
								SET filecheck = %d, releaseid = %d
								WHERE id = %d', $group['cname'], self::COLLFC_INSERTED, $releaseID, $collection['id']));
                        $returnCount++;
                        if ($this->echoCLI) {
                            echo "Added {$returnCount} releases.\r";
                        }
                    }
                } else {
                    // The release was already in the DB, so delete the collection.
                    $this->pdo->queryExec(sprintf('
							DELETE FROM %s
							WHERE collectionhash = %s', $group['cname'], $this->pdo->escapeString($collection['collectionhash'])));
                    $duplicate++;
                }
            }
        }
        if ($this->echoCLI) {
            $this->pdo->log->doEcho($this->pdo->log->primary(PHP_EOL . number_format($returnCount) . ' Releases added and ' . number_format($duplicate) . ' duplicate collections deleted in ' . $this->consoleTools->convertTime(time() - $startTime)), true);
        }
        return $returnCount;
    }