From c1bd4522b02c1977650ecfcfd98681e1cc5668d9 Mon Sep 17 00:00:00 2001 From: itismadness Date: Mon, 29 Sep 2025 03:53:43 +0000 Subject: [PATCH] Update logchecker to 0.14.2 / add rescore-logs script --- app/Torrent.php | 4 +- bin/rescore-logs | 104 +++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 2 +- composer.lock | 14 +++---- 4 files changed, 114 insertions(+), 10 deletions(-) create mode 100755 bin/rescore-logs diff --git a/app/Torrent.php b/app/Torrent.php index ad3331c25..202deacb1 100644 --- a/app/Torrent.php +++ b/app/Torrent.php @@ -186,7 +186,7 @@ class Torrent extends TorrentAbstract { return $affected; } - public function rescoreLog(int $logId, Logfile $logfile, string $version): int { + public function rescoreLog(int $logId, Logfile $logfile, string $version, bool $modifyLogscore = true): int { self::$db->prepared_query(" UPDATE torrents_logs SET Score = ?, `Checksum` = ?, ChecksumState = ?, Ripper = ?, RipperVersion = ?, @@ -197,7 +197,7 @@ class Torrent extends TorrentAbstract { $logfile->language(), $logfile->detailsAsString(), $version, $this->id, $logId ); - if (self::$db->affected_rows() > 0) { + if ($modifyLogscore && self::$db->affected_rows() > 0) { return $this->modifyLogscore(); } return 0; diff --git a/bin/rescore-logs b/bin/rescore-logs new file mode 100755 index 000000000..a33e65622 --- /dev/null +++ b/bin/rescore-logs @@ -0,0 +1,104 @@ +#! /usr/bin/env php +] [--offset ] + */ + +namespace Gazelle; + +use OrpheusNET\Logchecker\Logchecker; + +require_once(__DIR__ . '/../lib/bootstrap.php'); + +$dryRun = in_array('--dry-run', $argv); + +$limitKey = array_find_key($argv, fn ($val) => $val === '--limit'); +if ($limitKey !== null) { + if (!isset($argv[$limitKey + 1]) || !is_numeric($argv[$limitKey + 1])) { + die("If you specify --limit, you must also provide a numeric limit\n"); + } + $limit = (int)$argv[$limitKey + 1]; +} else { + $limit = PHP_INT_MAX; +} + +$offsetKey = array_find_key($argv, fn ($val) => $val === '--offset'); +if ($offsetKey !== null) { + if (!isset($argv[$offsetKey + 1]) || !is_numeric($argv[$offsetKey + 1])) { + die("If you specify --offset, you must also provide a numeric offset\n"); + } + $offset = (int)$argv[$offsetKey + 1]; +} else { + $offset = 0; +} + +$logcheckerVersion = Logchecker::getLogcheckerVersion(); +[$major, $minor, $patch] = explode('.', $logcheckerVersion); + +$db = DB::DB(); + +$db->prepared_query(" + SELECT TorrentID, LogID, Score + FROM torrents_logs + WHERE + LogcheckerVersion = '' + OR CAST(SUBSTRING_INDEX(LogcheckerVersion, '.', 1) AS UNSIGNED) < ? + OR ( + CAST(SUBSTRING_INDEX(LogcheckerVersion, '.', 1) AS UNSIGNED) = ? AND + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(LogcheckerVersion, '.', 2), '.', -1) AS UNSIGNED) < ? + ) + OR ( + CAST(SUBSTRING_INDEX(LogcheckerVersion, '.', 1) AS UNSIGNED) = ? AND + CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(LogcheckerVersion, '.', 2), '.', -1) AS UNSIGNED) = ? AND + CAST(SUBSTRING_INDEX(LogcheckerVersion, '.', -1) AS UNSIGNED) < ? + ) + ORDER BY LogID, TorrentID + LIMIT ? OFFSET ? +", $major, $major, $minor, $major, $minor, $patch, $limit, $offset); + +$i = 0; +/** @var Torrent|null */ +$torrent = null; + +while (true) { + $row = $db->next_row(MYSQLI_NUM); + if (!$row) { + if (!$dryRun) { + $torrent?->modifyLogscore(); + } + break; + } + + [$torrentId, $logId, $score] = $row; + + if (!$torrent || $torrent->id() !== $torrentId) { + if (!$dryRun) { + $torrent?->modifyLogscore(); + } + $torrent = new Torrent($torrentId); + $rescore = false; + } + + $logpath = new File\RipLog($torrent->id, $logId)->path(); + $logfile = new Logfile($logpath, basename($logpath)); + + echo sprintf( + "%d: torrent %d - log %d (%s): %d -> %d\n", + $i, + $torrent->id(), + $logId, + $logpath, + $score, + $logfile->score() + ); + + if (!$dryRun) { + new File\RipLogHTML($torrent->id, $logId)->put($logfile->text()); + $torrent->rescoreLog($logId, $logfile, Logchecker::getLogcheckerVersion(), false); + } + + $i++; +} diff --git a/composer.json b/composer.json index 01d52e6ae..60047e37a 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "maennchen/zipstream-php": "^3.1", "monero-integrations/monerophp": "dev-master#25d4c5838b35cbf1fb55170b831e895681a7410a", "orpheusnet/bencode-torrent": "^1.3.0", - "orpheusnet/logchecker": "^0.14.1", + "orpheusnet/logchecker": "^0.14.2", "protonlabs/bitcoin": "^1.0", "robmorgan/phinx": "^0.16", "robthree/twofactorauth": "^1.8.2", diff --git a/composer.lock b/composer.lock index 9924e05c2..33ab05811 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "29ff371adb62c2570ef7860b15ef1953", + "content-hash": "321c857e2383b26015bc2d0ac2888083", "packages": [ { "name": "bacon/bacon-qr-code", @@ -1202,16 +1202,16 @@ }, { "name": "orpheusnet/logchecker", - "version": "0.14.1", + "version": "0.14.2", "source": { "type": "git", "url": "https://github.com/OPSnet/Logchecker.git", - "reference": "e899a7819eaeda759f3122b80f5f6a20d8ec33d6" + "reference": "66d93bc78dabf9f6a1a14dbf2753ee90569887d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/OPSnet/Logchecker/zipball/e899a7819eaeda759f3122b80f5f6a20d8ec33d6", - "reference": "e899a7819eaeda759f3122b80f5f6a20d8ec33d6", + "url": "https://api.github.com/repos/OPSnet/Logchecker/zipball/66d93bc78dabf9f6a1a14dbf2753ee90569887d7", + "reference": "66d93bc78dabf9f6a1a14dbf2753ee90569887d7", "shasum": "" }, "require": { @@ -1257,9 +1257,9 @@ "description": "Logchecker for validating logs generated from supported ripping programs (like EAC and XLD)", "support": { "issues": "https://github.com/OPSnet/Logchecker/issues", - "source": "https://github.com/OPSnet/Logchecker/tree/0.14.1" + "source": "https://github.com/OPSnet/Logchecker/tree/0.14.2" }, - "time": "2025-08-14T21:17:05+00:00" + "time": "2025-09-14T02:12:48+00:00" }, { "name": "pleonasm/merkle-tree",