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 MPLAYEROUTPUTFORMAT_H
0009 #define MPLAYEROUTPUTFORMAT_H
0010 
0011 #include "formats/outputformat.h"
0012 #include "core/richtext/richdocument.h"
0013 #include "core/subtitleiterator.h"
0014 
0015 namespace SubtitleComposer {
0016 class MPlayerOutputFormat : public OutputFormat
0017 {
0018     friend class FormatManager;
0019 
0020 protected:
0021     QString dumpSubtitles(const Subtitle &subtitle, bool primary) const override
0022     {
0023         QString ret;
0024 
0025         double framesPerSecond = subtitle.framesPerSecond();
0026 
0027         for(SubtitleIterator it(subtitle); it.current(); ++it) {
0028             const SubtitleLine *line = it.current();
0029 
0030             QString text = (primary ? line->primaryDoc() : line->secondaryDoc())->toPlainText();
0031 
0032             ret += m_lineBuilder.arg(static_cast<long>((line->showTime().toMillis() / 1000.0) * framesPerSecond + 0.5))
0033                     .arg(static_cast<long>((line->hideTime().toMillis() / 1000.0) * framesPerSecond + 0.5))
0034                     .arg(text.replace('\n', '|'));
0035         }
0036         return ret;
0037     }
0038 
0039     MPlayerOutputFormat() :
0040         OutputFormat(QStringLiteral("MPlayer"), QStringList(QStringLiteral("mpl"))),
0041         m_lineBuilder(QStringLiteral("%1,%2,0,%3\n"))
0042     {}
0043 
0044     const QString m_lineBuilder;
0045 };
0046 }
0047 
0048 #endif