瀏覽代碼

improve handling of unknown non-UTF8 EAC logs

tags/0.9.3
itismadness 4 年之前
父節點
當前提交
d34e1151af
共有 5 個文件被更改,包括 231 次插入0 次删除
  1. +1
    -0
      src/Parser/EAC/Translator.php
  2. +6
    -0
      src/Util.php
  3. +30
    -0
      tests/Parser/EAC/TranslatorTest.php
  4. 二進制
     
  5. +194
    -0
      tests/logs/eac/originals/en_8.log

+ 1
- 0
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) {


+ 6
- 0
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;


+ 30
- 0
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']);
}
}

二進制
查看文件


+ 194
- 0
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

Loading…
取消
儲存