File indexing completed on 2024-12-22 04:40:09

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 YOUTUBECAPTIONSOUTPUTFORMAT_H
0009 #define YOUTUBECAPTIONSOUTPUTFORMAT_H
0010 
0011 #include "core/richtext/richdocument.h"
0012 #include "core/subtitleiterator.h"
0013 #include "formats/outputformat.h"
0014 #include "helpers/common.h"
0015 
0016 namespace SubtitleComposer {
0017 class YouTubeCaptionsOutputFormat : public OutputFormat
0018 {
0019     friend class FormatManager;
0020 
0021 protected:
0022     QString dumpSubtitles(const Subtitle &subtitle, bool primary) const override
0023     {
0024         QString ret;
0025 
0026         for(SubtitleIterator it(subtitle); it.current(); ++it) {
0027             const SubtitleLine *ln = it.current();
0028             const Time ts = ln->showTime();
0029             const Time th = ln->hideTime();
0030             ret += QString::asprintf("%d:%02d:%02d.%03d,%d:%02d:%02d.%03d\n",
0031                 ts.hours(), ts.minutes(), ts.seconds(), ts.millis(),
0032                 th.hours(), th.minutes(), th.seconds(), th.millis());
0033 
0034             const RichString text = (primary ? ln->primaryDoc() : ln->secondaryDoc())->toRichText();
0035 
0036             // TODO does the format actually supports styled text?
0037             // if so, does it use standard HTML style tags?
0038             ret += text.richString();
0039 
0040             ret += $("\n\n");
0041         }
0042         return ret;
0043     }
0044 
0045     YouTubeCaptionsOutputFormat()
0046         : OutputFormat($("YouTube Captions"), QStringList($("sbv")))
0047     {}
0048 };
0049 }
0050 
0051 #endif