#include "QHandbrake.h"
#include <QFile>
#include <QProcess>

QHandbrake::QHandbrake(QObject *parent)
    : QObject{parent}
{

}

uint8_t QHandbrake::setPath(QString pathIn)
{
    if (QFile::exists(pathIn)) {
        exePath = pathIn;
        return 1;
    }
    return -1;
}

uint8_t QHandbrake::startEncode()
{
    //HandBrakeCLI -i "../%TITLE%/%TITLE% - 4k.mkv" -o "../%TITLE%/temp/handbrake.mkv" -f av_mkv -m -e x265_10bit --encoder-preset slower -q 20 --encoder-profile auto --all-audio -E copy --audio-copy-mask aac,eac3,dts,ac3,truehd,dtshd,mp3 --crop-mode auto --auto-anamorphic --all-subtitles > "../%TITLE%/temp/log.txt"
    QStringList arguments;
    arguments << "-i" <<  "Cosmos.mkv" << "-o" << "test.mkv" << "-f" << "av_mkv" << "-m" << "-e" << "x265_10bit" << "--encoder-preset" << "slower" << "-q" << "20" << "--encoder-profile" << "auto" << "--all-audio" << "-E" << "copy" << "--audio-copy-mask" << "aac,eac3,dts,ac3,truehd,dtshd,mp3" << "--crop-mode" << "auto" << "--auto-anamorphic" << "--all-subtitles";

    QProcess *myProcess = new QProcess(parent());
    myProcess->start(exePath, arguments);

    return true;
}
