Commit 45042d1a authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix incorrect loading of subtitle with two dots.

BUG: 461995
FIXED-IN: 22.12.0
parent fcb24a4c
......@@ -191,14 +191,15 @@ void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool ext
while (stream.readLineInto(&line)) {
line = line.trimmed();
// qDebug()<<"Turn: "<<turn;
// qDebug()<<"Line: "<<line<<"\n";
// qDebug()<<"Line: "<<line;
if (!line.isEmpty()) {
if (!turn) {
// index=atoi(line.toStdString().c_str());
turn++;
continue;
}
if (line.contains(QLatin1String("-->")) || line.contains(rx)) {
// Check if position has already been read
if (endPos == startPos && (line.contains(QLatin1String("-->")) || line.contains(rx))) {
timeLine += line;
srtTime = timeLine.split(separator);
if (srtTime.count() > endIndex) {
......@@ -221,17 +222,22 @@ void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool ext
} else {
if (endPos > startPos) {
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment, undo, redo, false);
// qDebug()<<"Adding Subtitle: \n Start time: "<<start<<"\n End time: "<<end<<"\n Text: "<<comment;
// qDebug() << "Adding Subtitle: \n Start time: " << start << "\n End time: " << end << "\n Text: " << comment;
} else {
qDebug() << "===== INVALID SUBTITLE FOUND: " << start << "-" << end << ", " << comment;
}
// reinitialize
comment.clear();
timeLine.clear();
startPos = endPos;
r = 0;
turn = defaultTurn;
}
}
// Ensure last subtitle is read
if (endPos > startPos && !comment.isEmpty()) {
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment, undo, redo, false);
}
srtFile.close();
} else if (filePath.endsWith(QLatin1String(".ass"))) {
qDebug() << "ass File";
......
0:02:30.000,0:04:46.000
It si very unlileky that you do
a simple strange thing.
0:05:42.000,0:05:53.000
Welcome to the party.
0:06:51.000,0:06:55.000
By for now I will not answer
any more question,…
WEBVTT
00:00:00.600 --> 00:00:02.000
This is the first title
00:00:02.400 --> 00:00:04.400
This is the end
......@@ -13,3 +13,4 @@ Ce test de sous-titres
4
--> 00:00:35,000
Bravo
1
00:00:45,600 --> 00:00:55,600
4:14 bravo
2
00:01:05,600 --> 00:01:15,600
bravo
......@@ -28,9 +28,9 @@ TEST_CASE("Read subtitle file", "[Subtitles]")
// We mock the project class so that the undoStack function returns our undoStack
Mock<KdenliveDoc> docMock;
When(Method(docMock, getDocumentProperty)).AlwaysDo([](const QString &name, const QString &defaultValue) {
Q_UNUSED(name)
// Q_UNUSED(name)
Q_UNUSED(defaultValue)
qDebug() << "Intercepted call";
qDebug() << "Intercepted call:" << name;
return QStringLiteral("");
});
KdenliveDoc &mockedDoc = docMock.get();
......@@ -154,6 +154,38 @@ TEST_CASE("Read subtitle file", "[Subtitles]")
subtitleModel->importSubtitle(subtitleFile);
const QList<SubtitledTime> allSubs = subtitleModel->getAllSubtitles();
CHECK(allSubs.at(0).subtitle().toStdString() == "three spaces");
subtitleModel->removeAllSubtitles();
REQUIRE(subtitleModel->rowCount() == 0);
}
SECTION("Load SBV subtitle file")
{
QString subtitleFile = sourcesPath + "/dataset/01.sbv";
subtitleModel->importSubtitle(subtitleFile);
// Ensure the 3 dialogues are loaded
REQUIRE(subtitleModel->rowCount() == 3);
subtitleModel->removeAllSubtitles();
REQUIRE(subtitleModel->rowCount() == 0);
}
SECTION("Load VTT subtitle file")
{
QString subtitleFile = sourcesPath + "/dataset/01.vtt";
subtitleModel->importSubtitle(subtitleFile);
// Ensure the 2 dialogues are loaded
REQUIRE(subtitleModel->rowCount() == 2);
subtitleModel->removeAllSubtitles();
REQUIRE(subtitleModel->rowCount() == 0);
}
SECTION("Load SRT subtitle file with two dots")
{
QString subtitleFile = sourcesPath + "/dataset/subs-with-two-dots.srt";
subtitleModel->importSubtitle(subtitleFile);
// Ensure the 2 dialogues are loaded
REQUIRE(subtitleModel->rowCount() == 2);
subtitleModel->removeAllSubtitles();
REQUIRE(subtitleModel->rowCount() == 0);
}
binModel->clean();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment