diff options
author | Miguel Borges de Freitas <92enen@gmail.com> | 2024-07-08 09:53:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-08 09:53:03 +0100 |
commit | 78bc17d21abc4a11b51b1232bd6a5951747c8ab3 (patch) | |
tree | e7c25bc0765e83b0b9c6f5546df3b37d3d1b4d08 | |
parent | fece0d4a20998163e03eedcbb5d7bead225d059d (diff) | |
parent | 95f0748b158bdac2df3ccf75e59bc25293b8da82 (diff) |
Merge pull request #25442 from CastagnaIT/ass_detect
[DVDFactorySubtitle] Improved ASS format detection
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDSubtitles/DVDFactorySubtitle.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDFactorySubtitle.cpp b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDFactorySubtitle.cpp index 51270337c6..6f922cd02f 100644 --- a/xbmc/cores/VideoPlayer/DVDSubtitles/DVDFactorySubtitle.cpp +++ b/xbmc/cores/VideoPlayer/DVDSubtitles/DVDFactorySubtitle.cpp @@ -20,6 +20,12 @@ #include <cstring> #include <memory> +#include <regex> + +namespace +{ +constexpr const char* ASS_SCRIPT_TYPE_RE = "^ScriptType:\\s*v4\\.00\\+?"; +} CDVDSubtitleParser* CDVDFactorySubtitle::CreateParser(std::string& strFile) { @@ -32,6 +38,8 @@ CDVDSubtitleParser* CDVDFactorySubtitle::CreateParser(std::string& strFile) return nullptr; } + const std::regex reAssScriptType{ASS_SCRIPT_TYPE_RE}; + for (int t = 0; t < 256; t++) { if (pStream->ReadLine(line)) @@ -55,10 +63,9 @@ CDVDSubtitleParser* CDVDFactorySubtitle::CreateParser(std::string& strFile) return new CDVDSubtitleParserVplayer(std::move(pStream), strFile); } else if (!StringUtils::CompareNoCase(line, "!: This is a Sub Station Alpha v", 32) || - !StringUtils::CompareNoCase(line, "ScriptType: v4.00", 17) || - !StringUtils::CompareNoCase(line, "Dialogue: Marked", 16) || - !StringUtils::CompareNoCase(line, "Dialogue: ", 10) || - !StringUtils::CompareNoCase(line, "[Events]", 8)) + std::regex_match(line, reAssScriptType) || + !StringUtils::CompareNoCase(line, "[Events]", 8) || + !StringUtils::CompareNoCase(line, "Dialogue:", 9)) { return new CDVDSubtitleParserSSA(std::move(pStream), strFile); } |