-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
193 lines (152 loc) · 5.4 KB
/
main.cpp
File metadata and controls
193 lines (152 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* MusicCat CLI Entry
*/
#include <iostream>
#include <string>
#include <string_view>
#include <Mcat.h>
#include <CommonsInit.h>
#include <csignal>
#define MCAT_VERSION "0.1.2"
std::atomic<bool> g_shouldExit = false;
void signalHandler(int) {
g_shouldExit.store(true, std::memory_order_relaxed);
}
void help();
namespace {
constexpr std::string_view kAppName = "mcat";
void printUnknownCommand(const std::string_view command) {
std::cerr << "Unknown command: " << command << "\n\n";
help();
}
void readyCommand(const int argc, char *argv[]) {
CommonsInit::TestAllCommons(true);
if (argc < 3) {
Mcat::ready();
return;
}
const std::string outputPath = argv[2];
Mcat::ready();
}
void outputCommand(const int argc, char *argv[]) {
CommonsInit::TestAllCommons(false);
if (argc < 3) {
std::cerr << "mcat: usage: mcat -o <outputPath>\n";
return;
}
Mcat::setOutput(argv[2]);
}
void virtualDeviceCommand(const int argc, char *argv[]) {
CommonsInit::TestAllCommons(false);
if (argc < 3) {
std::cerr << "mcat: usage: mcat -vd <available virtual device>\n";
return;
}
Mcat::setVirtualDevice(argv[2]);
}
void versionCommand() {
CommonsInit::TestAllCommons(false);
const std::string version = MCAT_VERSION;
std::cout << kAppName << " " << version << std::endl;
}
void logCommand() {
CommonsInit::TestAllCommons(false);
Mcat::printLog();
}
} // namespace
void help() {
std::cout << "MusicCat - Apple Music recording CLI\n\n";
std::cout << "Usage:\n";
std::cout << " mcat <command> [options]\n\n";
std::cout << "Commands:\n";
std::cout << " ready Start the Apple Music recording listener\n";
std::cout << " log Print runtime logs\n";
std::cout << " help Show this help message\n";
std::cout << " zh Show Chinese help\n";
std::cout << " ja Show Japanese help\n\n";
std::cout << "Options:\n";
std::cout << " -o <path> Set output directory\n";
std::cout << " -vd <device> Set virtual audio device\n";
std::cout << " -h, --help Show help message\n";
std::cout << " -v, --version Show program version\n";
}
void helpZh() {
std::cout << "MusicCat - Apple Music 自动录音工具\n\n";
std::cout << "用法:\n";
std::cout << " mcat <命令> [参数]\n\n";
std::cout << "命令:\n";
std::cout << " ready 启动 Apple Music 监听并自动录音\n";
std::cout << " log 查看运行日志\n";
std::cout << " help 显示英文帮助\n";
std::cout << " zh 显示中文帮助\n";
std::cout << " ja 显示日文帮助\n\n";
std::cout << "参数:\n";
std::cout << " -o <路径> 设置输出目录\n";
std::cout << " -vd <设备名> 设置虚拟音频设备\n";
std::cout << " -h, --help 显示帮助信息\n";
std::cout << " -v, --version 显示版本号\n";
}
void helpJa() {
std::cout << "MusicCat - Apple Music 自動録音ツール\n\n";
std::cout << "使い方:\n";
std::cout << " mcat <コマンド> [オプション]\n\n";
std::cout << "コマンド:\n";
std::cout << " ready Apple Music を監視して自動録音を開始\n";
std::cout << " log 実行ログを表示\n";
std::cout << " help 英語ヘルプを表示\n";
std::cout << " zh 中国語ヘルプを表示\n";
std::cout << " ja 日本語ヘルプを表示\n\n";
std::cout << "オプション:\n";
std::cout << " -o <path> 出力ディレクトリを設定\n";
std::cout << " -vd <device> 仮想オーディオデバイスを設定\n";
std::cout << " -h, --help ヘルプを表示\n";
std::cout << " -v, --version バージョンを表示\n";
}
int main(const int argc, char *argv[]) {
std::signal(SIGINT, signalHandler); // Ctrl + C
std::signal(SIGTERM, signalHandler); // kill
// std::signal(SIGHUP, signalHandler);
if (argc < 2) {
help();
return 0;
}
const std::string cmd = argv[1];
if (cmd == "help"
|| cmd == "-h"
|| cmd == "--help"
|| cmd == "--zh"
|| cmd == "zh"
|| cmd == "ja"
|| cmd == "--ja"
) {
if (cmd == "zh" || cmd == "--zh")
helpZh();
else if (cmd == "ja" || cmd == "--ja" || cmd == "japan")
helpJa();
else
help();
return 0;
}
if (cmd == "ready") {
readyCommand(argc, argv);
return 0;
}
if (cmd == "-o" || cmd == "-output" || cmd == "-opf") {
outputCommand(argc, argv);
return 0;
}
if (cmd == "-vd" || cmd == "-virtualDevice" || cmd == "-d") {
virtualDeviceCommand(argc, argv);
return 0;
}
if (cmd == "-ver" || cmd == "-version" || cmd == "--version" || cmd == "-v") {
versionCommand();
return 0;
}
if (cmd == "log") {
logCommand();
return 0;
}
printUnknownCommand(cmd);
return 1;
}