diff --git a/src/Code/Converters/LrcConverter.php b/src/Code/Converters/LrcConverter.php index 5530aeb..0325958 100644 --- a/src/Code/Converters/LrcConverter.php +++ b/src/Code/Converters/LrcConverter.php @@ -11,7 +11,10 @@ class LrcConverter implements ConverterContract public function canParseFileContent($file_content) { - return preg_match(self::$regexp . 's', $file_content) === 1; + // only select when there is text after the timestamp + // do not select files that have timestamp and text somewhere on the other line + $regex = rtrim(self::$regexp, '/') . ' *[\p{L}]+' . '/s'; + return preg_match($regex, $file_content) === 1; } public function fileContentToInternalFormat($file_content) diff --git a/tests/formats/LrcTest.php b/tests/formats/LrcTest.php index 08749c1..4cf188e 100644 --- a/tests/formats/LrcTest.php +++ b/tests/formats/LrcTest.php @@ -1,6 +1,6 @@ assertTrue($converter::class === LrcConverter::class); } + public function testNotLrc() // let other converter handle invalid lrc + { + $content = '[00:02:35] +Tere Vaaste Falak Se +Main Chaand Launga +Solah Satrah Sitaare +Sang Baandh Launga + +[00:02:51] +Tere Vaaste Falak Se +Main Chaand Launga +Solah Satrah Sitaare +Sang Baandh Launga'; + $converter = Helpers::getConverterByFileContent($content); + $this->assertTrue($converter::class !== LrcConverter::class); + } + public function testParsesLrc() { $expected = (new Subtitles())->loadFromFile('./tests/files/lrc.lrc')->getInternalFormat();