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
|
org.mpris.MediaPlayer2.Player.xml
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(DOC_FILES
|
||||||
|
README.md
|
||||||
|
)
|
||||||
|
|
||||||
# meta data
|
# meta data
|
||||||
set(META_PROJECT_NAME dbus-soundrecorder)
|
set(META_PROJECT_NAME dbus-soundrecorder)
|
||||||
set(META_APP_NAME "D-Bus Sound Recorder")
|
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_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_MAJOR 1)
|
||||||
set(META_VERSION_MINOR 2)
|
set(META_VERSION_MINOR 2)
|
||||||
set(META_VERSION_PATCH 1)
|
set(META_VERSION_PATCH 2)
|
||||||
|
|
||||||
# find c++utilities
|
# find c++utilities
|
||||||
find_package(c++utilities 4.0.0 REQUIRED)
|
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;
|
SET_APPLICATION_INFO;
|
||||||
ArgumentParser parser;
|
ArgumentParser parser;
|
||||||
HelpArgument helpArg(parser);
|
HelpArgument helpArg(parser);
|
||||||
Argument recordArg("record", "r", "starts recording");
|
Argument recordArg("record", 'r', "starts recording");
|
||||||
recordArg.setDenotesOperation(true);
|
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.setRequired(true);
|
||||||
applicationArg.setValueNames({"name"});
|
applicationArg.setValueNames({"name"});
|
||||||
applicationArg.setRequiredValueCount(1);
|
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.setValueNames({"sink"});
|
||||||
sinkArg.setRequiredValueCount(1);
|
sinkArg.setRequiredValueCount(1);
|
||||||
sinkArg.setCombinable(true);
|
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.setRequiredValueCount(1);
|
||||||
ffmpegInputOptions.setCombinable(true);
|
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.setValueNames({"path"});
|
||||||
targetDirArg.setRequiredValueCount(1);
|
targetDirArg.setRequiredValueCount(1);
|
||||||
targetDirArg.setCombinable(true);
|
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.setValueNames({"extension"});
|
||||||
targetExtArg.setRequiredValueCount(1);
|
targetExtArg.setRequiredValueCount(1);
|
||||||
targetExtArg.setCombinable(true);
|
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);
|
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.setValueNames({"path"});
|
||||||
ffmpegBinArg.setRequiredValueCount(1);
|
ffmpegBinArg.setRequiredValueCount(1);
|
||||||
ffmpegBinArg.setCombinable(true);
|
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.setValueNames({"options"});
|
||||||
ffmpegOptions.setRequiredValueCount(1);
|
ffmpegOptions.setRequiredValueCount(1);
|
||||||
ffmpegOptions.setCombinable(true);
|
ffmpegOptions.setCombinable(true);
|
||||||
recordArg.setSecondaryArguments({&applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions});
|
recordArg.setSubArguments({&applicationArg, &sinkArg, &ffmpegInputOptions, &targetDirArg, &targetExtArg, &ignorePlaybackStatusArg, &ffmpegBinArg, &ffmpegOptions});
|
||||||
parser.setMainArguments({&recordArg, &helpArg});
|
parser.setMainArguments({&helpArg, &recordArg});
|
||||||
parser.setIgnoreUnknownArguments(false);
|
parser.setIgnoreUnknownArguments(false);
|
||||||
// parse command line arguments
|
// parse command line arguments
|
||||||
try {
|
try {
|
||||||
|
@ -67,26 +67,26 @@ int main(int argc, char *argv[])
|
||||||
cerr << "Watching MPRIS service of the specified application \"" << applicationArg.values().front() << "\" ..." << endl;
|
cerr << "Watching MPRIS service of the specified application \"" << applicationArg.values().front() << "\" ..." << endl;
|
||||||
// create app loop, player watcher and ffmpeg launcher
|
// create app loop, player watcher and ffmpeg launcher
|
||||||
QCoreApplication app(argc, argv);
|
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);
|
FfmpegLauncher ffmpeg(watcher);
|
||||||
// pass specified args to ffmpeg launcher
|
// pass specified args to ffmpeg launcher
|
||||||
if(sinkArg.isPresent()) {
|
if(sinkArg.isPresent()) {
|
||||||
ffmpeg.setSink(QString::fromLocal8Bit(sinkArg.values().front().data()));
|
ffmpeg.setSink(QString::fromLocal8Bit(sinkArg.values().front()));
|
||||||
}
|
}
|
||||||
if(ffmpegInputOptions.isPresent()) {
|
if(ffmpegInputOptions.isPresent()) {
|
||||||
ffmpeg.setFFmpegInputOptions(QString::fromLocal8Bit(ffmpegInputOptions.values().front().data()));
|
ffmpeg.setFFmpegInputOptions(QString::fromLocal8Bit(ffmpegInputOptions.values().front()));
|
||||||
}
|
}
|
||||||
if(ffmpegBinArg.isPresent()) {
|
if(ffmpegBinArg.isPresent()) {
|
||||||
ffmpeg.setFFmpegBinary(QString::fromLocal8Bit(ffmpegBinArg.values().front().data()));
|
ffmpeg.setFFmpegBinary(QString::fromLocal8Bit(ffmpegBinArg.values().front()));
|
||||||
}
|
}
|
||||||
if(ffmpegOptions.isPresent()) {
|
if(ffmpegOptions.isPresent()) {
|
||||||
ffmpeg.setFFmpegOptions(QString::fromLocal8Bit(ffmpegOptions.values().front().data()));
|
ffmpeg.setFFmpegOptions(QString::fromLocal8Bit(ffmpegOptions.values().front()));
|
||||||
}
|
}
|
||||||
if(targetDirArg.isPresent()) {
|
if(targetDirArg.isPresent()) {
|
||||||
ffmpeg.setTargetDir(QString::fromLocal8Bit(targetDirArg.values().front().data()));
|
ffmpeg.setTargetDir(QString::fromLocal8Bit(targetDirArg.values().front()));
|
||||||
}
|
}
|
||||||
if(targetExtArg.isPresent()) {
|
if(targetExtArg.isPresent()) {
|
||||||
ffmpeg.setTargetExtension(QString::fromLocal8Bit(targetExtArg.values().front().data()));
|
ffmpeg.setTargetExtension(QString::fromLocal8Bit(targetExtArg.values().front()));
|
||||||
}
|
}
|
||||||
// enter app loop
|
// enter app loop
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
Loading…
Reference in New Issue