Use new argument parser API
This commit is contained in:
parent
dfd00a9214
commit
0743d4f764
|
@ -17,6 +17,10 @@ set(DBUS_FILES
|
|||
org.mpris.MediaPlayer2.Player.xml
|
||||
)
|
||||
|
||||
set(DOC_FILES
|
||||
README.md
|
||||
)
|
||||
|
||||
# meta data
|
||||
set(META_PROJECT_NAME dbus-soundrecorder)
|
||||
set(META_APP_NAME "D-Bus Sound Recorder")
|
||||
|
@ -25,7 +29,7 @@ set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
|||
set(META_APP_DESCRIPTION "Records sound from Pulse Audio with ffmpeg while watching D-Bus to determine tracks and meta information.")
|
||||
set(META_VERSION_MAJOR 1)
|
||||
set(META_VERSION_MINOR 2)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_VERSION_PATCH 2)
|
||||
|
||||
# find c++utilities
|
||||
find_package(c++utilities 4.0.0 REQUIRED)
|
||||
|
|
36
main.cpp
36
main.cpp
|
@ -20,39 +20,39 @@ int main(int argc, char *argv[])
|
|||
SET_APPLICATION_INFO;
|
||||
ArgumentParser parser;
|
||||
HelpArgument helpArg(parser);
|
||||
Argument recordArg("record", "r", "starts recording");
|
||||
Argument recordArg("record", 'r', "starts recording");
|
||||
recordArg.setDenotesOperation(true);
|
||||
Argument applicationArg("application", "a", "specifies the application providing meta information via D-Bus interface");
|
||||
Argument applicationArg("application", 'a', "specifies the application providing meta information via D-Bus interface");
|
||||
applicationArg.setRequired(true);
|
||||
applicationArg.setValueNames({"name"});
|
||||
applicationArg.setRequiredValueCount(1);
|
||||
Argument sinkArg("sink", "s", "specifies the Pulse Audio sink to be recorded (see pactl list short sinks)");
|
||||
Argument sinkArg("sink", 's', "specifies the Pulse Audio sink to be recorded (see pactl list short sinks)");
|
||||
sinkArg.setValueNames({"sink"});
|
||||
sinkArg.setRequiredValueCount(1);
|
||||
sinkArg.setCombinable(true);
|
||||
Argument ffmpegInputOptions("ffmpeg-input-options", "i", "specifies options for the ffmpeg input device");
|
||||
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");
|
||||
Argument targetDirArg("target-dir", 't', "specifies the target directory");
|
||||
targetDirArg.setValueNames({"path"});
|
||||
targetDirArg.setRequiredValueCount(1);
|
||||
targetDirArg.setCombinable(true);
|
||||
Argument targetExtArg("target-extension", "e", "specifies the target extension (default is .m4a)");
|
||||
Argument targetExtArg("target-extension", 'e', "specifies the target extension (default is .m4a)");
|
||||
targetExtArg.setValueNames({"extension"});
|
||||
targetExtArg.setRequiredValueCount(1);
|
||||
targetExtArg.setCombinable(true);
|
||||
Argument ignorePlaybackStatusArg("ignore-playback-status", nullptr, "ignores the playback status (does not call PlaybackStatus())");
|
||||
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");
|
||||
Argument ffmpegBinArg("ffmpeg-bin", 'f', "specifies the path to the ffmpeg binary");
|
||||
ffmpegBinArg.setValueNames({"path"});
|
||||
ffmpegBinArg.setRequiredValueCount(1);
|
||||
ffmpegBinArg.setCombinable(true);
|
||||
Argument ffmpegOptions("ffmpeg-options", "o", "specifies options for ffmpeg");
|
||||
Argument ffmpegOptions("ffmpeg-options", 'o', "specifies options for ffmpeg");
|
||||
ffmpegOptions.setValueNames({"options"});
|
||||
ffmpegOptions.setRequiredValueCount(1);
|
||||
ffmpegOptions.setCombinable(true);
|
||||
recordArg.setSecondaryArguments({&applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions});
|
||||
parser.setMainArguments({&recordArg, &helpArg});
|
||||
recordArg.setSubArguments({&applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions});
|
||||
parser.setMainArguments({&helpArg, &recordArg});
|
||||
parser.setIgnoreUnknownArguments(false);
|
||||
// parse command line arguments
|
||||
try {
|
||||
|
@ -67,26 +67,26 @@ int main(int argc, char *argv[])
|
|||
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().data()), ignorePlaybackStatusArg.isPresent());
|
||||
PlayerWatcher watcher(QString::fromLocal8Bit(applicationArg.values().front()), ignorePlaybackStatusArg.isPresent());
|
||||
FfmpegLauncher ffmpeg(watcher);
|
||||
// pass specified args to ffmpeg launcher
|
||||
if(sinkArg.isPresent()) {
|
||||
ffmpeg.setSink(QString::fromLocal8Bit(sinkArg.values().front().data()));
|
||||
ffmpeg.setSink(QString::fromLocal8Bit(sinkArg.values().front()));
|
||||
}
|
||||
if(ffmpegInputOptions.isPresent()) {
|
||||
ffmpeg.setFFmpegInputOptions(QString::fromLocal8Bit(ffmpegInputOptions.values().front().data()));
|
||||
ffmpeg.setFFmpegInputOptions(QString::fromLocal8Bit(ffmpegInputOptions.values().front()));
|
||||
}
|
||||
if(ffmpegBinArg.isPresent()) {
|
||||
ffmpeg.setFFmpegBinary(QString::fromLocal8Bit(ffmpegBinArg.values().front().data()));
|
||||
ffmpeg.setFFmpegBinary(QString::fromLocal8Bit(ffmpegBinArg.values().front()));
|
||||
}
|
||||
if(ffmpegOptions.isPresent()) {
|
||||
ffmpeg.setFFmpegOptions(QString::fromLocal8Bit(ffmpegOptions.values().front().data()));
|
||||
ffmpeg.setFFmpegOptions(QString::fromLocal8Bit(ffmpegOptions.values().front()));
|
||||
}
|
||||
if(targetDirArg.isPresent()) {
|
||||
ffmpeg.setTargetDir(QString::fromLocal8Bit(targetDirArg.values().front().data()));
|
||||
ffmpeg.setTargetDir(QString::fromLocal8Bit(targetDirArg.values().front()));
|
||||
}
|
||||
if(targetExtArg.isPresent()) {
|
||||
ffmpeg.setTargetExtension(QString::fromLocal8Bit(targetExtArg.values().front().data()));
|
||||
ffmpeg.setTargetExtension(QString::fromLocal8Bit(targetExtArg.values().front()));
|
||||
}
|
||||
// enter app loop
|
||||
return app.exec();
|
||||
|
|
Loading…
Reference in New Issue