From 09bfa6a98b1e15c418f3365f58b66f69e9f59fb6 Mon Sep 17 00:00:00 2001 From: itismadness Date: Tue, 11 Jun 2019 00:28:21 -0100 Subject: [PATCH] Fix handling of whipper logs under YAML 1.2 --- src/Command/AnalyzeCommand.php | 2 ++ src/Logchecker.php | 38 ++++++++++++++++++++++++++++++-------- src/Util.php | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Command/AnalyzeCommand.php b/src/Command/AnalyzeCommand.php index 04525bf..da48ff2 100644 --- a/src/Command/AnalyzeCommand.php +++ b/src/Command/AnalyzeCommand.php @@ -28,6 +28,8 @@ class AnalyzeCommand extends Command { $logchecker = new Logchecker(); $logchecker->new_file($filename); list($score, $details, $checksum, $log_text) = $logchecker->parse(); + $output->writeln('Ripper : ' . $logchecker->get_ripper()); + $output->writeln('Version : ' . $logchecker->get_version()); $output->writeln('Score : ' . $score); $output->writeln('Checksum: ' . ($checksum ? 'true' : 'false')); diff --git a/src/Logchecker.php b/src/Logchecker.php index c8d47f2..9665f91 100644 --- a/src/Logchecker.php +++ b/src/Logchecker.php @@ -167,6 +167,17 @@ class Logchecker { return $this->return_parse(); } + $this->RIPPER = 'whipper'; + $this->Version = explode(" ", $Yaml['Log created by'])[1]; + + // Releases before this used octal numbers for tracks in the log which + // gets messed up in parsing and we lose track data (e.g. tracks 08 and + // 09 get merged into one entry). + if (empty($this->Version) || version_compare('0.7.3', $this->Version) === 1) { + $this->account('Logs must be produced by whipper 0.7.3+', 100); + return $this->return_parse(); + } + if (!empty($Yaml['SHA-256 hash'])) { $Hash = $Yaml['SHA-256 hash']; $Lines = explode("\n", trim($this->Log)); @@ -217,15 +228,18 @@ class Logchecker { } $DefeatCache = $Yaml['Ripping phase information']['Defeat audio cache']; - if ($DefeatCache) { - $Value = 'Yes'; - $Class = 'good'; + if (is_string($DefeatCache)) { + $Value = (strtolower($DefeatCache) === 'yes') ? 'Yes' : 'No'; + $Class = (strtolower($DefeatCache) === 'yes') ? 'good' : 'bad'; } else { - $Value = 'No'; - $Class = 'bad'; - $this->account('"Defeat audio cache" should be yes', 10); + $Value = ($DefeatCache === true) ? 'true' : 'false'; + $Class = ($DefeatCache === true) ? 'good' : 'bad'; } + if ($Class === 'bad') { + $this->account('"Defeat audio cache" should be Yes/true', 10); + } + $Yaml['Ripping phase information']['Defeat audio cache'] = "{$Value}"; foreach ($Yaml['Tracks'] as $Key => $Track) { @@ -245,7 +259,7 @@ class Logchecker { $this->Log .= "Ripping phase information:\n"; foreach ($Yaml['Ripping phase information'] as $Key => $Value) { if (is_bool($Value)) { - $Value = ($Value) ? 'Yes' : 'No'; + $Value = ($Value) ? 'true' : 'false'; } $this->Log .= " {$Key}: {$Value}\n"; } @@ -254,7 +268,7 @@ class Logchecker { $this->Log .= "CD metadata:\n"; foreach ($Yaml['CD metadata'] as $Key => $Value) { if (is_bool($Value)) { - $Value = ($Value) ? 'Yes' : 'No'; + $Value = ($Value) ? 'true' : 'false'; } $this->Log .= " {$Key}: {$Value}\n"; } @@ -1464,6 +1478,14 @@ class Logchecker { ); } + function get_ripper() { + return $this->RIPPER; + } + + function get_version() { + return $this->Version; + } + public static function get_accept_values() { return ".txt,.TXT,.log,.LOG"; } diff --git a/src/Util.php b/src/Util.php index a73666c..f30c488 100644 --- a/src/Util.php +++ b/src/Util.php @@ -3,7 +3,7 @@ namespace OrpheusNET\Logchecker; class Util { - public static function commandExists($cmd) { + public static function commandExists(string $cmd) { $where = substr(strtolower(PHP_OS), 0, 3) === 'win' ? 'where' : 'command -v'; exec("{$where} {$cmd} 2>/dev/null", $output, $return_var);