| 1 | /***************************************************************************** |
| 2 | ** QNapi |
| 3 | ** Copyright (C) 2008-2017 Piotr KrzemiĆski <[email protected]> |
| 4 | ** |
| 5 | ** This program is free software; you can redistribute it and/or modify |
| 6 | ** it under the terms of the GNU General Public License as published by |
| 7 | ** the Free Software Foundation; either version 2 of the License, or |
| 8 | ** (at your option) any later version. |
| 9 | ** |
| 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
| 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | ** |
| 13 | *****************************************************************************/ |
| 14 | |
| 15 | #ifndef SUBTITLECONVERTER_H |
| 16 | #define SUBTITLECONVERTER_H |
| 17 | |
| 18 | #include "movieinfo/movieinfoprovider.h" |
| 19 | #include "subconvert/subtitleformatsregistry.h" |
| 20 | |
| 21 | #include <QSharedPointer> |
| 22 | #include <QString> |
| 23 | #include <QStringList> |
| 24 | #include <functional> |
| 25 | |
| 26 | class SubtitleConverter { |
| 27 | public: |
| 28 | SubtitleConverter( |
| 29 | QSharedPointer<const SubtitleFormatsRegistry> subtitleFormatsRegistry, |
| 30 | QSharedPointer<const MovieInfoProvider> movieInfoProvider, |
| 31 | bool skipConvertAds); |
| 32 | |
| 33 | QString detectFormat(const QString &subtitleFile) const; |
| 34 | QString detectFormat(const QStringList &subtitleLines) const; |
| 35 | |
| 36 | bool convertSubtitles(QString subtitleFile, QString targetFormatName, |
| 37 | QString targetFileName, double movieFPS, |
| 38 | double fpsRatio, double delayOffset) const; |
| 39 | |
| 40 | bool convertSubtitles(QString subtitleFile, QString targetFormatName, |
| 41 | QString targetFileName, QString movieFile) const; |
| 42 | |
| 43 | bool convertSubtitles(QString subtitleFile, QString targetFormatName, |
| 44 | QString targetFileName, |
| 45 | std::function<double()> determineFPS, |
| 46 | double fpsRatio = 1.0, double delayOffset = 0.0) const; |
| 47 | |
| 48 | private: |
| 49 | QSharedPointer<const SubtitleFormatsRegistry> subtitleFormatsRegistry; |
| 50 | QSharedPointer<const MovieInfoProvider> movieInfoProvider; |
| 51 | bool skipConvertAds; |
| 52 | |
| 53 | long ts2frame(long ts, double frameRate) const; |
| 54 | long frame2ts(long frame, double frameRate) const; |
| 55 | |
| 56 | QStringList readFile(const QString &filename, QString encoding, |
| 57 | long atMostLines = 0) const; |
| 58 | bool writeFile(const QString &filename, QString encoding, |
| 59 | const QStringList &lines) const; |
| 60 | }; |
| 61 | |
| 62 | #endif // SUBTITLECONVERTER_H |