dbus-soundrecorder/main.cpp

96 lines
4.3 KiB
C++
Raw Permalink Normal View History

2016-08-29 20:48:19 +02:00
#include "ffmpeglauncher.h"
2017-05-01 03:39:45 +02:00
#include "playerwatcher.h"
2016-08-29 20:48:19 +02:00
#include "resources/config.h"
#include <c++utilities/application/argumentparser.h>
#include <QCoreApplication>
#include <iostream>
using namespace std;
2019-06-10 23:01:04 +02:00
using namespace CppUtilities;
2016-08-29 20:48:19 +02:00
using namespace DBusSoundRecorder;
int main(int argc, char *argv[])
{
// setup the argument parser
SET_APPLICATION_INFO;
ArgumentParser parser;
HelpArgument helpArg(parser);
Argument recordArg("record", 'r', "starts recording");
recordArg.setDenotesOperation(true);
Argument applicationArg("application", 'a', "specifies the application providing meta information via D-Bus interface");
applicationArg.setRequired(true);
2017-05-01 03:39:45 +02:00
applicationArg.setValueNames({ "name" });
2016-08-29 20:48:19 +02:00
applicationArg.setRequiredValueCount(1);
Argument sinkArg("sink", 's', "specifies the Pulse Audio sink to be recorded (see pactl list short sinks)");
2017-05-01 03:39:45 +02:00
sinkArg.setValueNames({ "sink" });
2016-08-29 20:48:19 +02:00
sinkArg.setRequiredValueCount(1);
sinkArg.setCombinable(true);
Argument ffmpegInputOptions("ffmpeg-input-options", 'i', "specifies options for the ffmpeg input device");
ffmpegInputOptions.setRequiredValueCount(1);
ffmpegInputOptions.setCombinable(true);
Argument targetDirArg("target-dir", 't', "specifies the target directory");
2017-05-01 03:39:45 +02:00
targetDirArg.setValueNames({ "path" });
2016-08-29 20:48:19 +02:00
targetDirArg.setRequiredValueCount(1);
targetDirArg.setCombinable(true);
Argument targetExtArg("target-extension", 'e', "specifies the target extension (default is .m4a)");
2017-05-01 03:39:45 +02:00
targetExtArg.setValueNames({ "extension" });
2016-08-29 20:48:19 +02:00
targetExtArg.setRequiredValueCount(1);
targetExtArg.setCombinable(true);
Argument ignorePlaybackStatusArg("ignore-playback-status", '\0', "ignores the playback status (does not call PlaybackStatus())");
ignorePlaybackStatusArg.setCombinable(true);
Argument ffmpegBinArg("ffmpeg-bin", 'f', "specifies the path to the ffmpeg binary");
2017-05-01 03:39:45 +02:00
ffmpegBinArg.setValueNames({ "path" });
2016-08-29 20:48:19 +02:00
ffmpegBinArg.setRequiredValueCount(1);
ffmpegBinArg.setCombinable(true);
Argument ffmpegOptions("ffmpeg-options", 'o', "specifies options for ffmpeg");
2017-05-01 03:39:45 +02:00
ffmpegOptions.setValueNames({ "options" });
2016-08-29 20:48:19 +02:00
ffmpegOptions.setRequiredValueCount(1);
ffmpegOptions.setCombinable(true);
2017-05-01 03:39:45 +02:00
recordArg.setSubArguments(
{ &applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions });
parser.setMainArguments({ &helpArg, &recordArg });
2016-08-29 20:48:19 +02:00
// parse command line arguments
2019-06-10 23:01:04 +02:00
parser.parseArgs(argc, argv);
2016-08-29 20:48:19 +02:00
try {
2017-05-01 03:39:45 +02:00
if (recordArg.isPresent()) {
2016-08-29 20:48:19 +02:00
// start watching/recording
cerr << "Watching MPRIS service of the specified application \"" << applicationArg.values().front() << "\" ..." << endl;
// create app loop, player watcher and ffmpeg launcher
QCoreApplication app(argc, argv);
PlayerWatcher watcher(QString::fromLocal8Bit(applicationArg.values().front()), ignorePlaybackStatusArg.isPresent());
FfmpegLauncher ffmpeg(watcher);
// pass specified args to ffmpeg launcher
2017-05-01 03:39:45 +02:00
if (sinkArg.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setSink(QString::fromLocal8Bit(sinkArg.values().front()));
}
2017-05-01 03:39:45 +02:00
if (ffmpegInputOptions.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setFFmpegInputOptions(QString::fromLocal8Bit(ffmpegInputOptions.values().front()));
}
2017-05-01 03:39:45 +02:00
if (ffmpegBinArg.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setFFmpegBinary(QString::fromLocal8Bit(ffmpegBinArg.values().front()));
}
2017-05-01 03:39:45 +02:00
if (ffmpegOptions.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setFFmpegOptions(QString::fromLocal8Bit(ffmpegOptions.values().front()));
}
2017-05-01 03:39:45 +02:00
if (targetDirArg.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setTargetDir(QString::fromLocal8Bit(targetDirArg.values().front()));
}
2017-05-01 03:39:45 +02:00
if (targetExtArg.isPresent()) {
2016-08-29 20:48:19 +02:00
ffmpeg.setTargetExtension(QString::fromLocal8Bit(targetExtArg.values().front()));
}
// enter app loop
return app.exec();
2017-05-01 03:39:45 +02:00
} else if (!helpArg.isPresent()) {
2016-08-29 20:48:19 +02:00
cerr << "No operation specified." << endl;
return 2;
}
2017-05-01 03:39:45 +02:00
} catch (const runtime_error &e) {
2016-08-29 20:48:19 +02:00
cerr << "Fatal error: " << e.what() << endl;
return 3;
}
}