/** * Update a release. */ public function update($id, $name, $searchname, $fromname, $category, $parts, $grabs, $size, $posteddate, $addeddate, $rageid, $seriesfull, $season, $episode, $imdbid, $anidbid, $tvdbid, $consoleinfoid) { $this->pdo->queryExec(sprintf("UPDATE releases SET name=%s, searchname=%s, fromname=%s, categoryid=%d, totalpart=%d, grabs=%d, size=%s, postdate=%s, adddate=%s, rageid=%d, seriesfull=%s, season=%s, episode=%s, imdbid=%d, anidbid=%d, tvdbid=%d,consoleinfoid=%d WHERE id = %d", $this->pdo->escapeString($name), $this->pdo->escapeString($searchname), $this->pdo->escapeString($fromname), $category, $parts, $grabs, $this->pdo->escapeString($size), $this->pdo->escapeString($posteddate), $this->pdo->escapeString($addeddate), $rageid, $this->pdo->escapeString($seriesfull), $this->pdo->escapeString($season), $this->pdo->escapeString($episode), $imdbid, $anidbid, $tvdbid, $consoleinfoid, $id)); $this->sphinxSearch->updateReleaseSearchName($id, $searchname); }
function processAnAnimeRelease($results) { $pdo = $this->pdo; $ri = new \ReleaseImage($this->pdo); if (count($results) > 0) { if ($this->echooutput) { $this->pdo->log->doEcho('Processing ' . count($results) . " anime releases.", true); } $sphinx = new \SphinxSearch(); foreach ($results as $arr) { // clean up the release name to ensure we get a good chance at getting a valid filename $cleanFilename = $this->cleanFilename($arr['searchname']); // Get a release name to update the DB with, this is more than the title as it includes group size ... or worst case the same as the title $getReleaseName = $this->getReleaseName($arr['searchname']); if ($this->echooutput) { $this->pdo->log->doEcho("\tProcessing Anime entitled: " . $getReleaseName['title'], true); } // get anidb number for the title of the naime $anidbID = $this->getanidbID($cleanFilename['title']); if (!$anidbID) { $newTitle = $pdo->escapeString($getReleaseName['title']); // no anidb ID found so set what we know and exit $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, anidbid = %d, rageid = %d WHERE id = %d', $newTitle, -1, -2, $arr['id'])); $sphinx->updateReleaseSearchName($newTitle, $arr['id']); continue; } if ($this->echooutput) { $this->pdo->log->doEcho('Looking up: ' . $arr['searchname'], true); } $AniDBAPIArray = $this->getAnimeInfo($anidbID); if ($AniDBAPIArray['anidbid']) { // if this anime is found postprocess it $epno = explode('|', $AniDBAPIArray['epnos']); $airdate = explode('|', $AniDBAPIArray['airdates']); $episodetitle = explode('|', $AniDBAPIArray['episodetitles']); // locate the episode if possible for ($i = 0; $i < count($epno); $i++) { if ($cleanFilename['epno'] == $epno[$i]) { $offset = $i; break; } else { $offset = -1; } } // update the airdate if teh episode is found $airdate = isset($airdate[$offset]) ? $airdate[$offset] : $AniDBAPIArray['startdate']; // update the episode title if teh episdoe is found $episodetitle = isset($episodetitle[$offset]) ? $episodetitle[$offset] : $cleanFilename['epno']; //set the TV title to that of the episode $tvtitle = $episodetitle !== 'Complete Movie' && $episodetitle !== $cleanFilename['epno'] ? $cleanFilename['epno'] . ' - ' . $episodetitle : $episodetitle; if ($this->echooutput) { $this->pdo->log->doEcho('- found ' . $AniDBAPIArray['anidbid'], true); } // lastly update the information, we also want a better readable name, AKA search name so we can use the title we cleaned $newTitle = $pdo->escapeString($getReleaseName['title']); $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, episode = %s, tvtitle = %s, tvairdate = %s, anidbid = %d, rageid = %d WHERE id = %d', $newTitle, $pdo->escapeString($cleanFilename['epno']), $pdo->escapeString($tvtitle), $pdo->escapeString($airdate), $AniDBAPIArray['anidbid'], -2, $arr['id'])); $sphinx->updateReleaseSearchName($newTitle, $arr['id']); } else { // if the anime was not found, just simply update the search name $newTitle = $pdo->escapeString($getReleaseName['title']); $sphinx->updateReleaseSearchName($newTitle, $arr['id']); $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s, anidbid = %d WHERE id = %d', $newTitle, $AniDBAPIArray['anidbid'], $arr['id'])); } } // foreach if ($this->echooutput) { $this->pdo->log->doEcho('Processed ' . count($results) . " anime releases.", true); } } else { if ($this->echooutput) { $this->pdo->log->doEcho($this->pdo->log->header('No anime releases to process.')); } } }
if (isset($argv[1]) && $argv[1] == "full") { $res = $pdo->query("SELECT releases.id, releases.name, releases.fromname, releases.size, groups.name AS gname FROM releases INNER JOIN groups ON releases.group_id = groups.id"); if (count($res) > 0) { echo $pdo->log->header("Going to recreate all search names, recategorize them and fix the names with namefixer, this can take a while."); $done = 0; $timestart = time(); $consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]); $rc = new ReleaseCleaning($pdo); foreach ($res as $row) { $newname = $rc->releaseCleaner($row['name'], $row['fromname'], $row['size'], $row['gname']); if (is_array($newname)) { $newname = $newname['cleansubject']; } $newname = $pdo->escapeString($newname); $pdo->queryExec(sprintf("UPDATE releases SET searchname = %s WHERE id = %d", $newname, $row['id'])); $sphinx->updateReleaseSearchName($newname, $row['id']); $done++; $consoletools->overWritePrimary("Renaming:" . $consoletools->percentString($done, count($res))); } $timenc = $consoletools->convertTime(time() - $timestart); echo $pdo->log->primary("\n" . $done . " releases renamed in " . $timenc . ".\nNow the releases will be recategorized."); $releases = new ProcessReleases(['Settings' => $pdo, 'ConsoleTools' => $consoletools, 'ReleaseCleaning' => $rc]); $releases->resetCategorize(); $categorized = $releases->categorizeRelease("name", ""); $timecat = $consoletools->convertTime(time() - $timestart); echo $pdo->log->primary("\nFinished categorizing " . $categorized . " releases in " . $timecat . ".\nFinally, the releases will be fixed using the NFO/filenames."); $namefixer = new NameFixer(['Settings' => $pdo, 'ConsoleTools' => $consoletools]); $namefixer->fixNamesWithNfo(2, 1, 1, 1, $show); $namefixer->fixNamesWithFiles(2, 1, 1, 1, $show); $timetotal = $consoletools->convertTime(time() - $timestart); echo $pdo->log->header("\nFinished recreating search names / recategorizing / refixing names in " . $timetotal);
$rename = false; if ($argv[3] === 'true') { $rename = true; } require_once dirname(__FILE__) . '/../../../www/config.php'; $pdo = new Settings(); $group = $pdo->queryOneRow(sprintf('SELECT id FROM groups WHERE name = %s', $pdo->escapeString($argv[1]))); if ($group === false) { exit('No group with name ' . $argv[1] . ' found in the database.'); } $releases = $pdo->query(sprintf('SELECT name, searchname, fromname, size, id FROM releases WHERE group_id = %d %s ORDER BY postdate LIMIT %d', $group['id'], $category, $argv[2])); if (count($releases) === 0) { exit('No releases found in your database for group ' . $argv[1] . PHP_EOL); } $RC = new ReleaseCleaning($pdo); $sphinx = new SphinxSearch(); foreach ($releases as $release) { $newName = $RC->releaseCleaner($release['name'], $release['fromname'], $release['size'], $argv[1]); if (is_array($newName)) { $newName = $newName['cleansubject']; } if ($newName !== $release['searchname']) { echo 'Old name: ' . $release['searchname'] . PHP_EOL; echo 'New name: ' . $newName . PHP_EOL . PHP_EOL; if ($rename === true) { $newName = $pdo->escapeString($newName); $pdo->queryExec(sprintf('UPDATE releases SET searchname = %s WHERE id = %d', $newName, $release['id'])); $sphinx->updateReleaseSearchName($release['id'], $newName); } } }