diff --git a/src/Parser/EAC/Translator.php b/src/Parser/EAC/Translator.php index e78d908..45f2dd2 100644 --- a/src/Parser/EAC/Translator.php +++ b/src/Parser/EAC/Translator.php @@ -54,6 +54,7 @@ class Translator file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR . 'master.json'), true ); + foreach ($languages as $code => $lang) { foreach ($lang['eac_strings'] as $eac_string) { if (preg_match('/' . preg_quote($eac_string, "/") . '/ui', $log) === 1) { diff --git a/src/Util.php b/src/Util.php index 5b36730..ccc5a84 100644 --- a/src/Util.php +++ b/src/Util.php @@ -41,6 +41,12 @@ class Util if ($results['charset'] !== 'utf-8' && $results['confidence'] > 0.7) { // $log = mb_convert_encoding($log, 'UTF-8', $results['charset']); $log = iconv($results['charset'], 'UTF-8', $log); + } elseif ($results['charset'] !== 'utf-8' && $results['confidence'] > 0.3) { + // If we've got a poor confidence on our decoding, we just use a generic + // ISO-8859-1 as that covers a decent range of things that people would + // inadvertently re-encode a log into. I seriously cannot express how + // much I hate how EAC does not use always UTF-8. + $log = iconv('ISO-8859-1', 'UTF-8', $log); } } return $log; diff --git a/tests/Parser/EAC/TranslatorTest.php b/tests/Parser/EAC/TranslatorTest.php index a1cea0e..e587288 100644 --- a/tests/Parser/EAC/TranslatorTest.php +++ b/tests/Parser/EAC/TranslatorTest.php @@ -6,6 +6,7 @@ namespace OrpheusNET\Logchecker\Parser\EAC; use FilesystemIterator; use OrpheusNET\Logchecker\Exception\UnknownLanguageException; +use OrpheusNET\Logchecker\Util; use PHPUnit\Framework\TestCase; class TranslatorTest extends TestCase @@ -51,4 +52,33 @@ class TranslatorTest extends TestCase ) ); } + + public function englishLogProvider() + { + return array_map( + function ($file) { + return [$file]; + }, + array_filter( + scandir(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'eac', 'originals'])), + function ($file) { + return substr($file, 0, 2) === 'en'; + } + ) + ); + } + + /** + * @dataProvider englishLogProvider + */ + public function testEnglishLanguage(string $file) + { + $logPath = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'eac', 'originals', $file]); + $log = file_get_contents($logPath); + $log = Util::decodeEncoding($log, $logPath); + $langDetails = Translator::getLanguage($log); + $this->assertSame('en', $langDetails['code']); + $this->assertSame('English', $langDetails['name']); + $this->assertSame('English', $langDetails['name_english']); + } } diff --git a/tests/logs/eac/originals/en_7.log b/tests/logs/eac/originals/en_7.log new file mode 100644 index 0000000..6e51a1b Binary files /dev/null and b/tests/logs/eac/originals/en_7.log differ diff --git a/tests/logs/eac/originals/en_8.log b/tests/logs/eac/originals/en_8.log new file mode 100644 index 0000000..cf9d843 --- /dev/null +++ b/tests/logs/eac/originals/en_8.log @@ -0,0 +1,194 @@ +EAC extraction logfile from 20. November 2006, 20:20 for CD +Banco del Mutuo Soccorso / Seguendo le Tracce + +Used drive : _NEC DVD+-RW ND-6450A Adapter: 1 ID: 0 +Read mode : Secure with NO C2, accurate stream, disable cache +Read offset correction : 594 +Overread into Lead-In and Lead-Out : No + +Used output format : Internal WAV Routines + 44.100 Hz; 16 Bit; Stereo + +Other options : + Fill up missing offset samples with silence : Yes + Delete leading and trailing silent blocks : No + Installed external ASPI interface + + +Track 1 + Filename C:\Documents and Settings\user\Documenti\file flac\01R.I.P. (english version).wav + + Pre-gap length 0:00:02.00 + + Peak level 97.7 % + Track quality 100.0 % + Test CRC EC43BAD3 + Copy CRC EC43BAD3 + Copy OK + +Track 2 + Filename C:\Documents and Settings\user\Documenti\file flac\02L'albero del pane.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 70584B1D + Copy CRC 70584B1D + Copy OK + +Track 3 + Filename C:\Documents and Settings\user\Documenti\file flac\03La danza dei grandi rettili.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 4E17BAEF + Copy CRC 4E17BAEF + Copy OK + +Track 4 + Filename C:\Documents and Settings\user\Documenti\file flac\04Passaggio.wav + + Peak level 44.4 % + Track quality 100.0 % + Test CRC D76BE99A + Copy CRC D76BE99A + Copy OK + +Track 5 + Filename C:\Documents and Settings\user\Documenti\file flac\05Non mi rompete.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 826A9F81 + Copy CRC 826A9F81 + Copy OK + +Track 6 + Filename C:\Documents and Settings\user\Documenti\file flac\06Dopo... niente pių č lo stesso.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC CFB6C6BA + Copy CRC CFB6C6BA + Copy OK + +Track 7 + Filename C:\Documents and Settings\user\Documenti\file flac\07Traccia II.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC D7BAF9A2 + Copy CRC D7BAF9A2 + Copy OK + +Track 8 + Filename C:\Documents and Settings\user\Documenti\file flac\08Metamorfosi.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC BBB2254A + Copy CRC BBB2254A + Copy OK + +No errors occured + + +End of status report + +------------------------------------------------------------ + +EAC extraction logfile from 20. November 2006, 21:08 for CD +Banco del Mutuo Soccorso / Seguendo le Tracce + +Used drive : _NEC DVD+-RW ND-6450A Adapter: 1 ID: 0 +Read mode : Secure with NO C2, accurate stream, disable cache +Read offset correction : 594 +Overread into Lead-In and Lead-Out : No + +Used output format : C:\Programmi\FLAC\flac.exe (User Defined Encoder) + 320 kBit/s + Additional command line options : -V --replay-gain -8 -T "artist=%a" -T "title=%t" -T "album=%g" -T "date=%y" -T "tracknumber=%n" -T "genre=%m" %s + +Other options : + Fill up missing offset samples with silence : Yes + Delete leading and trailing silent blocks : No + Installed external ASPI interface + + +Track 1 + Filename C:\Documents and Settings\user\Documenti\file flac\01R.I.P. (english version).wav + + Pre-gap length 0:00:02.00 + + Peak level 97.7 % + Track quality 100.0 % + Test CRC EC43BAD3 + Copy CRC EC43BAD3 + Copy OK + +Track 2 + Filename C:\Documents and Settings\user\Documenti\file flac\02L'albero del pane.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 70584B1D + Copy CRC 70584B1D + Copy OK + +Track 3 + Filename C:\Documents and Settings\user\Documenti\file flac\03La danza dei grandi rettili.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 4E17BAEF + Copy CRC 4E17BAEF + Copy OK + +Track 4 + Filename C:\Documents and Settings\user\Documenti\file flac\04Passaggio.wav + + Peak level 44.4 % + Track quality 100.0 % + Test CRC D76BE99A + Copy CRC D76BE99A + Copy OK + +Track 5 + Filename C:\Documents and Settings\user\Documenti\file flac\05Non mi rompete.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC 826A9F81 + Copy CRC 826A9F81 + Copy OK + +Track 6 + Filename C:\Documents and Settings\user\Documenti\file flac\06Dopo... niente pių č lo stesso.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC CFB6C6BA + Copy CRC CFB6C6BA + Copy OK + +Track 7 + Filename C:\Documents and Settings\user\Documenti\file flac\07Traccia II.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC D7BAF9A2 + Copy CRC D7BAF9A2 + Copy OK + +Track 8 + Filename C:\Documents and Settings\user\Documenti\file flac\08Metamorfosi.wav + + Peak level 97.7 % + Track quality 100.0 % + Test CRC BBB2254A + Copy CRC BBB2254A + Copy OK + +No errors occured + + +End of status report