Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Multimedia
Kdenlive
Commits
45042d1a
Commit
45042d1a
authored
Nov 20, 2022
by
Jean-Baptiste Mardelle
Browse files
Fix incorrect loading of subtitle with two dots.
BUG: 461995
FIXED-IN: 22.12.0
parent
fcb24a4c
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/bin/model/subtitlemodel.cpp
View file @
45042d1a
...
...
@@ -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"
;
...
...
tests/dataset/01.sbv
0 → 100644
View file @
45042d1a
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,…
tests/dataset/01.vtt
0 → 100644
View file @
45042d1a
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
tests/dataset/02.srt
View file @
45042d1a
...
...
@@ -13,3 +13,4 @@ Ce test de sous-titres
4
--> 00:00:35,000
Bravo
tests/dataset/subs-with-two-dots.srt
0 → 100644
View file @
45042d1a
1
00:00:45,600 --> 00:00:55,600
4:14 bravo
2
00:01:05,600 --> 00:01:15,600
bravo
tests/subtitlestest.cpp
View file @
45042d1a
...
...
@@ -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
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment