Commit af7f1689 authored by Nathan Hinton's avatar Nathan Hinton Committed by Jean-Baptiste Mardelle
Browse files

increase the flexablilty of importing captions. See issue #1361

Allow the timestamps in the SRT files to be formatted by MM:SS:MS where before it had to be HH:MM:SS:MS
parent ddb57d5d
Pipeline #147822 passed with stage
in 5 minutes and 23 seconds
......@@ -124,14 +124,14 @@ void SubtitleModel::importSubtitle(const QString &filePath, int offset, bool ext
if (r == 1)
comment += line;
else
comment = comment + "\r" +line;
comment = comment + "\n" +line; //changed from \r
}
turn++;
} else {
if (endPos > startPos) {
addSubtitle(startPos + subtitleOffset, endPos + subtitleOffset, comment, undo, redo, false);
} else {
qDebug()<<"===== INVALID SUBTITLE ITEM FOUND: "<<start<<"-"<<end<<", "<<comment;
qDebug()<<"===== INVALID SUBTITLE FOUND: "<<start<<"-"<<end<<", "<<comment;
}
//reinitialize
comment.clear();
......@@ -288,22 +288,28 @@ GenTime SubtitleModel::stringtoTime(QString &str)
double total_sec = 0;
GenTime pos;
total = str.split(QLatin1Char(':'));
if (total.count() != 3) {
if (total.count() == 3) {
//There is an hour timestamp
hours = atoi(total.takeFirst().toStdString().c_str());
}
if (total.count() == 2) {
mins = atoi(total.at(0).toStdString().c_str());
if (total.at(1).contains(QLatin1Char('.'))) {
secs = total.at(1).split(QLatin1Char('.')); //ssa file
} else {
secs = total.at(1).split(QLatin1Char(',')); //srt file
}
if (secs.count() < 2) {
seconds = atoi(total.at(1).toStdString().c_str());
} else {
seconds = atoi(secs.at(0).toStdString().c_str());
ms = atoi(secs.at(1).toStdString().c_str());
}
} else {
// invalid time found
return GenTime();
}
hours = atoi(total.at(0).toStdString().c_str());
mins = atoi(total.at(1).toStdString().c_str());
if (total.at(2).contains(QLatin1Char('.')))
secs = total.at(2).split(QLatin1Char('.')); //ssa file
else
secs = total.at(2).split(QLatin1Char(',')); //srt file
if (secs.count() < 2) {
seconds = atoi(total.at(2).toStdString().c_str());
} else {
seconds = atoi(secs.at(0).toStdString().c_str());
ms = atoi(secs.at(1).toStdString().c_str());
}
total_sec = hours *3600 + mins *60 + seconds + ms * 0.001 ;
pos= GenTime(total_sec);
return pos;
......
Markdown is supported
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