File indexing completed on 2024-12-22 04:40:08
0001 /* 0002 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 0003 SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef MPLAYER2INPUTFORMAT_H 0009 #define MPLAYER2INPUTFORMAT_H 0010 0011 #include "core/richtext/richdocument.h" 0012 #include "helpers/common.h" 0013 #include "formats/inputformat.h" 0014 0015 #include <QRegularExpression> 0016 0017 namespace SubtitleComposer { 0018 class MPlayer2InputFormat : public InputFormat 0019 { 0020 friend class FormatManager; 0021 0022 protected: 0023 MPlayer2InputFormat() 0024 : InputFormat($("MPlayer2"), QStringList($("mpl"))) 0025 {} 0026 0027 bool parseSubtitles(Subtitle &subtitle, const QString &data) const override 0028 { 0029 staticRE$(lineRE, "\\[(\\d+)\\]\\[(\\d+)\\]([^\n]+)\n", REu | REi); 0030 0031 QRegularExpressionMatchIterator itLine = lineRE.globalMatch(data); 0032 if(!itLine.hasNext()) 0033 return false; 0034 0035 do { 0036 const QRegularExpressionMatch mLine = itLine.next(); 0037 const Time showTime(mLine.captured(1).toInt() * 100); 0038 const Time hideTime(mLine.captured(2).toInt() * 100); 0039 const QString text = mLine.captured(3).replace(QChar('|'), QChar('\n')); 0040 0041 SubtitleLine *line = new SubtitleLine(showTime, hideTime); 0042 line->primaryDoc()->setPlainText(text); 0043 subtitle.insertLine(line); 0044 } while(itLine.hasNext()); 0045 0046 return true; 0047 } 0048 }; 0049 } 0050 0051 #endif