|
|
@ -45,8 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com |
|
|
|
#include "hsStream.h" |
|
|
|
#include "hsStream.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "../plStatusLog/plStatusLog.h" |
|
|
|
#include "../plStatusLog/plStatusLog.h" |
|
|
|
#include "../pnUtils/Private/pnUtPath.h" |
|
|
|
#include "../pnUtils/pnUtils.h" |
|
|
|
#include "../pnUtils/Private/pnUtStr.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <regex> |
|
|
|
#include <regex> |
|
|
|
|
|
|
|
|
|
|
@ -55,8 +54,15 @@ static const std::regex timingsRegex("^(\\d{2}):(\\d{2}):(\\d{2}),(\\d{3}) --> ( |
|
|
|
|
|
|
|
|
|
|
|
bool plSrtFileReader::ReadFile() |
|
|
|
bool plSrtFileReader::ReadFile() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
char path[MAX_PATH]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strchr(fAudioFileName, '\\') != nil) |
|
|
|
|
|
|
|
strcpy(path, fAudioFileName); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
sprintf(path, "sfx\\%s", fAudioFileName); |
|
|
|
|
|
|
|
|
|
|
|
wchar srtPathUnicode[MAX_PATH]; |
|
|
|
wchar srtPathUnicode[MAX_PATH]; |
|
|
|
StrToUnicode(srtPathUnicode, fAudioFileName, arrsize(srtPathUnicode)); |
|
|
|
StrToUnicode(srtPathUnicode, path, arrsize(srtPathUnicode)); |
|
|
|
PathSetExtension(srtPathUnicode, srtPathUnicode, L".sub", arrsize(srtPathUnicode)); |
|
|
|
PathSetExtension(srtPathUnicode, srtPathUnicode, L".sub", arrsize(srtPathUnicode)); |
|
|
|
|
|
|
|
|
|
|
|
if (PathDoesFileExist(srtPathUnicode)) { |
|
|
|
if (PathDoesFileExist(srtPathUnicode)) { |
|
|
@ -70,7 +76,7 @@ bool plSrtFileReader::ReadFile() |
|
|
|
uint32_t subtitleNumber = 0; |
|
|
|
uint32_t subtitleNumber = 0; |
|
|
|
uint32_t subtitleStartTimeMs = 0; |
|
|
|
uint32_t subtitleStartTimeMs = 0; |
|
|
|
uint32_t subtitleEndTimeMs = 0; |
|
|
|
uint32_t subtitleEndTimeMs = 0; |
|
|
|
char* line; |
|
|
|
char line[4096]; |
|
|
|
std::string speakerName; |
|
|
|
std::string speakerName; |
|
|
|
std::string subtitleText; |
|
|
|
std::string subtitleText; |
|
|
|
std::cmatch matches; |
|
|
|
std::cmatch matches; |
|
|
@ -78,8 +84,7 @@ bool plSrtFileReader::ReadFile() |
|
|
|
for (unsigned int lnCounter = 0; !srtFileStream.AtEnd(); lnCounter++) { |
|
|
|
for (unsigned int lnCounter = 0; !srtFileStream.AtEnd(); lnCounter++) { |
|
|
|
if (lnCounter % 4 == 0 && srtFileStream.ReadLn(line)) { |
|
|
|
if (lnCounter % 4 == 0 && srtFileStream.ReadLn(line)) { |
|
|
|
subtitleNumber = std::stoul(line); |
|
|
|
subtitleNumber = std::stoul(line); |
|
|
|
} |
|
|
|
} else if (lnCounter % 4 == 1 && srtFileStream.ReadLn(line)) { |
|
|
|
else if (lnCounter % 4 == 1 && srtFileStream.ReadLn(line)) { |
|
|
|
|
|
|
|
if (std::regex_match(line, matches, timingsRegex)) { |
|
|
|
if (std::regex_match(line, matches, timingsRegex)) { |
|
|
|
if (matches.size() < 9) { |
|
|
|
if (matches.size() < 9) { |
|
|
|
// add error message and ensure this subtitle line won't be added to the entries
|
|
|
|
// add error message and ensure this subtitle line won't be added to the entries
|
|
|
@ -107,8 +112,7 @@ bool plSrtFileReader::ReadFile() |
|
|
|
subtitleEndTimeMs += std::stoul(matches[8].str()); |
|
|
|
subtitleEndTimeMs += std::stoul(matches[8].str()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (lnCounter % 4 == 2 && srtFileStream.ReadLn(line)) { |
|
|
|
else if (lnCounter % 4 == 2 && srtFileStream.ReadLn(line)) { |
|
|
|
|
|
|
|
if (std::regex_match(line, matches, speakerTextRegex)) { |
|
|
|
if (std::regex_match(line, matches, speakerTextRegex)) { |
|
|
|
if (matches.size() < 5) { |
|
|
|
if (matches.size() < 5) { |
|
|
|
// add error message and ensure this subtitle line won't be added to the entries
|
|
|
|
// add error message and ensure this subtitle line won't be added to the entries
|
|
|
@ -124,8 +128,7 @@ bool plSrtFileReader::ReadFile() |
|
|
|
subtitleText = matches[5]; |
|
|
|
subtitleText = matches[5]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (lnCounter % 4 == 3 && subtitleNumber > 0 && subtitleStartTimeMs >= 0 && subtitleEndTimeMs >= 0 && !subtitleText.empty()) { |
|
|
|
else if (lnCounter % 4 == 3 && subtitleNumber > 0 && subtitleStartTimeMs >= 0 && subtitleEndTimeMs >= 0 && !subtitleText.empty()) { |
|
|
|
|
|
|
|
// entry is complete, add to the queue and reset our temp variables
|
|
|
|
// entry is complete, add to the queue and reset our temp variables
|
|
|
|
if (!speakerName.empty()) |
|
|
|
if (!speakerName.empty()) |
|
|
|
fEntries.emplace_back(plSrtEntry(subtitleNumber, subtitleStartTimeMs, subtitleEndTimeMs, std::move(subtitleText), std::move(speakerName))); |
|
|
|
fEntries.emplace_back(plSrtEntry(subtitleNumber, subtitleStartTimeMs, subtitleEndTimeMs, std::move(subtitleText), std::move(speakerName))); |
|
|
|