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 MPLAYERINPUTFORMAT_H 0009 #define MPLAYERINPUTFORMAT_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 MPlayerInputFormat : public InputFormat 0019 { 0020 friend class FormatManager; 0021 0022 protected: 0023 MPlayerInputFormat() 0024 : InputFormat($("MPlayer"), QStringList($("mpl"))) 0025 {} 0026 0027 bool parseSubtitles(Subtitle &subtitle, const QString &data) const override 0028 { 0029 staticRE$(lineRE, "(^|\n)(\\d+),(\\d+),0,([^\n]+)[^\n]", REu | REi); 0030 0031 const double fps = subtitle.framesPerSecond(); 0032 0033 QRegularExpressionMatchIterator itLine = lineRE.globalMatch(data); 0034 if(!itLine.hasNext()) 0035 return false; 0036 0037 do { 0038 const QRegularExpressionMatch mLine = itLine.next(); 0039 const Time showTime(static_cast<long>((mLine.captured(1).toLong() / fps) * 1000)); 0040 const Time hideTime(static_cast<long>((mLine.captured(2).toLong() / fps) * 1000)); 0041 const QString text = mLine.captured(3).replace(QChar('|'), QChar('\n')); 0042 0043 SubtitleLine *line = new SubtitleLine(showTime, hideTime); 0044 line->primaryDoc()->setPlainText(text); 0045 subtitle.insertLine(line); 0046 } while(itLine.hasNext()); 0047 0048 return true; 0049 } 0050 }; 0051 } 0052 0053 #endif