Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Kdenlive
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
252
Issues
252
List
Boards
Labels
Service Desk
Milestones
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Multimedia
Kdenlive
Commits
35985076
Commit
35985076
authored
Jun 07, 2020
by
Sashmita Raghav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add srt parser to model
parent
a0db1142
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
156 additions
and
0 deletions
+156
-0
src/bin/model/subtitlemodel.cpp
src/bin/model/subtitlemodel.cpp
+112
-0
src/bin/model/subtitlemodel.hpp
src/bin/model/subtitlemodel.hpp
+44
-0
No files found.
src/bin/model/subtitlemodel.cpp
0 → 100644
View file @
35985076
#include "subtitlemodel.hpp"
#include "core.h"
#include "project/projectmanager.h"
SubtitleModel
::
SubtitleModel
(
std
::
weak_ptr
<
DocUndoStack
>
undo_stack
,
QObject
*
parent
)
:
QAbstractListModel
(
parent
)
{
}
std
::
shared_ptr
<
SubtitleModel
>
SubtitleModel
::
getModel
()
{
return
pCore
->
projectManager
()
->
getSubtitleModel
();
}
void
SubtitleModel
::
parseSubtitle
()
{
//QModelIndex index;
//int paramName = m_model->data(index, AssetParameterModel::NameRole).toInt();
//QString filePath(m_asset->get(paramName.toUtf8().constData()));
QString
filePath
=
"path_to_srt_file.srt"
;
QString
start
,
end
,
comment
;
GenTime
startPos
,
endPos
;
QString
timeLine
;
int
index
=
0
,
turn
=
0
,
r
=
0
;
/*
* turn = 0 -> Add subtitle number
* turn = 1 -> Add string to timeLine
* turn > 1 -> Add string to completeLine
*/
if
(
filePath
.
isEmpty
())
return
;
if
(
filePath
.
contains
(
".srt"
))
qDebug
()
<<
"srt File"
;
QFile
srtFile
(
filePath
);
if
(
!
srtFile
.
exists
()
&&
!
srtFile
.
open
(
QIODevice
::
ReadOnly
)){
qDebug
()
<<
" File not found "
<<
filePath
;
return
;
}
{
//parsing srt file
QTextStream
stream
(
&
srtFile
);
QString
line
;
while
(
stream
.
readLineInto
(
&
line
))
{
line
=
line
.
simplified
();
if
(
line
.
compare
(
""
))
{
if
(
!
turn
)
{
index
=
atoi
(
line
.
toStdString
().
c_str
());
turn
++
;
continue
;
}
if
(
line
.
contains
(
"-->"
))
{
timeLine
+=
line
;
QStringList
srtTime
;
srtTime
=
timeLine
.
split
(
' '
);
start
=
srtTime
[
0
];
startPos
=
stringtoTime
(
start
);
end
=
srtTime
[
2
];
startPos
=
stringtoTime
(
start
);
}
else
{
r
++
;
if
(
comment
!=
""
)
comment
+=
" "
;
if
(
r
==
1
)
// only one line
comment
+=
line
;
else
comment
=
comment
+
"
\r
"
+
line
;
}
turn
++
;
}
else
{
addSubtitle
(
index
,
startPos
,
endPos
,
comment
);
//reinitialize
comment
=
timeLine
=
""
;
turn
=
0
;
r
=
0
;
}
}
}
}
GenTime
SubtitleModel
::
stringtoTime
(
QString
str
)
{
QStringList
total
,
secs
;
int
hours
=
0
,
mins
=
0
,
seconds
=
0
,
ms
=
0
;
double
total_sec
=
0
;
total
=
str
.
split
(
':'
);
hours
=
atoi
(
total
[
0
].
toStdString
().
c_str
());
mins
=
atoi
(
total
[
1
].
toStdString
().
c_str
());
secs
=
total
[
2
].
split
(
','
);
seconds
=
atoi
(
secs
[
0
].
toStdString
().
c_str
());
ms
=
atoi
(
secs
[
1
].
toStdString
().
c_str
());
total_sec
=
hours
*
3600
+
mins
*
60
+
seconds
+
ms
*
0.001
;
GenTime
pos
=
*
new
GenTime
(
total_sec
);
return
pos
;
}
\ No newline at end of file
src/bin/model/subtitlemodel.hpp
0 → 100644
View file @
35985076
#ifndef SUBTITLEMODEL_HPP
#define SUBTITLEMODEL_HPP
#include "definitions.h"
#include "gentime.h"
#include "undohelper.hpp"
#include <QAbstractListModel>
#include <QReadWriteLock>
#include <array>
#include <map>
#include <memory>
#include <mlt++/MltProperties.h>
class
DocUndoStack
;
class
AssetParameterModel
;
/* @brief This class is the model for a list of subtitles.
*/
class
SubtitleModel
:
public
QAbstractListModel
{
Q_OBJECT
public:
/* @brief Construct a subtitle list bound to the timeline */
SubtitleModel
(
std
::
weak_ptr
<
DocUndoStack
>
undo_stack
,
QObject
*
parent
=
nullptr
);
/** @brief Function that parses through a subtitle file */
void
parseSubtitle
();
void
addSubtitle
(
int
ix
,
GenTime
start
,
GenTime
end
,
QString
str
);
GenTime
stringtoTime
(
QString
str
);
private:
std
::
weak_ptr
<
DocUndoStack
>
m_undoStack
;
std
::
map
<
GenTime
,
std
::
pair
<
QString
,
GenTime
>>
m_subtitleList
;
//To get subtitle file from effects parameter:
//std::unique_ptr<Mlt::Properties> m_asset;
//std::shared_ptr<AssetParameterModel> m_model;
};
Q_DECLARE_METATYPE
(
SubtitleModel
*
)
#endif // SUBTITLEMODEL_HPP
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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