benlipp / srt-parser

A PHP library to parse SRT files
Other
21 stars 12 forks source link

Parsing badly encoded srt files. #15

Open hondnl opened 6 years ago

hondnl commented 6 years ago

When parsing a srt file and it is not properly encoded into utf-8 it will remove lines.

Example :

144
00:05:43,673 --> 00:05:45,206
Have you ever had déjà vu?

I solved it by using https://github.com/neitanod/forceutf8 before parsing the srt.

You might want to implement it ?

Thanks for your project !

araeuchle commented 6 years ago

for all others wondering how to do it:

    $content = Encoding::fixUTF8(\File::get($filePath));

    $parsedContent = $parser
        ->loadString($content)
        ->parse();

i also solved this with the forceutf8 package.

Edit: Oh its Laravel based in my case.

firecentaur commented 4 years ago

Hi there, I also noticed that if a subtitle text has \n\n at the end of it, the next subtitle text is included as the text. This causes an error:

example: the Vanderhall is a great option.\n\n28\n00:01:32,70 --> 00:01:34,70\nNow for the second car of our lineup,\n\n29\n00:01:34,70 --> 00:01:37,80\nat just under $20,000,the Polaris Slingshot\n\n30\n00:01:37,80 --> 00:01:40,60\nhas the least expensive\nstarting price of the group,\n\n31\n00:01:40,60 --> 00:01:42,110\nbut it comes with the most technology. Any ideas how to fix this?