├── .github
└── workflows
│ └── auto_tests.yml
├── .gitignore
├── Cargo.lock
├── Cargo.toml
├── LICENSE
├── Makefile
├── README.md
└── src
├── args
├── config.rs
├── mod.rs
└── types.rs
├── json.rs
├── main.rs
├── process.rs
├── strings
├── info.txt
├── mod.rs
└── usage.txt
├── tests.rs
└── version
/.github/workflows/auto_tests.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 |
9 | env:
10 | CARGO_TERM_COLOR: always
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | steps:
18 | - uses: actions/checkout@v3
19 | - name: Build
20 | run: cargo build --verbose
21 | - name: Run tests
22 | run: cargo test --verbose
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target
2 |
--------------------------------------------------------------------------------
/Cargo.lock:
--------------------------------------------------------------------------------
1 | # This file is automatically @generated by Cargo.
2 | # It is not intended for manual editing.
3 | version = 3
4 |
5 | [[package]]
6 | name = "addr2line"
7 | version = "0.21.0"
8 | source = "registry+https://github.com/rust-lang/crates.io-index"
9 | checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
10 | dependencies = [
11 | "gimli",
12 | ]
13 |
14 | [[package]]
15 | name = "adler"
16 | version = "1.0.2"
17 | source = "registry+https://github.com/rust-lang/crates.io-index"
18 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
19 |
20 | [[package]]
21 | name = "autocfg"
22 | version = "1.2.0"
23 | source = "registry+https://github.com/rust-lang/crates.io-index"
24 | checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
25 |
26 | [[package]]
27 | name = "backtrace"
28 | version = "0.3.71"
29 | source = "registry+https://github.com/rust-lang/crates.io-index"
30 | checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
31 | dependencies = [
32 | "addr2line",
33 | "cc",
34 | "cfg-if",
35 | "libc",
36 | "miniz_oxide",
37 | "object",
38 | "rustc-demangle",
39 | ]
40 |
41 | [[package]]
42 | name = "base64"
43 | version = "0.21.7"
44 | source = "registry+https://github.com/rust-lang/crates.io-index"
45 | checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
46 |
47 | [[package]]
48 | name = "bitflags"
49 | version = "1.3.2"
50 | source = "registry+https://github.com/rust-lang/crates.io-index"
51 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
52 |
53 | [[package]]
54 | name = "bitflags"
55 | version = "2.5.0"
56 | source = "registry+https://github.com/rust-lang/crates.io-index"
57 | checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
58 |
59 | [[package]]
60 | name = "bumpalo"
61 | version = "3.16.0"
62 | source = "registry+https://github.com/rust-lang/crates.io-index"
63 | checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
64 |
65 | [[package]]
66 | name = "bytes"
67 | version = "1.6.0"
68 | source = "registry+https://github.com/rust-lang/crates.io-index"
69 | checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
70 |
71 | [[package]]
72 | name = "cc"
73 | version = "1.0.95"
74 | source = "registry+https://github.com/rust-lang/crates.io-index"
75 | checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
76 |
77 | [[package]]
78 | name = "cfg-if"
79 | version = "1.0.0"
80 | source = "registry+https://github.com/rust-lang/crates.io-index"
81 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
82 |
83 | [[package]]
84 | name = "core-foundation"
85 | version = "0.9.4"
86 | source = "registry+https://github.com/rust-lang/crates.io-index"
87 | checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
88 | dependencies = [
89 | "core-foundation-sys",
90 | "libc",
91 | ]
92 |
93 | [[package]]
94 | name = "core-foundation-sys"
95 | version = "0.8.6"
96 | source = "registry+https://github.com/rust-lang/crates.io-index"
97 | checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
98 |
99 | [[package]]
100 | name = "encoding_rs"
101 | version = "0.8.34"
102 | source = "registry+https://github.com/rust-lang/crates.io-index"
103 | checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59"
104 | dependencies = [
105 | "cfg-if",
106 | ]
107 |
108 | [[package]]
109 | name = "equivalent"
110 | version = "1.0.1"
111 | source = "registry+https://github.com/rust-lang/crates.io-index"
112 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
113 |
114 | [[package]]
115 | name = "errno"
116 | version = "0.3.8"
117 | source = "registry+https://github.com/rust-lang/crates.io-index"
118 | checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
119 | dependencies = [
120 | "libc",
121 | "windows-sys 0.52.0",
122 | ]
123 |
124 | [[package]]
125 | name = "fastrand"
126 | version = "2.0.2"
127 | source = "registry+https://github.com/rust-lang/crates.io-index"
128 | checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984"
129 |
130 | [[package]]
131 | name = "fnv"
132 | version = "1.0.7"
133 | source = "registry+https://github.com/rust-lang/crates.io-index"
134 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
135 |
136 | [[package]]
137 | name = "foreign-types"
138 | version = "0.3.2"
139 | source = "registry+https://github.com/rust-lang/crates.io-index"
140 | checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
141 | dependencies = [
142 | "foreign-types-shared",
143 | ]
144 |
145 | [[package]]
146 | name = "foreign-types-shared"
147 | version = "0.1.1"
148 | source = "registry+https://github.com/rust-lang/crates.io-index"
149 | checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
150 |
151 | [[package]]
152 | name = "form_urlencoded"
153 | version = "1.2.1"
154 | source = "registry+https://github.com/rust-lang/crates.io-index"
155 | checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
156 | dependencies = [
157 | "percent-encoding",
158 | ]
159 |
160 | [[package]]
161 | name = "futures"
162 | version = "0.3.30"
163 | source = "registry+https://github.com/rust-lang/crates.io-index"
164 | checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
165 | dependencies = [
166 | "futures-channel",
167 | "futures-core",
168 | "futures-io",
169 | "futures-sink",
170 | "futures-task",
171 | "futures-util",
172 | ]
173 |
174 | [[package]]
175 | name = "futures-channel"
176 | version = "0.3.30"
177 | source = "registry+https://github.com/rust-lang/crates.io-index"
178 | checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
179 | dependencies = [
180 | "futures-core",
181 | "futures-sink",
182 | ]
183 |
184 | [[package]]
185 | name = "futures-core"
186 | version = "0.3.30"
187 | source = "registry+https://github.com/rust-lang/crates.io-index"
188 | checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
189 |
190 | [[package]]
191 | name = "futures-io"
192 | version = "0.3.30"
193 | source = "registry+https://github.com/rust-lang/crates.io-index"
194 | checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
195 |
196 | [[package]]
197 | name = "futures-sink"
198 | version = "0.3.30"
199 | source = "registry+https://github.com/rust-lang/crates.io-index"
200 | checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5"
201 |
202 | [[package]]
203 | name = "futures-task"
204 | version = "0.3.30"
205 | source = "registry+https://github.com/rust-lang/crates.io-index"
206 | checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
207 |
208 | [[package]]
209 | name = "futures-util"
210 | version = "0.3.30"
211 | source = "registry+https://github.com/rust-lang/crates.io-index"
212 | checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
213 | dependencies = [
214 | "futures-core",
215 | "futures-sink",
216 | "futures-task",
217 | "pin-project-lite",
218 | "pin-utils",
219 | ]
220 |
221 | [[package]]
222 | name = "gimli"
223 | version = "0.28.1"
224 | source = "registry+https://github.com/rust-lang/crates.io-index"
225 | checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
226 |
227 | [[package]]
228 | name = "h2"
229 | version = "0.3.26"
230 | source = "registry+https://github.com/rust-lang/crates.io-index"
231 | checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
232 | dependencies = [
233 | "bytes",
234 | "fnv",
235 | "futures-core",
236 | "futures-sink",
237 | "futures-util",
238 | "http",
239 | "indexmap",
240 | "slab",
241 | "tokio",
242 | "tokio-util",
243 | "tracing",
244 | ]
245 |
246 | [[package]]
247 | name = "hashbrown"
248 | version = "0.14.3"
249 | source = "registry+https://github.com/rust-lang/crates.io-index"
250 | checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
251 |
252 | [[package]]
253 | name = "hermit-abi"
254 | version = "0.3.9"
255 | source = "registry+https://github.com/rust-lang/crates.io-index"
256 | checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
257 |
258 | [[package]]
259 | name = "http"
260 | version = "0.2.12"
261 | source = "registry+https://github.com/rust-lang/crates.io-index"
262 | checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
263 | dependencies = [
264 | "bytes",
265 | "fnv",
266 | "itoa",
267 | ]
268 |
269 | [[package]]
270 | name = "http-body"
271 | version = "0.4.6"
272 | source = "registry+https://github.com/rust-lang/crates.io-index"
273 | checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
274 | dependencies = [
275 | "bytes",
276 | "http",
277 | "pin-project-lite",
278 | ]
279 |
280 | [[package]]
281 | name = "httparse"
282 | version = "1.8.0"
283 | source = "registry+https://github.com/rust-lang/crates.io-index"
284 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904"
285 |
286 | [[package]]
287 | name = "httpdate"
288 | version = "1.0.3"
289 | source = "registry+https://github.com/rust-lang/crates.io-index"
290 | checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
291 |
292 | [[package]]
293 | name = "hyper"
294 | version = "0.14.28"
295 | source = "registry+https://github.com/rust-lang/crates.io-index"
296 | checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
297 | dependencies = [
298 | "bytes",
299 | "futures-channel",
300 | "futures-core",
301 | "futures-util",
302 | "h2",
303 | "http",
304 | "http-body",
305 | "httparse",
306 | "httpdate",
307 | "itoa",
308 | "pin-project-lite",
309 | "socket2",
310 | "tokio",
311 | "tower-service",
312 | "tracing",
313 | "want",
314 | ]
315 |
316 | [[package]]
317 | name = "hyper-tls"
318 | version = "0.5.0"
319 | source = "registry+https://github.com/rust-lang/crates.io-index"
320 | checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
321 | dependencies = [
322 | "bytes",
323 | "hyper",
324 | "native-tls",
325 | "tokio",
326 | "tokio-native-tls",
327 | ]
328 |
329 | [[package]]
330 | name = "idna"
331 | version = "0.5.0"
332 | source = "registry+https://github.com/rust-lang/crates.io-index"
333 | checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
334 | dependencies = [
335 | "unicode-bidi",
336 | "unicode-normalization",
337 | ]
338 |
339 | [[package]]
340 | name = "indexmap"
341 | version = "2.2.6"
342 | source = "registry+https://github.com/rust-lang/crates.io-index"
343 | checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
344 | dependencies = [
345 | "equivalent",
346 | "hashbrown",
347 | ]
348 |
349 | [[package]]
350 | name = "ipnet"
351 | version = "2.9.0"
352 | source = "registry+https://github.com/rust-lang/crates.io-index"
353 | checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
354 |
355 | [[package]]
356 | name = "itoa"
357 | version = "1.0.11"
358 | source = "registry+https://github.com/rust-lang/crates.io-index"
359 | checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
360 |
361 | [[package]]
362 | name = "js-sys"
363 | version = "0.3.69"
364 | source = "registry+https://github.com/rust-lang/crates.io-index"
365 | checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
366 | dependencies = [
367 | "wasm-bindgen",
368 | ]
369 |
370 | [[package]]
371 | name = "lazy_static"
372 | version = "1.4.0"
373 | source = "registry+https://github.com/rust-lang/crates.io-index"
374 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
375 |
376 | [[package]]
377 | name = "libc"
378 | version = "0.2.153"
379 | source = "registry+https://github.com/rust-lang/crates.io-index"
380 | checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
381 |
382 | [[package]]
383 | name = "linux-raw-sys"
384 | version = "0.4.13"
385 | source = "registry+https://github.com/rust-lang/crates.io-index"
386 | checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c"
387 |
388 | [[package]]
389 | name = "log"
390 | version = "0.4.21"
391 | source = "registry+https://github.com/rust-lang/crates.io-index"
392 | checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
393 |
394 | [[package]]
395 | name = "memchr"
396 | version = "2.7.2"
397 | source = "registry+https://github.com/rust-lang/crates.io-index"
398 | checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
399 |
400 | [[package]]
401 | name = "mime"
402 | version = "0.3.17"
403 | source = "registry+https://github.com/rust-lang/crates.io-index"
404 | checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
405 |
406 | [[package]]
407 | name = "miniz_oxide"
408 | version = "0.7.2"
409 | source = "registry+https://github.com/rust-lang/crates.io-index"
410 | checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
411 | dependencies = [
412 | "adler",
413 | ]
414 |
415 | [[package]]
416 | name = "mio"
417 | version = "0.8.11"
418 | source = "registry+https://github.com/rust-lang/crates.io-index"
419 | checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
420 | dependencies = [
421 | "libc",
422 | "wasi",
423 | "windows-sys 0.48.0",
424 | ]
425 |
426 | [[package]]
427 | name = "native-tls"
428 | version = "0.2.11"
429 | source = "registry+https://github.com/rust-lang/crates.io-index"
430 | checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e"
431 | dependencies = [
432 | "lazy_static",
433 | "libc",
434 | "log",
435 | "openssl",
436 | "openssl-probe",
437 | "openssl-sys",
438 | "schannel",
439 | "security-framework",
440 | "security-framework-sys",
441 | "tempfile",
442 | ]
443 |
444 | [[package]]
445 | name = "num_cpus"
446 | version = "1.16.0"
447 | source = "registry+https://github.com/rust-lang/crates.io-index"
448 | checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
449 | dependencies = [
450 | "hermit-abi",
451 | "libc",
452 | ]
453 |
454 | [[package]]
455 | name = "object"
456 | version = "0.32.2"
457 | source = "registry+https://github.com/rust-lang/crates.io-index"
458 | checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
459 | dependencies = [
460 | "memchr",
461 | ]
462 |
463 | [[package]]
464 | name = "once_cell"
465 | version = "1.19.0"
466 | source = "registry+https://github.com/rust-lang/crates.io-index"
467 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
468 |
469 | [[package]]
470 | name = "openssl"
471 | version = "0.10.64"
472 | source = "registry+https://github.com/rust-lang/crates.io-index"
473 | checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f"
474 | dependencies = [
475 | "bitflags 2.5.0",
476 | "cfg-if",
477 | "foreign-types",
478 | "libc",
479 | "once_cell",
480 | "openssl-macros",
481 | "openssl-sys",
482 | ]
483 |
484 | [[package]]
485 | name = "openssl-macros"
486 | version = "0.1.1"
487 | source = "registry+https://github.com/rust-lang/crates.io-index"
488 | checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
489 | dependencies = [
490 | "proc-macro2",
491 | "quote",
492 | "syn",
493 | ]
494 |
495 | [[package]]
496 | name = "openssl-probe"
497 | version = "0.1.5"
498 | source = "registry+https://github.com/rust-lang/crates.io-index"
499 | checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
500 |
501 | [[package]]
502 | name = "openssl-src"
503 | version = "300.3.0+3.3.0"
504 | source = "registry+https://github.com/rust-lang/crates.io-index"
505 | checksum = "eba8804a1c5765b18c4b3f907e6897ebabeedebc9830e1a0046c4a4cf44663e1"
506 | dependencies = [
507 | "cc",
508 | ]
509 |
510 | [[package]]
511 | name = "openssl-sys"
512 | version = "0.9.102"
513 | source = "registry+https://github.com/rust-lang/crates.io-index"
514 | checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2"
515 | dependencies = [
516 | "cc",
517 | "libc",
518 | "openssl-src",
519 | "pkg-config",
520 | "vcpkg",
521 | ]
522 |
523 | [[package]]
524 | name = "percent-encoding"
525 | version = "2.3.1"
526 | source = "registry+https://github.com/rust-lang/crates.io-index"
527 | checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
528 |
529 | [[package]]
530 | name = "pin-project-lite"
531 | version = "0.2.14"
532 | source = "registry+https://github.com/rust-lang/crates.io-index"
533 | checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
534 |
535 | [[package]]
536 | name = "pin-utils"
537 | version = "0.1.0"
538 | source = "registry+https://github.com/rust-lang/crates.io-index"
539 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
540 |
541 | [[package]]
542 | name = "pkg-config"
543 | version = "0.3.30"
544 | source = "registry+https://github.com/rust-lang/crates.io-index"
545 | checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
546 |
547 | [[package]]
548 | name = "proc-macro2"
549 | version = "1.0.81"
550 | source = "registry+https://github.com/rust-lang/crates.io-index"
551 | checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
552 | dependencies = [
553 | "unicode-ident",
554 | ]
555 |
556 | [[package]]
557 | name = "quote"
558 | version = "1.0.36"
559 | source = "registry+https://github.com/rust-lang/crates.io-index"
560 | checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
561 | dependencies = [
562 | "proc-macro2",
563 | ]
564 |
565 | [[package]]
566 | name = "reqwest"
567 | version = "0.11.27"
568 | source = "registry+https://github.com/rust-lang/crates.io-index"
569 | checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62"
570 | dependencies = [
571 | "base64",
572 | "bytes",
573 | "encoding_rs",
574 | "futures-core",
575 | "futures-util",
576 | "h2",
577 | "http",
578 | "http-body",
579 | "hyper",
580 | "hyper-tls",
581 | "ipnet",
582 | "js-sys",
583 | "log",
584 | "mime",
585 | "native-tls",
586 | "once_cell",
587 | "percent-encoding",
588 | "pin-project-lite",
589 | "rustls-pemfile",
590 | "serde",
591 | "serde_json",
592 | "serde_urlencoded",
593 | "sync_wrapper",
594 | "system-configuration",
595 | "tokio",
596 | "tokio-native-tls",
597 | "tower-service",
598 | "url",
599 | "wasm-bindgen",
600 | "wasm-bindgen-futures",
601 | "web-sys",
602 | "winreg",
603 | ]
604 |
605 | [[package]]
606 | name = "rustc-demangle"
607 | version = "0.1.23"
608 | source = "registry+https://github.com/rust-lang/crates.io-index"
609 | checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
610 |
611 | [[package]]
612 | name = "rustix"
613 | version = "0.38.32"
614 | source = "registry+https://github.com/rust-lang/crates.io-index"
615 | checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89"
616 | dependencies = [
617 | "bitflags 2.5.0",
618 | "errno",
619 | "libc",
620 | "linux-raw-sys",
621 | "windows-sys 0.52.0",
622 | ]
623 |
624 | [[package]]
625 | name = "rustls-pemfile"
626 | version = "1.0.4"
627 | source = "registry+https://github.com/rust-lang/crates.io-index"
628 | checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c"
629 | dependencies = [
630 | "base64",
631 | ]
632 |
633 | [[package]]
634 | name = "ryu"
635 | version = "1.0.17"
636 | source = "registry+https://github.com/rust-lang/crates.io-index"
637 | checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
638 |
639 | [[package]]
640 | name = "schannel"
641 | version = "0.1.23"
642 | source = "registry+https://github.com/rust-lang/crates.io-index"
643 | checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534"
644 | dependencies = [
645 | "windows-sys 0.52.0",
646 | ]
647 |
648 | [[package]]
649 | name = "security-framework"
650 | version = "2.10.0"
651 | source = "registry+https://github.com/rust-lang/crates.io-index"
652 | checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
653 | dependencies = [
654 | "bitflags 1.3.2",
655 | "core-foundation",
656 | "core-foundation-sys",
657 | "libc",
658 | "security-framework-sys",
659 | ]
660 |
661 | [[package]]
662 | name = "security-framework-sys"
663 | version = "2.10.0"
664 | source = "registry+https://github.com/rust-lang/crates.io-index"
665 | checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
666 | dependencies = [
667 | "core-foundation-sys",
668 | "libc",
669 | ]
670 |
671 | [[package]]
672 | name = "serde"
673 | version = "1.0.198"
674 | source = "registry+https://github.com/rust-lang/crates.io-index"
675 | checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc"
676 | dependencies = [
677 | "serde_derive",
678 | ]
679 |
680 | [[package]]
681 | name = "serde_derive"
682 | version = "1.0.198"
683 | source = "registry+https://github.com/rust-lang/crates.io-index"
684 | checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9"
685 | dependencies = [
686 | "proc-macro2",
687 | "quote",
688 | "syn",
689 | ]
690 |
691 | [[package]]
692 | name = "serde_json"
693 | version = "1.0.116"
694 | source = "registry+https://github.com/rust-lang/crates.io-index"
695 | checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
696 | dependencies = [
697 | "itoa",
698 | "ryu",
699 | "serde",
700 | ]
701 |
702 | [[package]]
703 | name = "serde_urlencoded"
704 | version = "0.7.1"
705 | source = "registry+https://github.com/rust-lang/crates.io-index"
706 | checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
707 | dependencies = [
708 | "form_urlencoded",
709 | "itoa",
710 | "ryu",
711 | "serde",
712 | ]
713 |
714 | [[package]]
715 | name = "slab"
716 | version = "0.4.9"
717 | source = "registry+https://github.com/rust-lang/crates.io-index"
718 | checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
719 | dependencies = [
720 | "autocfg",
721 | ]
722 |
723 | [[package]]
724 | name = "socket2"
725 | version = "0.5.6"
726 | source = "registry+https://github.com/rust-lang/crates.io-index"
727 | checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
728 | dependencies = [
729 | "libc",
730 | "windows-sys 0.52.0",
731 | ]
732 |
733 | [[package]]
734 | name = "syn"
735 | version = "2.0.60"
736 | source = "registry+https://github.com/rust-lang/crates.io-index"
737 | checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
738 | dependencies = [
739 | "proc-macro2",
740 | "quote",
741 | "unicode-ident",
742 | ]
743 |
744 | [[package]]
745 | name = "sync_wrapper"
746 | version = "0.1.2"
747 | source = "registry+https://github.com/rust-lang/crates.io-index"
748 | checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160"
749 |
750 | [[package]]
751 | name = "system-configuration"
752 | version = "0.5.1"
753 | source = "registry+https://github.com/rust-lang/crates.io-index"
754 | checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7"
755 | dependencies = [
756 | "bitflags 1.3.2",
757 | "core-foundation",
758 | "system-configuration-sys",
759 | ]
760 |
761 | [[package]]
762 | name = "system-configuration-sys"
763 | version = "0.5.0"
764 | source = "registry+https://github.com/rust-lang/crates.io-index"
765 | checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9"
766 | dependencies = [
767 | "core-foundation-sys",
768 | "libc",
769 | ]
770 |
771 | [[package]]
772 | name = "tcobalt"
773 | version = "1.3.0"
774 | dependencies = [
775 | "futures",
776 | "openssl",
777 | "reqwest",
778 | "tokio",
779 | ]
780 |
781 | [[package]]
782 | name = "tempfile"
783 | version = "3.10.1"
784 | source = "registry+https://github.com/rust-lang/crates.io-index"
785 | checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
786 | dependencies = [
787 | "cfg-if",
788 | "fastrand",
789 | "rustix",
790 | "windows-sys 0.52.0",
791 | ]
792 |
793 | [[package]]
794 | name = "tinyvec"
795 | version = "1.6.0"
796 | source = "registry+https://github.com/rust-lang/crates.io-index"
797 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
798 | dependencies = [
799 | "tinyvec_macros",
800 | ]
801 |
802 | [[package]]
803 | name = "tinyvec_macros"
804 | version = "0.1.1"
805 | source = "registry+https://github.com/rust-lang/crates.io-index"
806 | checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
807 |
808 | [[package]]
809 | name = "tokio"
810 | version = "1.37.0"
811 | source = "registry+https://github.com/rust-lang/crates.io-index"
812 | checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
813 | dependencies = [
814 | "backtrace",
815 | "bytes",
816 | "libc",
817 | "mio",
818 | "num_cpus",
819 | "pin-project-lite",
820 | "socket2",
821 | "tokio-macros",
822 | "windows-sys 0.48.0",
823 | ]
824 |
825 | [[package]]
826 | name = "tokio-macros"
827 | version = "2.2.0"
828 | source = "registry+https://github.com/rust-lang/crates.io-index"
829 | checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
830 | dependencies = [
831 | "proc-macro2",
832 | "quote",
833 | "syn",
834 | ]
835 |
836 | [[package]]
837 | name = "tokio-native-tls"
838 | version = "0.3.1"
839 | source = "registry+https://github.com/rust-lang/crates.io-index"
840 | checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2"
841 | dependencies = [
842 | "native-tls",
843 | "tokio",
844 | ]
845 |
846 | [[package]]
847 | name = "tokio-util"
848 | version = "0.7.10"
849 | source = "registry+https://github.com/rust-lang/crates.io-index"
850 | checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15"
851 | dependencies = [
852 | "bytes",
853 | "futures-core",
854 | "futures-sink",
855 | "pin-project-lite",
856 | "tokio",
857 | "tracing",
858 | ]
859 |
860 | [[package]]
861 | name = "tower-service"
862 | version = "0.3.2"
863 | source = "registry+https://github.com/rust-lang/crates.io-index"
864 | checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52"
865 |
866 | [[package]]
867 | name = "tracing"
868 | version = "0.1.40"
869 | source = "registry+https://github.com/rust-lang/crates.io-index"
870 | checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
871 | dependencies = [
872 | "pin-project-lite",
873 | "tracing-core",
874 | ]
875 |
876 | [[package]]
877 | name = "tracing-core"
878 | version = "0.1.32"
879 | source = "registry+https://github.com/rust-lang/crates.io-index"
880 | checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
881 | dependencies = [
882 | "once_cell",
883 | ]
884 |
885 | [[package]]
886 | name = "try-lock"
887 | version = "0.2.5"
888 | source = "registry+https://github.com/rust-lang/crates.io-index"
889 | checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
890 |
891 | [[package]]
892 | name = "unicode-bidi"
893 | version = "0.3.15"
894 | source = "registry+https://github.com/rust-lang/crates.io-index"
895 | checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
896 |
897 | [[package]]
898 | name = "unicode-ident"
899 | version = "1.0.12"
900 | source = "registry+https://github.com/rust-lang/crates.io-index"
901 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
902 |
903 | [[package]]
904 | name = "unicode-normalization"
905 | version = "0.1.23"
906 | source = "registry+https://github.com/rust-lang/crates.io-index"
907 | checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5"
908 | dependencies = [
909 | "tinyvec",
910 | ]
911 |
912 | [[package]]
913 | name = "url"
914 | version = "2.5.0"
915 | source = "registry+https://github.com/rust-lang/crates.io-index"
916 | checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633"
917 | dependencies = [
918 | "form_urlencoded",
919 | "idna",
920 | "percent-encoding",
921 | ]
922 |
923 | [[package]]
924 | name = "vcpkg"
925 | version = "0.2.15"
926 | source = "registry+https://github.com/rust-lang/crates.io-index"
927 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
928 |
929 | [[package]]
930 | name = "want"
931 | version = "0.3.1"
932 | source = "registry+https://github.com/rust-lang/crates.io-index"
933 | checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
934 | dependencies = [
935 | "try-lock",
936 | ]
937 |
938 | [[package]]
939 | name = "wasi"
940 | version = "0.11.0+wasi-snapshot-preview1"
941 | source = "registry+https://github.com/rust-lang/crates.io-index"
942 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
943 |
944 | [[package]]
945 | name = "wasm-bindgen"
946 | version = "0.2.92"
947 | source = "registry+https://github.com/rust-lang/crates.io-index"
948 | checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
949 | dependencies = [
950 | "cfg-if",
951 | "wasm-bindgen-macro",
952 | ]
953 |
954 | [[package]]
955 | name = "wasm-bindgen-backend"
956 | version = "0.2.92"
957 | source = "registry+https://github.com/rust-lang/crates.io-index"
958 | checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
959 | dependencies = [
960 | "bumpalo",
961 | "log",
962 | "once_cell",
963 | "proc-macro2",
964 | "quote",
965 | "syn",
966 | "wasm-bindgen-shared",
967 | ]
968 |
969 | [[package]]
970 | name = "wasm-bindgen-futures"
971 | version = "0.4.42"
972 | source = "registry+https://github.com/rust-lang/crates.io-index"
973 | checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0"
974 | dependencies = [
975 | "cfg-if",
976 | "js-sys",
977 | "wasm-bindgen",
978 | "web-sys",
979 | ]
980 |
981 | [[package]]
982 | name = "wasm-bindgen-macro"
983 | version = "0.2.92"
984 | source = "registry+https://github.com/rust-lang/crates.io-index"
985 | checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
986 | dependencies = [
987 | "quote",
988 | "wasm-bindgen-macro-support",
989 | ]
990 |
991 | [[package]]
992 | name = "wasm-bindgen-macro-support"
993 | version = "0.2.92"
994 | source = "registry+https://github.com/rust-lang/crates.io-index"
995 | checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
996 | dependencies = [
997 | "proc-macro2",
998 | "quote",
999 | "syn",
1000 | "wasm-bindgen-backend",
1001 | "wasm-bindgen-shared",
1002 | ]
1003 |
1004 | [[package]]
1005 | name = "wasm-bindgen-shared"
1006 | version = "0.2.92"
1007 | source = "registry+https://github.com/rust-lang/crates.io-index"
1008 | checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
1009 |
1010 | [[package]]
1011 | name = "web-sys"
1012 | version = "0.3.69"
1013 | source = "registry+https://github.com/rust-lang/crates.io-index"
1014 | checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef"
1015 | dependencies = [
1016 | "js-sys",
1017 | "wasm-bindgen",
1018 | ]
1019 |
1020 | [[package]]
1021 | name = "windows-sys"
1022 | version = "0.48.0"
1023 | source = "registry+https://github.com/rust-lang/crates.io-index"
1024 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
1025 | dependencies = [
1026 | "windows-targets 0.48.5",
1027 | ]
1028 |
1029 | [[package]]
1030 | name = "windows-sys"
1031 | version = "0.52.0"
1032 | source = "registry+https://github.com/rust-lang/crates.io-index"
1033 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
1034 | dependencies = [
1035 | "windows-targets 0.52.5",
1036 | ]
1037 |
1038 | [[package]]
1039 | name = "windows-targets"
1040 | version = "0.48.5"
1041 | source = "registry+https://github.com/rust-lang/crates.io-index"
1042 | checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
1043 | dependencies = [
1044 | "windows_aarch64_gnullvm 0.48.5",
1045 | "windows_aarch64_msvc 0.48.5",
1046 | "windows_i686_gnu 0.48.5",
1047 | "windows_i686_msvc 0.48.5",
1048 | "windows_x86_64_gnu 0.48.5",
1049 | "windows_x86_64_gnullvm 0.48.5",
1050 | "windows_x86_64_msvc 0.48.5",
1051 | ]
1052 |
1053 | [[package]]
1054 | name = "windows-targets"
1055 | version = "0.52.5"
1056 | source = "registry+https://github.com/rust-lang/crates.io-index"
1057 | checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
1058 | dependencies = [
1059 | "windows_aarch64_gnullvm 0.52.5",
1060 | "windows_aarch64_msvc 0.52.5",
1061 | "windows_i686_gnu 0.52.5",
1062 | "windows_i686_gnullvm",
1063 | "windows_i686_msvc 0.52.5",
1064 | "windows_x86_64_gnu 0.52.5",
1065 | "windows_x86_64_gnullvm 0.52.5",
1066 | "windows_x86_64_msvc 0.52.5",
1067 | ]
1068 |
1069 | [[package]]
1070 | name = "windows_aarch64_gnullvm"
1071 | version = "0.48.5"
1072 | source = "registry+https://github.com/rust-lang/crates.io-index"
1073 | checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
1074 |
1075 | [[package]]
1076 | name = "windows_aarch64_gnullvm"
1077 | version = "0.52.5"
1078 | source = "registry+https://github.com/rust-lang/crates.io-index"
1079 | checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
1080 |
1081 | [[package]]
1082 | name = "windows_aarch64_msvc"
1083 | version = "0.48.5"
1084 | source = "registry+https://github.com/rust-lang/crates.io-index"
1085 | checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
1086 |
1087 | [[package]]
1088 | name = "windows_aarch64_msvc"
1089 | version = "0.52.5"
1090 | source = "registry+https://github.com/rust-lang/crates.io-index"
1091 | checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
1092 |
1093 | [[package]]
1094 | name = "windows_i686_gnu"
1095 | version = "0.48.5"
1096 | source = "registry+https://github.com/rust-lang/crates.io-index"
1097 | checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
1098 |
1099 | [[package]]
1100 | name = "windows_i686_gnu"
1101 | version = "0.52.5"
1102 | source = "registry+https://github.com/rust-lang/crates.io-index"
1103 | checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
1104 |
1105 | [[package]]
1106 | name = "windows_i686_gnullvm"
1107 | version = "0.52.5"
1108 | source = "registry+https://github.com/rust-lang/crates.io-index"
1109 | checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
1110 |
1111 | [[package]]
1112 | name = "windows_i686_msvc"
1113 | version = "0.48.5"
1114 | source = "registry+https://github.com/rust-lang/crates.io-index"
1115 | checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
1116 |
1117 | [[package]]
1118 | name = "windows_i686_msvc"
1119 | version = "0.52.5"
1120 | source = "registry+https://github.com/rust-lang/crates.io-index"
1121 | checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
1122 |
1123 | [[package]]
1124 | name = "windows_x86_64_gnu"
1125 | version = "0.48.5"
1126 | source = "registry+https://github.com/rust-lang/crates.io-index"
1127 | checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
1128 |
1129 | [[package]]
1130 | name = "windows_x86_64_gnu"
1131 | version = "0.52.5"
1132 | source = "registry+https://github.com/rust-lang/crates.io-index"
1133 | checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
1134 |
1135 | [[package]]
1136 | name = "windows_x86_64_gnullvm"
1137 | version = "0.48.5"
1138 | source = "registry+https://github.com/rust-lang/crates.io-index"
1139 | checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
1140 |
1141 | [[package]]
1142 | name = "windows_x86_64_gnullvm"
1143 | version = "0.52.5"
1144 | source = "registry+https://github.com/rust-lang/crates.io-index"
1145 | checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
1146 |
1147 | [[package]]
1148 | name = "windows_x86_64_msvc"
1149 | version = "0.48.5"
1150 | source = "registry+https://github.com/rust-lang/crates.io-index"
1151 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
1152 |
1153 | [[package]]
1154 | name = "windows_x86_64_msvc"
1155 | version = "0.52.5"
1156 | source = "registry+https://github.com/rust-lang/crates.io-index"
1157 | checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
1158 |
1159 | [[package]]
1160 | name = "winreg"
1161 | version = "0.50.0"
1162 | source = "registry+https://github.com/rust-lang/crates.io-index"
1163 | checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1"
1164 | dependencies = [
1165 | "cfg-if",
1166 | "windows-sys 0.48.0",
1167 | ]
1168 |
--------------------------------------------------------------------------------
/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "tcobalt"
3 | version = "1.3.0"
4 | edition = "2021"
5 |
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7 |
8 | [dependencies]
9 | futures = { version = "0.3.30", default-features = false, features = ["alloc"] }
10 | reqwest = "0.11.26"
11 | tokio = { version = "1.37.0", default-features = false, features = ["rt-multi-thread", "macros", "fs"] }
12 |
13 | [target.'cfg(target_arch = "aarch64")'.dependencies]
14 | openssl = { version = "0.10.29", features = ["vendored"] }
15 |
16 | [profile.release]
17 | opt-level = "s"
18 | lto = true
19 | debug = 0
20 | codegen-units = 1
21 | panic = "abort"
22 | strip = true
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | tcobalt:
2 | export RUSTUP_TOOLCHAIN=stable
3 | export CARGO_TARGET_DIR=target
4 |
5 | cargo fetch --locked --target "$$(rustc -vV | sed -n 's/host: //p')"
6 | cargo build --frozen --release --all-features
7 |
8 | debug:
9 | export RUSTUP_TOOLCHAIN=stable
10 | export CARGO_TARGET_DIR=target
11 |
12 | cargo fetch --locked --target "$$(rustc -vV | sed -n 's/host: //p')"
13 | cargo build --frozen --all-features
14 |
15 | arm:
16 | export RUSTUP_TOOLCHAIN=stable
17 | export CARGO_TARGET_DIR=target
18 |
19 | cargo fetch --locked --target aarch64-unknown-linux-gnu
20 | CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc \
21 | cargo build --frozen --all-features --target aarch64-unknown-linux-gnu --release
22 |
23 |
24 | release: tcobalt
25 |
26 | install:
27 | install -Dm0755 -t "/usr/bin" "target/release/tcobalt"
28 | ln -sf "/usr/bin/tcobalt" "/usr/bin/tcb"
29 |
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://repology.org/project/tcobalt/versions)
2 | [](https://github.com/khyerdev/tcobalt/releases/)
3 | [](https://github.com/khyerdev/tcobalt/releases/)
4 | [](https://github.com/khyerdev/tcobalt/blob/main/LICENSE)
5 | [](https://github.com/khyerdev/tcobalt/actions)
6 | []()
7 |
8 | ### NOTICE
9 |
10 | As of September 10th, the newest version of [cobalt.tools](https://cobalt.tools) contains breaking api changes. I made the changes necessary but ran into a "massive" issue that I do not feel motivated to fix. See [issue #1](https://github.com/khyerdev/tcobalt/issues/1) for more details.
11 |
12 | As of October 18th, I have decided to orphan this project simply because I have lost interest in it and do not want to fix the aformentioned issue. Below are 3 projects I recommend checking out that most likely do things better than tcobalt:
13 |
14 | * [lostdusty/cobalt](https://github.com/lostdusty/cobalt): Cobalt CLI written in golang
15 | * [lostdusty/gobalt](https://github.com/lostdusty/gobalt): Golang library for the Cobalt API
16 | * [tskau/tobalt](https://github.com/tskau/tobalt): Typescript library for the Cobalt API
17 |
18 | If you still wish to gain insight of what this project was like, feel free to read through this document, the code, and/or compile this yourself.
19 |
20 | # tcobalt Command Line Utility
21 |
22 | tcobalt (or tcb) is a command-line tool for downloading your favorite videos and audios from the internet. This tool uses the api of [wukko](https://github.com/wukko)'s [cobalt.tools](https://cobalt.tools), which is an amazing website to save what you love without ads, trackers, or anything creepy.
23 |
24 | Stop using random websites to download videos, just use [cobalt.tools](https://cobalt.tools), or the unofficial command-line version, tcobalt.
25 |
26 | ## Features
27 | * tcobalt allows you to download videos and audios just as easily as you can with [cobalt.tools](https://cobalt.tools) with `tcb get`
28 | * tcobalt also allows you to download multiple videos/audios at once with `tcb bulk get` and `tcb bulk execute`
29 | * tcobalt allows some integration with other commands, by allowing a url to be piped into `tcb get +`
30 | * tcobalt includes all the settings that web cobalt has, along with a few extra features that will get extended in the future
31 | * tcobalt gives methods to check cobalt's version and to list the supported services right from your terminal
32 | * tcobalt has support for using a different cobalt api instance than the main one
33 | * You can change the default tcobalt flags in a configuration file
34 | * tcobalt's help method is easy to understand, and gives the option to list usage examples
35 | * tcobalt supports single letter methods for lazy people `tcb g`, `tcb b e`
36 |
37 | ## Examples
38 | Basic downloading of a video
39 | ```
40 | tcb get 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' -o rickroll.mp4
41 | ```
42 | Downloading of a song with '.ogg' format and using the default filename
43 | ```
44 | tcb get -af ogg 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
45 | ```
46 | Shuffling a list of youtube links and downloading the first one as a .webm file
47 | ```
48 | cat links.txt | shuf | head -n 1 | tcb get -c vp9 +
49 | ```
50 | Downloading the same video twice, but with one being audio-only:
51 | ```
52 | tcb bulk execute links.txt
53 | ```
54 | ```
55 | https://www.youtube.com/watch?v=dQw4w9WgXcQ -o roll.mp4
56 | https://www.youtube.com/watch?v=dQw4w9WgXcQ -ao silly-song.mp3
57 | ```
58 | Downloading three coding videos at once with 720p resolution each
59 | ```
60 | tcb bulk get -q 720 'https://www.youtube.com/watch?v=qclZUQYZTzg' 'https://www.youtube.com/watch?v=wvQCIMjlxHw' 'https://www.youtube.com/watch?v=3T3ZDquDDVg'
61 | ```
62 | Full usage help is available with `tcb help`, but can also be seen in the [usage.txt](https://github.com/khyerdev/tcobalt/blob/main/src/strings/usage.txt) and [info.txt](https://github.com/khyerdev/tcobalt/blob/main/src/strings/info.txt) files
63 |
64 | tcobalt also supports `tcb --help`, `tcb -h`, `tcb --version`, and `tcb -v` for people who have not read the help or this page
65 |
66 | ## Support
67 | x86_64 and aarch64 are the only architectures supported, as I only own machines with those architectures. If you wish tcobalt added more support, open up an issue/pr.
68 |
69 | ### OS/Packager Support Progress
70 | 1. Arch Linux (AUR) (COMPLETE)
71 | 2. Windows 10/11 (Prebuilt binary)
72 | 3. Fedora
73 | 4. Ubuntu (Prebuilt PKG)
74 |
75 | The repos that contain tcobalt can be seen on the right, along with the highest version the repo has.
76 |
77 | ## Installation
78 |
79 | ### Prebuilt Binary Downloads
80 | | Arch Linux (pkg) | Ubuntu (pkg) | Linux | Windows |
81 | | ---------------- | ------------ | ----- | ------- |
82 | | [v1.2.1-1 x86_64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.1/tcobalt-1.2.1-1-x86_64.pkg.tar.zst) | [v1.2.0 amd64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.0/tcobalt-1.2.0-amd64.deb) | [v1.2.1 x86_64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.1/tcobalt-linux-x86_64) | [v1.2.1 x86_64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.1/tcobalt-windows-x86_64.exe) |
83 | | Use the AUR (aarch64) | [v1.2.0 arm64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.0/tcobalt-1.2.0-arm64.deb) | [v1.2.1 aarch64](https://github.com/khyerdev/tcobalt/releases/download/v1.2.1/tcobalt-linux-aarch64) | Unsupported (aarch64) |
84 |
85 | ### Arch Linux
86 | 1. Install `yay` or `paru`:
87 | ```sh
88 | sudo pacman -S base-devel
89 | git clone https://aur.archlinux.org/yay.git # or paru.git
90 | cd yay # or paru
91 | makepkg -si
92 | ```
93 | 2. Use either `yay` or `paru` to install `tcobalt`:
94 | ```
95 | yay -S tcobalt
96 | ```
97 | ```
98 | paru -S tcobalt
99 | ```
100 | OR
101 |
102 | Get it directly from the AUR without installing an AUR helper:
103 | ```
104 | sudo pacman -S base-devel
105 | git clone https://aur.archlinux.org/tcobalt.git
106 | cd tcobalt
107 | makepkg -si
108 | ```
109 |
110 | OR
111 | 1. Download the pkg from the above prebuilt binaries (or use cURL)
112 | 2. Open a terminal and navigate to the directory containing the donwloaded .pkg.tar.zst file
113 | 3. Run the following command (replacing the fields in the angle brackets as necessary)
114 | ```
115 | sudo pacman -U tcobalt---.pkg.tar.zst
116 | ```
117 |
118 | The PKGBUILD declares that this only supports x86_64, but since it builds from source, yay/paru will allow you to install tcobalt on any architecture
119 |
120 | This process will also work on arch-based distros
121 |
122 | ### Ubuntu
123 | Packaging to a PPA has literally no good documentation online, and the official Ubuntu website for it has LITERALLY NO TEXT ON IT (its undergoing maintenance). Debian docs and launchpad docks also suck. You are stuck with this process until I feel like requesting tcobalt to be added to the official Ubuntu repositories. I won't bother with debian because they release stable updates every 2 years.
124 | 1. Download the pkg from the above prebuilt binaries (or use cURL)
125 | 2. Open a terminal and navigate to the directory containing the downloaded .deb file
126 | 3. Run the following command (replacing the fields in the angle brackets as necessary)
127 | ```
128 | sudo dpkg -i tcobalt--.deb
129 | ```
130 |
131 | ### Windows 10/11
132 | Download the .exe from the above prebuilt binaries, put it into any `%PATH%` folder, and rename it to `tcb.exe`
133 |
134 | I will figure out how to add tcobalt to winget-pkgs sometime in the future
135 |
136 | ### Other Linux
137 | You can try downloading the linux binary from the above prebuilt binaries, putting it into `/usr/bin`, and renaming it to `tcb`
138 |
139 | ### Unsupported OSes
140 | More support will come later. If you are on an unsupported operating system or architecture, or downloading a prebuilt binary didnt work, do this:
141 | 1. Clone the repository
142 | ```
143 | git clone https://github.com/khyerdev/tcobalt.git
144 | cd tcobalt
145 | ```
146 | 2. Compile (make sure rust is installed and the default rust toolchain is also installed)
147 | * On Linux:
148 | ```
149 | make
150 | ```
151 | * On Windows/MacOS:
152 | ```
153 | cargo build --release
154 | ```
155 | 3. Install tcobalt
156 | * On Linux:
157 | ```
158 | sudo make install
159 | ```
160 | * On Windows/MacOS:
161 |
162 | Copy the tcobalt binary from `target/release` into a folder that has your PATH and rename it to `tcb` with the file extension corresponding to your OS (`.exe` on windows)
163 |
164 | ## Dependencies
165 | tcobalt is designed to use as little dependencies as possible. Here are the ones it uses:
166 |
167 | The [tokio](https://crates.io/crates/tokio) runtime, for easily handling asynchronous code
168 |
169 | [futures](https://crates.io/crates/futures), for easily parralelizing bulk downloads
170 |
171 | [reqwest](https://crates.io/crates/reqwest), for making web requests with HTTPS. Requires tokio to work
172 |
173 | I have reinvented the wheel for things that are possible for me to do without dependencies, like parsing json
174 |
175 | ## License
176 | This project is licensed under the [GNU GPL v3](https://www.gnu.org/licenses/gpl-3.0.en.html), meaning you are allowed to freely use, modify, and distribute this project as long as you keep it as free and open-source as this project is, and as long as you include the same lisence and indicate your changes. More information about this license is [here (fossa.com)](https://fossa.com/blog/open-source-software-licenses-101-gpl-v3/) and [here (gnu.org)](https://www.gnu.org/licenses/quick-guide-gplv3.html).
177 |
178 | Cobalt has granted permission for anyone to use the cobalt api in their personal perojects, and not for commercial use. tcobalt is a personal project of mine, and I am not affiliated with wukko in any way.
179 |
180 | I would prefer if you credited my work when you share this.
181 |
--------------------------------------------------------------------------------
/src/args/config.rs:
--------------------------------------------------------------------------------
1 | use std::path::PathBuf;
2 |
3 | #[cfg(unix)]
4 | const CONFIG_PATH: &str = "$CFG/.config/tcobalt.conf";
5 | #[cfg(target_os = "windows")]
6 | const CONFIG_PATH: &str = "$CFG\\tcobalt.conf";
7 |
8 | pub fn load_config_into(args: &mut Vec, instance_list: &mut Vec) {
9 | let path = PathBuf::from({
10 | if cfg!(target_os = "windows") {
11 | CONFIG_PATH.replace("$CFG", &std::env::var("LOCALAPPDATA").expect("no localappdata var"))
12 | } else {
13 | CONFIG_PATH.replace("$CFG", &std::env::var("HOME").expect("no home var"))
14 | }
15 | });
16 |
17 | if path.exists() {
18 | let options = get_config(&path, "default");
19 | for line in options.lines() {
20 | let option: Vec<&str> = line.split('=').map(|s| s.trim()).collect();
21 | if option.len() != 2 {
22 | continue;
23 | }
24 |
25 | match option[0].to_lowercase().as_str() {
26 | "vcodec" => {
27 | args.push("-c".into());
28 | args.push(option[1].into())
29 | },
30 | "vquality" => {
31 | args.push("-q".into());
32 | args.push(option[1].into())
33 | },
34 | "aformat" => {
35 | args.push("-f".into());
36 | args.push(option[1].into())
37 | },
38 | "proxy" => {
39 | if option[1].to_lowercase().as_str() == "true" {
40 | args.push("-x".into())
41 | }
42 | }
43 | "download-mode" => {
44 | if option[1].to_lowercase().as_str() == "auto" {
45 | args.push("-=".into())
46 | } else if option[1].to_lowercase().as_str() == "audio" {
47 | args.push("-a".into())
48 | } else if option[1].to_lowercase().as_str() == "mute" {
49 | args.push("-m".into())
50 | }
51 | },
52 | "twitter-gif" => {
53 | if option[1].to_lowercase().as_str() == "true" {
54 | args.push("-g".into())
55 | }
56 | },
57 | "tt-full-audio" => {
58 | if option[1].to_lowercase().as_str() == "true" {
59 | args.push("-u".into())
60 | }
61 | },
62 | "tt-h265" => {
63 | if option[1].to_lowercase().as_str() == "true" {
64 | args.push("-h".into())
65 | }
66 | },
67 | "dublang" => {
68 | if option[1].to_lowercase().as_str() != "none" {
69 | args.push("-l".into());
70 | args.push(option[1].into())
71 | }
72 | },
73 | "no-metadata" => {
74 | if option[1].to_lowercase().as_str() == "true" {
75 | args.push("-n".into())
76 | }
77 | },
78 | "fname-style" => {
79 | args.push("-s".into());
80 | args.push(option[1].into())
81 | },
82 | "instance" => {
83 | args.push("-i".into());
84 | args.push(option[1].into())
85 | },
86 | "bitrate" => {
87 | args.push("-b".into());
88 | args.push(option[1].into())
89 | }
90 | _ => ()
91 | }
92 | }
93 | drop(options);
94 |
95 | let instances = get_config(&path, "default.instances");
96 | for line in instances.lines() {
97 | let mut url = line.replace("https://", "");
98 | if let Some(idx) = url.find('/') {
99 | url.truncate(idx);
100 | }
101 | instance_list.push(format!("{url}\n"));
102 | }
103 | }
104 | }
105 |
106 | fn get_config(path: &PathBuf, symbol: &str) -> String {
107 | let text = std::fs::read_to_string(path).unwrap_or("".into());
108 |
109 | let mut string = String::new();
110 | let mut select = false;
111 | let mut brackets = 0;
112 |
113 | for line in text.lines().into_iter() {
114 | if brackets == 2 { break }
115 | if !select && crate::strings::remove_trailing_whitespace(line) != format!("[{symbol}]") { continue }
116 | select = true;
117 | if line.chars().collect::>().first() == Some(&'[') { brackets += 1; continue }
118 |
119 | string.push_str(line);
120 | string.push('\n');
121 | }
122 | crate::strings::remove_trailing_whitespace(string)
123 | }
124 |
125 |
--------------------------------------------------------------------------------
/src/args/mod.rs:
--------------------------------------------------------------------------------
1 | use std::io::Read;
2 |
3 | pub mod types;
4 | mod config;
5 |
6 | #[derive(Debug, Clone, PartialEq)]
7 | pub struct Args {
8 | pub raw: Vec,
9 | pub parsed: bool,
10 | pub method: Option,
11 | pub c_url: Option,
12 | pub bulk_array: Option>,
13 | pub c_video_codec: types::VideoCodec,
14 | pub c_video_quality: u16,
15 | pub c_audio_format: types::AudioFormat,
16 | pub c_audio_bitrate: u16,
17 | pub c_download_mode: types::DownloadMode,
18 | pub c_twitter_gif: bool,
19 | pub c_tt_full_audio: bool,
20 | pub c_tt_h265: bool,
21 | pub c_disable_metadata: bool,
22 | pub accept_language: String,
23 | pub out_filename: Option,
24 | pub c_fname_style: types::FilenamePattern,
25 | pub same_filenames: bool,
26 | pub picker_choice: u8,
27 | pub cobalt_instance: String,
28 | pub help_flag: Option,
29 | pub c_proxy: bool
30 | }
31 | impl Args {
32 | pub fn get() -> Self {
33 | Self {
34 | raw: std::env::args().collect(),
35 | parsed: false,
36 | c_url: None,
37 | c_video_codec: types::VideoCodec::H264,
38 | c_video_quality: 1080,
39 | c_audio_format: types::AudioFormat::MP3,
40 | c_download_mode: types::DownloadMode::Auto,
41 | c_twitter_gif: false,
42 | out_filename: None,
43 | same_filenames: false,
44 | c_audio_bitrate: 128,
45 | help_flag: None,
46 | method: None,
47 | bulk_array: None,
48 | picker_choice: 0,
49 | c_fname_style: types::FilenamePattern::Classic,
50 | c_tt_full_audio: false,
51 | c_tt_h265: false,
52 | c_disable_metadata: false,
53 | c_proxy: false,
54 | cobalt_instance: String::from("api.cobalt.tools"),
55 | accept_language: String::from("en")
56 | }
57 | }
58 |
59 | pub fn parse(mut self) -> Result {
60 | self.parsed = true;
61 | self.raw = self.raw.iter().map(|str| {
62 | if !str.contains("https://") {
63 | str.to_lowercase()
64 | } else {
65 | str.into()
66 | }
67 | }).collect();
68 |
69 | match self.raw.get(1) {
70 | Some(method) => match method.as_str() {
71 | "help" | "-h" | "--help" | "h" => {
72 | self.method = Some(types::Method::Help);
73 | match self.raw.get(2) {
74 | Some(help) => match help.as_str() {
75 | "get" | "g" => self.help_flag = Some(types::Help::Get),
76 | "list" | "l" => self.help_flag = Some(types::Help::List),
77 | "bulk" | "b" => self.help_flag = Some(types::Help::Bulk),
78 | "help" | "h" => self.help_flag = Some(types::Help::Help),
79 | "examples" | "e" => self.help_flag = Some(types::Help::Examples),
80 | "gen-config" | "gc" => self.help_flag = Some(types::Help::GenConfig),
81 | "config" | "c" => self.help_flag = Some(types::Help::Config),
82 | _ => self.help_flag = Some(types::Help::Help)
83 | },
84 | None => self.help_flag = Some(types::Help::Help),
85 | }
86 | },
87 | "get" | "g" => {
88 | self.method = Some(types::Method::Get);
89 |
90 | let mut instance_list: Vec = Vec::new();
91 | let mut default_args: Vec = Vec::new();
92 | config::load_config_into(&mut default_args, &mut instance_list);
93 | let (pre_args, added_args) = self.raw.split_at(2);
94 | self.raw = [pre_args, &default_args, added_args].concat().to_vec();
95 |
96 | let mut idx = 1;
97 | let mut expected: Vec = Vec::new();
98 | let mut stdin = false;
99 | while let Some(arg) = self.raw.get(idx+1) {
100 | idx += 1;
101 | if expected.len() == 0 {
102 | let mut short = false;
103 | match arg.as_str() {
104 | "--vcodec" => expected.push(ExpectedFlags::VideoCodec),
105 | "--vquality" => expected.push(ExpectedFlags::VideoQuality),
106 | "--aformat" => expected.push(ExpectedFlags::AudioFormat),
107 | "--audio-only" => self.c_download_mode = types::DownloadMode::Audio,
108 | "--mute-audio" => self.c_download_mode = types::DownloadMode::Mute,
109 | "--auto" => self.c_download_mode = types::DownloadMode::Auto,
110 | "--twitter-gif" => self.c_twitter_gif = !self.c_twitter_gif,
111 | "--tt-full-audio" => self.c_tt_full_audio = !self.c_tt_full_audio,
112 | "--tt-h265" => self.c_tt_h265 = !self.c_tt_h265,
113 | "--dublang" => expected.push(ExpectedFlags::Language),
114 | "--no-metadata" => self.c_disable_metadata = !self.c_disable_metadata,
115 | "--output" => expected.push(ExpectedFlags::Output),
116 | "--fname-style" => expected.push(ExpectedFlags::FilenamePattern),
117 | "--pick" => expected.push(ExpectedFlags::Picker),
118 | "--instance" => expected.push(ExpectedFlags::Instance),
119 | "--bitrate" => expected.push(ExpectedFlags::Bitrate),
120 | "--proxy" => self.c_proxy = !self.c_proxy,
121 | _ => {
122 | if self.c_url == None && arg.contains("https://") {
123 | self.c_url = Some(arg.clone());
124 | continue;
125 | }
126 | if self.c_url.is_some() && arg.contains("https://") {
127 | return Err(types::ParseError::throw_invalid("You cannot have 2 URLs in the same GET command"));
128 | }
129 | for c in arg.chars() {
130 | if !short {
131 | if c == '-' {
132 | short = true;
133 | } else if c == '+' {
134 | stdin = true;
135 | } else {
136 | return Err(types::ParseError::throw_invalid(&format!("Unrecognized argument: {arg}")));
137 | }
138 | continue;
139 | }
140 | match c {
141 | 'c' => expected.push(ExpectedFlags::VideoCodec),
142 | 'q' => expected.push(ExpectedFlags::VideoQuality),
143 | 'f' => expected.push(ExpectedFlags::AudioFormat),
144 | 'a' => self.c_download_mode = types::DownloadMode::Audio,
145 | 'm' => self.c_download_mode = types::DownloadMode::Mute,
146 | 'g' => self.c_twitter_gif = !self.c_twitter_gif,
147 | 'u' => self.c_tt_full_audio = !self.c_tt_full_audio,
148 | 'h' => self.c_tt_h265 = !self.c_tt_h265,
149 | 'l' => {
150 | expected.push(ExpectedFlags::Language);
151 | },
152 | 'n' => self.c_disable_metadata = !self.c_disable_metadata,
153 | 'o' => expected.push(ExpectedFlags::Output),
154 | 's' => expected.push(ExpectedFlags::FilenamePattern),
155 | 'p' => expected.push(ExpectedFlags::Picker),
156 | 'i' => expected.push(ExpectedFlags::Instance),
157 | 'x' => self.c_proxy = !self.c_proxy,
158 | '=' => self.c_download_mode = types::DownloadMode::Auto,
159 | 'b' => expected.push(ExpectedFlags::Bitrate),
160 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid character {c} in multi-flag argument: {arg}")))
161 | }
162 | }
163 | }
164 | }
165 | } else {
166 | match expected.remove(0) {
167 | ExpectedFlags::VideoCodec => {
168 | match arg.as_str() {
169 | "h264" => self.c_video_codec = types::VideoCodec::H264,
170 | "av1" => self.c_video_codec = types::VideoCodec::AV1,
171 | "vp9" => self.c_video_codec = types::VideoCodec::VP9,
172 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid video codec: {arg}")))
173 | }
174 | },
175 | ExpectedFlags::VideoQuality => {
176 | match arg.as_str() {
177 | "144" | "480" | "720" | "1080" | "1440" | "2160" => self.c_video_quality = arg.parse().unwrap(),
178 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid video quality: {arg}")))
179 | }
180 | },
181 | ExpectedFlags::AudioFormat => {
182 | match arg.as_str() {
183 | "best" => self.c_audio_format = types::AudioFormat::BEST,
184 | "mp3" => self.c_audio_format = types::AudioFormat::MP3,
185 | "ogg" => self.c_audio_format = types::AudioFormat::OGG,
186 | "wav" => self.c_audio_format = types::AudioFormat::WAV,
187 | "opus" => self.c_audio_format = types::AudioFormat::OPUS,
188 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid audio format: {arg}")))
189 | }
190 | },
191 | ExpectedFlags::Output => {
192 | if arg.contains(".mp3") || arg.contains(".ogg") || arg.contains(".wav") || arg.contains(".opus") || arg.contains(".mp4") || arg.contains(".webm") || arg.contains(".gif") {
193 | self.out_filename = Some(arg.clone())
194 | } else {
195 | return Err(types::ParseError::throw_invalid("Output filename must be a video file type (supported: mp4/webm/gif), or an audio file type (supported: mp3/ogg/wav/opus)\nMake sure you choose the right file type for the chosen codec/format!"));
196 | }
197 | },
198 | ExpectedFlags::FilenamePattern => {
199 | match arg.as_str() {
200 | "classic" | "c" => self.c_fname_style = types::FilenamePattern::Classic,
201 | "pretty" | "p" => self.c_fname_style = types::FilenamePattern::Pretty,
202 | "basic" | "b" => self.c_fname_style = types::FilenamePattern::Basic,
203 | "nerdy" | "n" => self.c_fname_style = types::FilenamePattern::Nerdy,
204 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid filename style: {arg}")))
205 | }
206 | },
207 | ExpectedFlags::Picker => {
208 | if let Ok(int) = arg.parse::() {
209 | self.picker_choice = int;
210 | } else {
211 | return Err(types::ParseError::throw_invalid("Picker choice must be an integer between 0 and 255"));
212 | }
213 | },
214 | ExpectedFlags::Language => {
215 | self.accept_language = arg.clone();
216 | },
217 | ExpectedFlags::Instance => {
218 | let mut url = if let Ok(choice) = arg.parse::() {
219 | if let Some(url) = instance_list.get((choice-1) as usize) {
220 | url.clone()
221 | } else {
222 | return Err(types::ParseError::throw_invalid("Invalid instance quick-choice"))
223 | }
224 | } else {
225 | arg.clone()
226 | };
227 | url = url.replace("https://", "");
228 | if let Some(idx) = url.find('/') {
229 | url.truncate(idx);
230 | }
231 | self.cobalt_instance = url;
232 | },
233 | ExpectedFlags::Bitrate => {
234 | if arg == "320" || arg == "256" || arg == "128" || arg == "96" || arg == "64" || arg == "8" {
235 | self.c_audio_bitrate = arg.parse::().unwrap();
236 | } else {
237 | return Err(types::ParseError::throw_invalid("Make sure you select a valid bitrate! (320/256/128/96/64/8)"));
238 | }
239 | }
240 | }
241 | }
242 | }
243 | if stdin {
244 | let mut buf = String::new();
245 | std::io::stdin().read_to_string(&mut buf).unwrap_or(0);
246 | if self.c_url == None && buf.contains("https://") {
247 | self.c_url = Some(buf.trim().to_string());
248 | } else {
249 | if self.c_url.is_some() {
250 | return Err(types::ParseError::throw_invalid("You cannot have 2 URLs in the same GET command"));
251 | }
252 | return Err(types::ParseError::throw_invalid("URL from STDIN is invalid."))
253 | }
254 | }
255 | if self.c_url == None {
256 | return Err(types::ParseError::throw_incomplete("Missing URL from GET method"))
257 | }
258 | if expected.len() > 0 {
259 | let mut missing = String::new();
260 | for (i, v) in expected.iter().enumerate() {
261 | if i > 0 {
262 | missing.push_str(", ")
263 | }
264 | missing.push_str(&format!("{v:?}"));
265 | }
266 | return Err(types::ParseError::throw_incomplete(&format!("The following flags were specified but their values were not: {missing}")));
267 | }
268 | },
269 | "bulk" | "b" => {
270 | if let Some(action) = self.raw.get(2) {
271 | self.method = Some(types::Method::Bulk);
272 | match action.as_str() {
273 | "get" | "g" => {
274 | let mut url_list: Vec = Vec::new();
275 | let mut dummy_args = self.raw.clone();
276 | let mut has_url = false;
277 | (0..dummy_args.len()).rev().for_each(|i| {
278 | if dummy_args[i].contains("https://") {
279 | has_url = true;
280 | url_list.push(dummy_args[i].clone());
281 | dummy_args.remove(i);
282 | }
283 | });
284 | if !has_url {
285 | return Err(types::ParseError::throw_incomplete("Bulk get action is missing at least 1 URL"));
286 | }
287 | (0..=2).for_each(|_| {
288 | dummy_args.remove(0);
289 | });
290 | let get_flags = dummy_args.iter().map(|s| s.as_str()).collect::>();
291 | let get_flags = Self::override_args(&[&["get", "https://"], get_flags.as_slice()].concat()).parse();
292 | match get_flags {
293 | Ok(flags) => {
294 | let mut arg_array: Vec = Vec::new();
295 | for url in url_list {
296 | arg_array.push({
297 | let mut clone = flags.clone();
298 | clone.c_url = Some(url);
299 | clone
300 | });
301 | }
302 | self.bulk_array = Some(arg_array);
303 | if flags.out_filename.is_some() {
304 | self.same_filenames = true;
305 | }
306 | },
307 | Err(e) => return Err(types::ParseError::throw_bulkerr(&format!("Invalid flags | {}", e.print()))),
308 | }
309 | },
310 | "execute" | "exe" | "e" => {
311 | if let Some(filename) = self.raw.get(3) {
312 | if let Ok(contents) = std::fs::read_to_string(filename) {
313 | let mut arg_array: Vec = Vec::new();
314 | for (i, line) in contents.lines().enumerate() {
315 | let mut args_raw = line.split(" ").collect::>();
316 | args_raw.insert(0, "get");
317 | match Self::override_args(args_raw.as_slice()).parse() {
318 | Ok(args) => arg_array.push(args),
319 | Err(e) => return Err(types::ParseError::throw_bulkerr(&format!("On line {} | {}", i+1, e.print())))
320 | }
321 | }
322 | self.bulk_array = Some(arg_array);
323 | } else {
324 | return Err(types::ParseError::throw_invalid("The file \"{filename}\" either doesnt exist, or doesn't have proper permissions"));
325 | }
326 | } else {
327 | return Err(types::ParseError::throw_incomplete("Bulk execute action is missing the filename to execute commands from"));
328 | }
329 | },
330 | _ => return Err(types::ParseError::throw_invalid(&format!("Invalid action: {action}")))
331 | }
332 | } else {
333 | return Err(types::ParseError::throw_incomplete("Action is missing for bulk download"));
334 | }
335 | },
336 | "list" | "l" => self.method = Some(types::Method::List),
337 | "version" | "v" | "-v" | "--version" => self.method = Some(types::Method::Version),
338 | "cobalt-version" | "cv" | "c" => {
339 | if self.raw.get(2).is_some() {
340 | self.method = Some(types::Method::CobaltVersion(self.raw[2].clone()))
341 | } else {
342 | self.method = Some(types::Method::CobaltVersion(String::from("api.cobalt.tools")))
343 | }
344 | },
345 | "gen-config" | "gc" => self.method = Some(types::Method::GenConfig),
346 |
347 | unknown => return Err(types::ParseError::throw_invalid(&format!("Unrecognized tcobalt method: {}", unknown)))
348 | },
349 | None => unreachable!()
350 | }
351 | Ok(self)
352 | }
353 |
354 | pub fn override_args(args: &[&str]) -> Self {
355 | let mut args = args.to_vec().iter().map(|str| str.to_string()).collect::>();
356 | args.insert(0, "tcb".to_string());
357 | let mut template = Self::get();
358 | template.raw = args;
359 | template
360 | }
361 | }
362 |
363 | #[derive(Debug)]
364 | enum ExpectedFlags {
365 | VideoCodec, VideoQuality, AudioFormat, Output, FilenamePattern, Picker, Language, Instance, Bitrate
366 | }
367 |
--------------------------------------------------------------------------------
/src/args/types.rs:
--------------------------------------------------------------------------------
1 | #[derive(Debug, PartialEq, Eq, Clone)]
2 | pub enum VideoCodec {
3 | H264, AV1, VP9
4 | }
5 | impl Default for VideoCodec {
6 | fn default() -> Self {
7 | Self::H264
8 | }
9 | }
10 | impl VideoCodec {
11 | pub fn print(&self) -> String {
12 | format!("{self:?}").to_lowercase()
13 | }
14 | }
15 |
16 | #[derive(Debug, PartialEq, Eq, Clone)]
17 | pub enum AudioFormat {
18 | BEST, MP3, OGG, WAV, OPUS
19 | }
20 | impl Default for AudioFormat {
21 | fn default() -> Self {
22 | Self::MP3
23 | }
24 | }
25 | impl AudioFormat {
26 | pub fn print(&self) -> String {
27 | format!("{self:?}").to_lowercase()
28 | }
29 | }
30 |
31 | #[derive(Debug, PartialEq, Eq, Clone)]
32 | pub enum FilenamePattern {
33 | Classic, Pretty, Basic, Nerdy
34 | }
35 | impl Default for FilenamePattern {
36 | fn default() -> Self {
37 | Self::Classic
38 | }
39 | }
40 | impl FilenamePattern {
41 | pub fn print(&self) -> String {
42 | format!("{self:?}").to_lowercase()
43 | }
44 | }
45 | #[derive(Debug, PartialEq, Eq, Clone)]
46 | pub enum DownloadMode {
47 | Auto, Audio, Mute
48 | }
49 | impl Default for DownloadMode {
50 | fn default() -> Self {
51 | Self::Auto
52 | }
53 | }
54 |
55 | #[derive(Debug, PartialEq, Eq, Clone)]
56 | pub enum Help {
57 | Get, List, Bulk, Help, Examples, Config, GenConfig
58 | }
59 | #[derive(Debug, PartialEq, Eq, Clone)]
60 | pub enum Method {
61 | Get, List, Bulk, Help, Version, CobaltVersion(String), GenConfig
62 | }
63 |
64 | #[derive(Debug, PartialEq, Eq)]
65 | enum ParseErrType {
66 | InvalidArg,
67 | Incomplete,
68 | BulkParseError
69 | }
70 | #[derive(Debug)]
71 | pub struct ParseError {
72 | err_type: ParseErrType,
73 | message: String
74 | }
75 | impl ParseError {
76 | pub fn throw_incomplete(message: &str) -> Self {
77 | Self {
78 | err_type: ParseErrType::Incomplete,
79 | message: message.to_string()
80 | }
81 | }
82 | pub fn throw_invalid(message: &str) -> Self {
83 | Self {
84 | err_type: ParseErrType::InvalidArg,
85 | message: message.to_string()
86 | }
87 | }
88 | pub fn throw_bulkerr(message: &str) -> Self {
89 | Self {
90 | err_type: ParseErrType::BulkParseError,
91 | message: message.to_string()
92 | }
93 | }
94 | pub fn print(&self) -> String {
95 | format!("{:?}: {}", self.err_type , &self.message)
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/json.rs:
--------------------------------------------------------------------------------
1 | use std::collections::HashMap;
2 |
3 | pub fn parse(json: impl ToString) -> Result, String> {
4 | let json = json.to_string();
5 |
6 | let mut ignore_whitespace = true;
7 | let mut escape = false;
8 | let mut can_continue = false;
9 | let mut closing_expect = false;
10 | let mut str_finish = false;
11 | let mut is_float = false;
12 | let mut reading = Reader::None;
13 | let mut global_object = false;
14 | let mut object_level: u16 = 0;
15 | let mut array_level: u16 = 0;
16 | let mut history: Vec = Vec::new();
17 | let mut key_level: u8 = 0;
18 | let mut last_push_object = false;
19 | let mut new_object = false;
20 | let mut new_array = false;
21 | let mut using_quote = '\"';
22 |
23 | let mut key_buf: String = String::new();
24 | let mut key_array: Vec = Vec::new();
25 | let mut str_buf = String::new();
26 | let mut num_buf = String::new();
27 | let mut bool_buf = String::new();
28 | let mut null_buf = String::new();
29 | let mut array_storage: Vec> = Vec::new();
30 | #[allow(unused_assignments)]
31 | let mut temp_array: Vec = Vec::new();
32 | let mut current_array: Vec = Vec::new();
33 | let mut subobject_storage: Vec> = Vec::new();
34 | #[allow(unused_assignments)]
35 | let mut temp_object: HashMap = HashMap::new();
36 | let mut current_subobject: HashMap = HashMap::new();
37 |
38 | let mut parsed_map: HashMap = HashMap::new();
39 | for (i, c) in json.chars().enumerate() {
40 | if !((c.is_control() || c == ' ') && ignore_whitespace) {
41 | // println!("{:?} : {c} - {key_level} ; a{array_level} o{object_level}", history);
42 |
43 | if object_level == 0 {
44 | if global_object == false {
45 | if c == '{' {
46 | object_level = 1;
47 | global_object = true;
48 | new_object = true;
49 | continue
50 | }
51 | return Err("First non-whitespace character has to be '{'".to_string())
52 | }
53 | break
54 | }
55 | if escape {
56 | escape = false;
57 | match reading {
58 | Reader::Key => key_buf.push(c),
59 | Reader::ValStr => str_buf.push(c),
60 | _ => unreachable!()
61 | }
62 | continue
63 | }
64 | if c == '\\' && (reading == Reader::Key || reading == Reader::ValStr) {
65 | escape = true;
66 | continue;
67 | }
68 |
69 | if c == ']' && new_array {
70 | let next_array = history.get(sub_without_overflow(history.len(), 2)) == Some(&ReadHistory::Array);
71 |
72 | assert_eq!(history.pop().unwrap(), ReadHistory::Array);
73 | last_push_object = false;
74 | array_level -= 1;
75 | match array_level {
76 | 0 => {
77 | match object_level {
78 | 1 => {
79 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
80 | },
81 | _ => {
82 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
83 | }
84 | }
85 | current_array.clear();
86 | key_buf.clear();
87 | },
88 | _ => {
89 | if next_array {
90 | temp_array = current_array.clone();
91 | current_array = array_storage.pop().unwrap();
92 | current_array.push(JsonValue::Array(temp_array.clone()));
93 | temp_array.clear();
94 | } else {
95 | match object_level {
96 | 1 => {
97 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
98 | current_array = array_storage.pop().unwrap();
99 | }
100 | _ => {
101 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
102 | current_array = array_storage.pop().unwrap();
103 | }
104 | }
105 | key_buf.clear();
106 | }
107 | }
108 | }
109 | closing_expect = true;
110 | can_continue = true;
111 | key_level = 2;
112 | continue;
113 | } else if c == '}' && new_object {
114 | let next_array = history.get(sub_without_overflow(history.len(), 2)) == Some(&ReadHistory::Array);
115 |
116 | last_push_object = true;
117 | object_level -= 1;
118 | if next_array {
119 | key_buf = key_array.pop().unwrap();
120 | match object_level {
121 | 1 => {
122 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
123 | current_array.push(JsonValue::Object(current_subobject.clone()));
124 | current_subobject.clear();
125 | },
126 | 0 => { key_level = 0; break },
127 | _ => {
128 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
129 | temp_object = current_subobject.clone();
130 | current_subobject = subobject_storage.pop().unwrap();
131 | current_array.push(JsonValue::Object(temp_object.clone()));
132 | temp_object.clear();
133 | }
134 | }
135 | } else {
136 | match object_level {
137 | 1 => {
138 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
139 | parsed_map.insert(key_array.pop().unwrap(), JsonValue::Object(current_subobject.clone()));
140 | current_subobject.clear();
141 | },
142 | 0 => { key_level = 0; break },
143 | _ => {
144 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
145 | temp_object = current_subobject.clone();
146 | current_subobject = subobject_storage.pop().unwrap();
147 | current_subobject.insert(key_array.pop().unwrap(), JsonValue::Object(temp_object.clone()));
148 | temp_object.clear();
149 | }
150 | }
151 | }
152 | closing_expect = true;
153 | can_continue = true;
154 | key_level = 2;
155 | continue;
156 | }
157 | new_object = false;
158 | new_array = false;
159 |
160 | match key_level {
161 | 0 => match reading {
162 | Reader::None => match c {
163 | '"' | '\'' => {
164 | reading = Reader::Key;
165 | ignore_whitespace = false;
166 | using_quote = c;
167 | },
168 | _ => return Err(format!("Double quote expected, got '{c}' at char {i}"))
169 | },
170 | Reader::Key => match c {
171 | '"' | '\'' => {
172 | if c != using_quote {
173 | key_buf.push(c);
174 | continue;
175 | }
176 | reading = Reader::None;
177 | key_level = 1;
178 | ignore_whitespace = true;
179 | },
180 | _ => {
181 | key_buf.push(c);
182 | }
183 | },
184 | _ => unreachable!()
185 | },
186 | 1 => {
187 | if c == ':' {
188 | key_level = 2
189 | } else {
190 | return Err(format!("Colon expected, got '{c}' at char {i}"))
191 | }
192 | },
193 | 2 => {
194 | let mut is_array = false;
195 | if let Some(first_hist) = history.last() {
196 | if first_hist == &ReadHistory::Array {
197 | is_array = true;
198 | } else if let Some(second_hist) = history.get(sub_without_overflow(history.len(), 2)) {
199 | if second_hist == &ReadHistory::Array && (reading != Reader::None || str_finish) {
200 | is_array = true;
201 | }
202 | }
203 | }
204 | if ((c == ',' && !last_push_object) || (c == '}' && !is_array) || (c == ']' && is_array)) && (reading != Reader::None || closing_expect || str_finish) && reading != Reader::ValStr {
205 | reading = Reader::None;
206 | if !can_continue {
207 | return Err(format!("Character {c} placed too early at char {i}"));
208 | }
209 | let mut already_checked_cb = false;
210 | let mut already_checked_ab = false;
211 |
212 | let next_array = history.get(sub_without_overflow(history.len(), 2)) == Some(&ReadHistory::Array);
213 | let nextnext_array = history.get(sub_without_overflow(history.len(), 3)) == Some(&ReadHistory::Array);
214 |
215 | let mut get = history.pop();
216 | if c == ',' && (get == Some(ReadHistory::Object) || get == Some(ReadHistory::Array)) {
217 | history.push(get.take().unwrap());
218 | }
219 | if let Some(hist) = get.take() {
220 | match hist {
221 | ReadHistory::Str => {
222 | str_finish = false;
223 | },
224 | ReadHistory::Num => {
225 | if num_buf.chars().last() == Some('.') {
226 | return Err(format!("Expected digits after decimal, got: {c} at char {i}"));
227 | }
228 | match is_float {
229 | true => {
230 | if is_array {
231 | current_array.push(JsonValue::Float(num_buf.clone().parse().unwrap()));
232 | } else {
233 | match object_level {
234 | 1 => {
235 | parsed_map.insert(key_buf.clone(), JsonValue::Float(num_buf.clone().parse().unwrap()));
236 | },
237 | _ => {
238 | current_subobject.insert(key_buf.clone(), JsonValue::Float(num_buf.clone().parse().unwrap()));
239 | }
240 | }
241 | }
242 | },
243 | false => {
244 | if is_array {
245 | current_array.push(JsonValue::Int(num_buf.clone().parse().unwrap()));
246 | } else {
247 | match object_level {
248 | 1 => {
249 | parsed_map.insert(key_buf.clone(), JsonValue::Int(num_buf.clone().parse().unwrap()));
250 | },
251 | _ => {
252 | current_subobject.insert(key_buf.clone(), JsonValue::Int(num_buf.clone().parse().unwrap()));
253 | }
254 | }
255 | }
256 | }
257 | }
258 | is_float = false;
259 | ignore_whitespace = true;
260 | if !is_array {
261 | key_buf.clear();
262 | }
263 | num_buf.clear();
264 | },
265 | ReadHistory::Bool => {
266 | if !(bool_buf == "true" || bool_buf == "false") {
267 | return Err(format!("Incomplete bool value with char {c} at char {i}"));
268 | }
269 | if is_array {
270 | current_array.push(JsonValue::Bool(bool_buf.clone().parse().unwrap()));
271 | } else {
272 | match object_level {
273 | 1 => {
274 | parsed_map.insert(key_buf.clone(), JsonValue::Bool(bool_buf.clone().parse().unwrap()));
275 | }
276 | _ => {
277 | current_subobject.insert(key_buf.clone(), JsonValue::Bool(bool_buf.clone().parse().unwrap()));
278 | }
279 | }
280 | }
281 | ignore_whitespace = true;
282 | if !is_array {
283 | key_buf.clear();
284 | }
285 | bool_buf.clear();
286 | },
287 | ReadHistory::Null => {
288 | if null_buf != "null" {
289 | return Err(format!("Incomplete null value with char {c} at char {i}"));
290 | }
291 | if is_array {
292 | current_array.push(JsonValue::Null);
293 | } else {
294 | match object_level {
295 | 1 => {
296 | parsed_map.insert(key_buf.clone(), JsonValue::Null);
297 | }
298 | _ => {
299 | current_subobject.insert(key_buf.clone(), JsonValue::Null);
300 | }
301 | }
302 | }
303 | ignore_whitespace = true;
304 | if !is_array {
305 | key_buf.clear();
306 | }
307 | null_buf.clear();
308 | },
309 | ReadHistory::Array => {
310 | already_checked_ab = true;
311 | last_push_object = false;
312 | array_level -= 1;
313 | match array_level {
314 | 0 => {
315 | match object_level {
316 | 1 => {
317 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
318 | },
319 | _ => {
320 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
321 | }
322 | }
323 | current_array.clear();
324 | key_buf.clear();
325 | },
326 | _ => {
327 | if next_array {
328 | temp_array = current_array.clone();
329 | current_array = array_storage.pop().unwrap();
330 | current_array.push(JsonValue::Array(temp_array.clone()));
331 | temp_array.clear();
332 | } else {
333 | match object_level {
334 | 1 => {
335 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
336 | current_array = array_storage.pop().unwrap();
337 | }
338 | _ => {
339 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
340 | current_array = array_storage.pop().unwrap();
341 | }
342 | }
343 | key_buf.clear();
344 | }
345 | }
346 | }
347 | closing_expect = true;
348 | },
349 | ReadHistory::Object => {
350 | already_checked_cb = true;
351 | last_push_object = true;
352 | object_level -= 1;
353 | if next_array {
354 | key_buf = key_array.pop().unwrap();
355 | match object_level {
356 | 1 => {
357 | current_array.push(JsonValue::Object(current_subobject.clone()));
358 | current_subobject.clear();
359 | },
360 | 0 => { key_level = 0; break },
361 | _ => {
362 | temp_object = current_subobject.clone();
363 | current_subobject = subobject_storage.pop().unwrap();
364 | current_array.push(JsonValue::Object(temp_object.clone()));
365 | temp_object.clear();
366 | }
367 | }
368 | } else {
369 | match object_level {
370 | 1 => {
371 | parsed_map.insert(key_array.pop().unwrap(), JsonValue::Object(current_subobject.clone()));
372 | current_subobject.clear();
373 |
374 | },
375 | 0 => { key_level = 0; break },
376 | _ => {
377 | temp_object = current_subobject.clone();
378 | current_subobject = subobject_storage.pop().unwrap();
379 | current_subobject.insert(key_array.pop().unwrap(), JsonValue::Object(temp_object.clone()));
380 | temp_object.clear();
381 | }
382 | }
383 | }
384 | closing_expect = true;
385 | }
386 | }
387 | }
388 | if c == ',' {
389 | if !is_array {
390 | key_level = 0;
391 | }
392 | closing_expect = false;
393 | can_continue = false;
394 | } else if c == ']' && !already_checked_ab {
395 | assert_eq!(history.pop().unwrap(), ReadHistory::Array);
396 | last_push_object = false;
397 | array_level -= 1;
398 | match array_level {
399 | 0 => {
400 | match object_level {
401 | 1 => {
402 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
403 | },
404 | _ => {
405 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
406 | }
407 | }
408 | current_array.clear();
409 | key_buf.clear();
410 | },
411 | _ => {
412 | if nextnext_array {
413 | temp_array = current_array.clone();
414 | current_array = array_storage.pop().unwrap();
415 | current_array.push(JsonValue::Array(temp_array.clone()));
416 | temp_array.clear();
417 | } else {
418 | match object_level {
419 | 1 => {
420 | parsed_map.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
421 | current_array = array_storage.pop().unwrap();
422 | }
423 | _ => {
424 | current_subobject.insert(key_buf.clone(), JsonValue::Array(current_array.clone()));
425 | current_array = array_storage.pop().unwrap();
426 | }
427 | }
428 | key_buf.clear();
429 | }
430 | }
431 | }
432 | closing_expect = true;
433 | } else if c == '}' && !already_checked_cb {
434 | last_push_object = true;
435 | object_level -= 1;
436 | if nextnext_array {
437 | key_buf = key_array.pop().unwrap();
438 | match object_level {
439 | 1 => {
440 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
441 | current_array.push(JsonValue::Object(current_subobject.clone()));
442 | current_subobject.clear();
443 | },
444 | 0 => { key_level = 0; break },
445 | _ => {
446 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
447 | temp_object = current_subobject.clone();
448 | current_subobject = subobject_storage.pop().unwrap();
449 | current_array.push(JsonValue::Object(temp_object.clone()));
450 | temp_object.clear();
451 | }
452 | }
453 | } else {
454 | match object_level {
455 | 1 => {
456 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
457 | parsed_map.insert(key_array.pop().unwrap(), JsonValue::Object(current_subobject.clone()));
458 | current_subobject.clear();
459 | },
460 | 0 => { key_level = 0; break },
461 | _ => {
462 | assert_eq!(history.pop().unwrap(), ReadHistory::Object);
463 | temp_object = current_subobject.clone();
464 | current_subobject = subobject_storage.pop().unwrap();
465 | current_subobject.insert(key_array.pop().unwrap(), JsonValue::Object(temp_object.clone()));
466 | temp_object.clear();
467 | }
468 | }
469 | }
470 | closing_expect = true;
471 | }
472 | continue;
473 | }
474 | if c == ',' && last_push_object {
475 | closing_expect = false;
476 | last_push_object = false;
477 | continue;
478 | }
479 | if closing_expect {
480 | return Err(format!("Expected comma or closing bracket at char {i}"))
481 | }
482 | last_push_object = false;
483 | match reading {
484 | Reader::None => match c {
485 | '{' => {
486 | match object_level {
487 | 0 => unreachable!(),
488 | 1 => {
489 | key_array.push(key_buf.clone());
490 | key_buf.clear();
491 | },
492 | u16::MAX => return Err(format!("Maximum object nesting reached at char {i}")),
493 | _ => {
494 | subobject_storage.push(current_subobject.clone());
495 | current_subobject.clear();
496 | key_array.push(key_buf.clone());
497 | key_buf.clear();
498 | }
499 | }
500 | object_level += 1;
501 | new_object = true;
502 | history.push(ReadHistory::Object);
503 | key_level = 0;
504 | },
505 | '[' => {
506 | match array_level {
507 | 0 => (),
508 | u16::MAX => return Err(format!("Maximum array nesting reached at char {i}")),
509 | _ => {
510 | array_storage.push(current_array.clone());
511 | current_array.clear();
512 | }
513 | }
514 | array_level += 1;
515 | new_array = true;
516 | history.push(ReadHistory::Array);
517 | },
518 | '\"' | '\'' => {
519 | using_quote = c;
520 | reading = Reader::ValStr;
521 | ignore_whitespace = false;
522 | history.push(ReadHistory::Str);
523 | can_continue = true;
524 | },
525 | '0'..='9' => {
526 | reading = Reader::ValNum;
527 | num_buf.push(c);
528 | history.push(ReadHistory::Num);
529 | ignore_whitespace = false;
530 | can_continue = true;
531 | },
532 | '.' => {
533 | reading = Reader::ValNum;
534 | num_buf.push('0');
535 | num_buf.push(c);
536 | ignore_whitespace = false;
537 | can_continue = true;
538 | history.push(ReadHistory::Num);
539 | }
540 | 't' | 'f' => {
541 | reading = Reader::ValBool;
542 | bool_buf.push(c);
543 | ignore_whitespace = false;
544 | history.push(ReadHistory::Bool);
545 | can_continue = true;
546 | },
547 | 'n' => {
548 | reading = Reader::ValNull;
549 | null_buf.push(c);
550 | ignore_whitespace = false;
551 | history.push(ReadHistory::Null);
552 | can_continue = true;
553 | },
554 | e => return Err(format!("Invalid character: {e} at char {i}"))
555 | }
556 | Reader::Key => unreachable!(),
557 | Reader::ValStr => match c {
558 | '"' | '\'' => {
559 | if c != using_quote {
560 | str_buf.push(c);
561 | continue;
562 | }
563 | reading = Reader::None;
564 | ignore_whitespace = true;
565 | if is_array {
566 | current_array.push(JsonValue::Str(str_buf.clone()));
567 | } else {
568 | match object_level {
569 | 1 => {
570 | parsed_map.insert(key_buf.clone(), JsonValue::Str(str_buf.clone()));
571 | },
572 | _ => {
573 | current_subobject.insert(key_buf.clone(), JsonValue::Str(str_buf.clone()));
574 | }
575 | }
576 | }
577 | if !is_array {
578 | key_buf.clear();
579 | }
580 | str_buf.clear();
581 | str_finish = true;
582 | },
583 | _ => str_buf.push(c)
584 | },
585 | Reader::ValNum => match c {
586 | '0'..='9' => num_buf.push(c),
587 | '.' => {
588 | if !is_float {
589 | is_float = true;
590 | num_buf.push(c);
591 | } else {
592 | return Err("Floats can only have one decimal character".to_string())
593 | }
594 | },
595 | o => return Err(format!("Invalid character '{o}' found in number at char {i}"))
596 | },
597 | Reader::ValBool => match bool_buf.as_str() {
598 | "t" => if c == 'r' { bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
599 | "tr" => if c == 'u' { bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
600 | "tru" => if c == 'e' { ignore_whitespace = true; bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
601 | "f" => if c == 'a' { bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
602 | "fa" => if c == 'l' { bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
603 | "fal" => if c == 's' { bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
604 | "fals" => if c == 'e' { ignore_whitespace = true; bool_buf.push(c) } else { return Err(format!("Invalid character in bool: {c}")) }
605 | _ => return Err(format!("Invalid character after bool: {c}"))
606 | },
607 | Reader::ValNull => match null_buf.as_str() {
608 | "n" => if c == 'u' { null_buf.push(c) } else { return Err(format!("Invalid character in nullval: {c}")) }
609 | "nu" => if c == 'l' { null_buf.push(c) } else { return Err(format!("Invalid character in nullval: {c}")) }
610 | "nul" => if c == 'l' { null_buf.push(c) } else { return Err(format!("Invalid character in nullval: {c}")) }
611 | _ => return Err(format!("Invalid character after null: {c}"))
612 | }
613 | }
614 | },
615 | _ => unreachable!()
616 | }
617 | }
618 | };
619 |
620 | if key_level != 0 || object_level != 0 {
621 | return Err(format!("The given JSON is incomplete: {key_level}-{object_level} (both need to be 0)"));
622 | }
623 |
624 | Ok(parsed_map)
625 | }
626 |
627 | #[allow(unused)]
628 | #[derive(PartialEq, Eq, Debug)]
629 | enum Reader {
630 | None,
631 | Key,
632 | ValStr,
633 | ValNum,
634 | ValBool,
635 | ValNull
636 | }
637 | #[allow(unused)]
638 | #[derive(PartialEq, Eq, Debug)]
639 | enum ReadHistory {
640 | Str, Num, Bool, Null, Array, Object
641 | }
642 |
643 | #[allow(unused)]
644 | #[derive(Clone, Debug, PartialEq)]
645 | pub enum JsonValue {
646 | Str(String),
647 | Int(i128),
648 | Float(f64),
649 | Bool(bool),
650 | Null,
651 | Array(Vec),
652 | Object(HashMap)
653 | }
654 | #[allow(unused)]
655 | impl JsonValue {
656 | pub fn type_of<'a>(&self) -> &'a str {
657 | match self {
658 | JsonValue::Str(_) => "string",
659 | JsonValue::Int(_) => "int",
660 | JsonValue::Float(_) => "float",
661 | JsonValue::Bool(_) => "bool",
662 | JsonValue::Null => "null",
663 | JsonValue::Array(_) => "array",
664 | JsonValue::Object(_) => "object",
665 | }
666 | }
667 | pub fn get_str(&self) -> Result {
668 | if let Self::Str(val) = self {
669 | return Ok(val.to_string())
670 | }
671 | Err(false)
672 | }
673 | pub fn get_int(&self) -> Result {
674 | if let Self::Int(val) = self {
675 | return Ok(*val)
676 | }
677 | Err(false)
678 | }
679 | pub fn get_float(&self) -> Result {
680 | if let Self::Float(val) = self {
681 | return Ok(*val)
682 | }
683 | Err(false)
684 | }
685 | pub fn get_bool(&self) -> Result {
686 | if let Self::Bool(val) = self {
687 | return Ok(*val)
688 | }
689 | Err(false)
690 | }
691 | pub fn get_null(&self) -> Result<(), bool> {
692 | if let Self::Null = self {
693 | return Ok(())
694 | }
695 | Err(false)
696 | }
697 | pub fn get_array(&self) -> Result, bool> {
698 | if let Self::Array(val) = self {
699 | return Ok(val.clone())
700 | }
701 | Err(false)
702 | }
703 | pub fn get_object(&self) -> Result, bool> {
704 | if let Self::Object(val) = self {
705 | return Ok(val.clone())
706 | }
707 | Err(false)
708 | }
709 | }
710 |
711 | fn sub_without_overflow(num: usize, subtractor: usize) -> usize {
712 | if num < subtractor {
713 | 0
714 | } else {
715 | num - subtractor
716 | }
717 | }
718 |
--------------------------------------------------------------------------------
/src/main.rs:
--------------------------------------------------------------------------------
1 | mod json;
2 | mod args;
3 | mod strings;
4 | mod process;
5 |
6 | use process as proc;
7 | use args as tcargs;
8 | use args::Args;
9 |
10 | use std::pin::Pin;
11 | use std::sync::Arc;
12 | use tokio::sync::RwLock;
13 |
14 | const VERSION: &str = include_str!("version");
15 |
16 | #[tokio::main]
17 | async fn main() -> std::process::ExitCode {
18 | if std::env::args().len() == 1 {
19 | println!("tcobalt Command Line Utility; run `tcb help` for help");
20 | return std::process::ExitCode::SUCCESS;
21 | }
22 |
23 | let debug = std::env::var("TCOBALT_DEBUG").is_ok_and(|v| v == 1.to_string());
24 | if debug { eprintln!("[DEBUG] Parsing arguments ..") };
25 | let args = match Args::get().parse() {
26 | Ok(parsed) => parsed,
27 | Err(err) => {
28 | eprintln!("Invalid command syntax");
29 | eprintln!("{}", err.print());
30 | return std::process::ExitCode::FAILURE;
31 | },
32 | };
33 | if let Some(help_flag) = args.help_flag {
34 | match help_flag {
35 | args::types::Help::Help => println!("{}", strings::get_help()),
36 | args::types::Help::List => println!("{}", strings::get_str("usage", "list")),
37 | args::types::Help::Bulk => println!("{}", strings::get_str("usage", "bulk")),
38 | args::types::Help::Get => println!("{}", strings::get_str("usage", "get")),
39 | args::types::Help::Examples => println!("{}", strings::get_str("usage", "examples")),
40 | args::types::Help::GenConfig => println!("{}", strings::get_str("usage", "gen-config")),
41 | args::types::Help::Config => println!("{}", strings::get_str("usage", "config")),
42 | }
43 | return std::process::ExitCode::SUCCESS;
44 | }
45 | match args.method.clone().expect("Failed to catch invalid method early") {
46 | args::types::Method::Get => {
47 | if debug { eprintln!("[DEBUG] Executing GET method\n") };
48 | let success = execute_get_media(args, 0, debug).await;
49 | if debug { eprintln!("\n[DEBUG] GET method is complete") };
50 | if !success {
51 | return std::process::ExitCode::FAILURE;
52 | }
53 | },
54 | args::types::Method::Bulk => {
55 | let failed: Arc> = Arc::new(RwLock::new(false));
56 | let mut futures_array: Vec>>> = Vec::new();
57 | let mut i = 0;
58 | if debug { eprintln!("[DEBUG] Collecting bulk tasks ...") };
59 | args.bulk_array.unwrap().iter().for_each(|a| {
60 | if args.same_filenames {
61 | i += 1;
62 | }
63 | let args = a.clone();
64 | let switch = Arc::clone(&failed);
65 | let task = async move {
66 | let success = execute_get_media(args, i, debug).await;
67 | if !success {
68 | let mut lock = switch.write().await;
69 | *lock = true;
70 | }
71 | };
72 | futures_array.push(Box::pin(task));
73 | });
74 |
75 | if debug { eprintln!("[DEBUG] Executing all tasks asynchronously ...\n") };
76 | futures::future::join_all(futures_array).await;
77 | if debug { eprintln!("\n[DEBUG] Execution has completed") };
78 |
79 | if failed.read().await.clone() == true {
80 | return std::process::ExitCode::FAILURE;
81 | }
82 | },
83 | args::types::Method::List => println!("{}", strings::get_str("info", "supported")),
84 | args::types::Method::Help => unreachable!(),
85 | args::types::Method::Version => println!("{}", strings::get_str("info", "version").replace("{}", VERSION.trim())),
86 | args::types::Method::CobaltVersion(api_url) => {
87 | let request = reqwest::Client::new().get(format!("https://{}/", api_url))
88 | .header("User-Agent", &format!("tcobalt {}", VERSION.trim()));
89 | if debug { eprintln!("[DEBUG] Sending GET request to cobalt ...") };
90 | let ver = match request.send().await {
91 | Ok(res) => {
92 | res.text().await.expect("cobalt returned nothing")
93 | },
94 | Err(e) => {
95 | eprintln!("Cobalt server did not respond: {}", e.to_string());
96 | return std::process::ExitCode::FAILURE;
97 | }
98 | };
99 | if debug { eprintln!("[DEBUG] Response received, parsing json ...") };
100 | let stats = match json::parse(&ver) {
101 | Ok(j) => j,
102 | Err(e) => {
103 | eprintln!("{}", proc::print_json_error(e, ver));
104 | return std::process::ExitCode::FAILURE;
105 | }
106 | };
107 | let cobalt = stats.get("cobalt").unwrap().get_object().unwrap();
108 | let git = stats.get("git").unwrap().get_object().unwrap();
109 | let version = cobalt.get("version").unwrap().get_str().unwrap();
110 | let commit = git.get("commit").unwrap().get_str().unwrap();
111 | let branch = git.get("branch").unwrap().get_str().unwrap();
112 | println!("Cobalt (by wukko and jj) version {version}");
113 | println!("Latest commit on branch \"{branch}\": {commit}");
114 | },
115 | args::types::Method::GenConfig => {
116 | let text = strings::get_str("info", "default-config").replace("\\", "");
117 | let path = std::path::PathBuf::from({
118 | if cfg!(target_os = "windows") {
119 | "$CFG\\tcobalt.conf".replace("$CFG", &std::env::var("LOCALAPPDATA").expect("no localappdata var"))
120 | } else {
121 | "$CFG/.config/tcobalt.conf".replace("$CFG", &std::env::var("HOME").expect("no home var"))
122 | }
123 | });
124 |
125 | if let Ok(()) = std::fs::write(&path, text) {
126 | println!("Wrote default config to {}", path.to_string_lossy());
127 | return std::process::ExitCode::SUCCESS
128 | } else {
129 | return std::process::ExitCode::FAILURE
130 | }
131 | }
132 | }
133 | std::process::ExitCode::SUCCESS
134 | }
135 |
136 | async fn execute_get_media(args: Args, bulk: u16, debug: bool) -> bool {
137 | let json = proc::cobalt_args(&args);
138 | let download_url: &str = args.c_url.as_ref().unwrap();
139 |
140 | let request = reqwest::Client::new().post(format!("https://{}/", &args.cobalt_instance))
141 | .header("User-Agent", &format!("tcobalt {}", VERSION.trim()))
142 | .header("Accept", "application/json")
143 | .header("Content-Type", "application/json")
144 | .body(json);
145 |
146 | if debug { eprintln!("[DEBUG {download_url}] Sending POST request to cobalt server ...") };
147 | let res = attempt!(request.send().await, "Cobalt server did not respond:\n\"{}\"\n(when downloading from {download_url})");
148 |
149 | let body = res.text().await.unwrap();
150 | if debug { eprintln!("[DEBUG {download_url}] Response received, parsing json ...") };
151 | let json = attempt!(json::parse(&body), proc::print_json_error("{}".into(), body));
152 |
153 | let status = json.get("status".into()).unwrap().get_str().unwrap();
154 | match status.as_str() {
155 | "error" => {
156 | let text = json.get("error".into()).unwrap().get_object().unwrap().get("code".into()).unwrap().get_str().unwrap();
157 | eprintln!("Cobalt returned error: \"{text}\" (when downloading from {download_url})");
158 | return false;
159 | },
160 | "tunnel" | "redirect" | "picker" => {
161 | if debug { eprintln!("[DEBUG {download_url}] Cobalt returned a response") };
162 |
163 | let url = proc::get_url(&args, &status, &json);
164 |
165 | let media = if args.c_download_mode == tcargs::types::DownloadMode::Audio {
166 | "audio"
167 | } else {
168 | "video"
169 | };
170 |
171 | let stream_request = reqwest::Client::new().get(url)
172 | .header("User-Agent", &format!("tcobalt {}", VERSION.trim()));
173 |
174 | let res = attempt!(stream_request.send().await, "Live renderer did not respond:\n\"{}\"\n(when downloading from {download_url})");
175 |
176 | if debug { eprintln!("[DEBUG {download_url}] Response received from stream") };
177 | let mut filename = json.get("filename".into()).unwrap().get_str().unwrap();
178 | if let Some(custom_name) = args.out_filename {
179 | filename = custom_name;
180 | }
181 | if bulk > 0 {
182 | filename = format!("{bulk}_{filename}");
183 | }
184 | println!(
185 | "Downloading {} from {} ...",
186 | media,
187 | download_url
188 | );
189 | let stream = attempt!(res.bytes().await, "Error decoding byte stream:\n\"{}\"\n(when downloading from {download_url})");
190 |
191 | let display = match filename.contains(' ') {
192 | true => {
193 | format!("'{}'", &filename)
194 | },
195 | false => filename.clone(),
196 | };
197 |
198 | println!("Data downloaded successfully! Writing {media} to {} ...", &display);
199 | let path = std::env::current_dir().unwrap().join(&filename);
200 | attempt!(tokio::fs::write(path, stream).await, "Unable to write data to file:\n\"{}\"\n(when writing to {display})");
201 |
202 | println!("Your {media} is ready! >> {display}")
203 | },
204 | _ => unreachable!()
205 | }
206 | true
207 | }
208 |
209 |
210 | #[cfg(test)]
211 | mod tests;
212 |
--------------------------------------------------------------------------------
/src/process.rs:
--------------------------------------------------------------------------------
1 | use crate::{tcargs, args::Args, json};
2 | use std::io::Write;
3 |
4 | pub fn print_json_error(error: String, body: String) -> String {
5 | let mut text = String::new();
6 | text.push_str("Cobalt server returned improper JSON\n");
7 | text.push_str(&format!("JSON parse error: {error}\n"));
8 | if std::env::var("TCOBALT_DEBUG").is_ok_and(|v| v == 1.to_string()) == true {
9 | text.push_str(&format!("\n[DEBUG] Cobalt returned response:\n{body}\n\n"));
10 | text.push_str("[DEBUG] If this response isn't proper JSON, please contact wukko about this error.\n");
11 | text.push_str("[DEBUG] If this looks like proper json, contact khyernet/khyerdev about his json parser not functioning right.");
12 | } else {
13 | text.push_str("Contact wukko about this error. Run with TCOBALT_DEBUG=1 to see the incorrect response.")
14 | }
15 | text
16 | }
17 |
18 | pub fn get_url(args: &Args, status: &str, json: &std::collections::HashMap) -> String {
19 | let media = if args.c_download_mode == tcargs::types::DownloadMode::Audio {
20 | "audio"
21 | } else {
22 | "video"
23 | };
24 |
25 | if status == "picker" {
26 | let urls = {
27 | let mut urls: Vec = Vec::new();
28 | let picker_array = json.get("picker").unwrap().get_array().unwrap();
29 | for picker in picker_array.iter() {
30 | let picker = picker.get_object().unwrap();
31 | let cobalt_type = picker.get("type".into()).unwrap().get_str().unwrap();
32 | if cobalt_type == String::from("video") || cobalt_type == String::from("gif") {
33 | urls.push(picker.get("url".into()).unwrap().get_str().unwrap());
34 | }
35 | }
36 | urls
37 | };
38 |
39 | let choice = if args.picker_choice == 0 {
40 | loop {
41 | let mut buf = String::new();
42 | print!("Choose which {media} to download [1-{}] >> ", urls.len());
43 | std::io::stdout().flush().unwrap();
44 | std::io::stdin().read_line(&mut buf).unwrap();
45 | if let Ok(int) = buf.trim().parse::() {
46 | if int as usize <= urls.len() {
47 | break int;
48 | }
49 | }
50 | println!("Input must be an integer between 1 and {}", urls.len());
51 | }
52 | } else {
53 | args.picker_choice
54 | };
55 |
56 | urls.get((choice - 1) as usize).unwrap_or(&urls[0]).clone()
57 | } else {
58 | json.get("url").unwrap().get_str().unwrap()
59 | }
60 | }
61 |
62 | const POST_TEMPLATE: &str = "{
63 | \"url\": \"\",
64 | \"youtubeVideoCodec\": \"\",
65 | \"videoQuality\": \"\",
66 | \"audioFormat\": \"\",
67 | \"audioBitrate\": \"\",
68 | \"filenameStyle\": \"\",
69 | \"downloadMode\": \"\",
70 | \"tiktokFullAudio\": ,
71 | \"tiktokH265\": ,
72 | \"youtubeDubLang\": \"\",
73 | \"disableMetadata\": ,
74 | \"twitterGif\": ,
75 | \"alwaysProxy\":
76 | }";
77 | pub fn cobalt_args(args_in: &Args) -> String {
78 | POST_TEMPLATE.to_string()
79 | .replace("", &args_in.c_url.clone().unwrap())
80 | .replace("", &args_in.c_video_codec.print())
81 | .replace("", &args_in.c_video_quality.to_string())
82 | .replace("", &args_in.c_audio_format.print())
83 | .replace("", &args_in.c_fname_style.print())
84 | .replace("", &args_in.c_tt_full_audio.to_string())
85 | .replace("", &args_in.c_tt_h265.to_string())
86 | .replace("", &format!("{:?}", args_in.c_download_mode).to_lowercase())
87 | .replace("", &args_in.accept_language)
88 | .replace("", &args_in.c_disable_metadata.to_string())
89 | .replace("", &args_in.c_twitter_gif.to_string())
90 | .replace("", &args_in.c_proxy.to_string())
91 | .replace("", &args_in.c_audio_bitrate.to_string())
92 | }
93 |
94 | #[macro_export]
95 | macro_rules! attempt {
96 | ($try: expr, $error_msg_format: literal $(,$($extra:expr),*)?) => {{
97 | let result = $try;
98 | if result.is_err() {
99 | let e = result.unwrap_err().to_string();
100 | eprintln!($error_msg_format, e $(,$($extra)*)?);
101 | return false;
102 | }
103 | result.unwrap()
104 | }};
105 | ($try: expr, $error_string_generator: expr) => {{
106 | let result = $try;
107 | if result.is_err() {
108 | let e = result.unwrap_err().to_string();
109 | let diag = $error_string_generator;
110 | eprintln!("{}", diag.to_string().replace("{}", &e));
111 | return false;
112 | }
113 | result.unwrap()
114 | }};
115 | }
116 |
--------------------------------------------------------------------------------
/src/strings/info.txt:
--------------------------------------------------------------------------------
1 | [version]
2 | tcobalt command line utility {}
3 | Copyright (c) 2024 Khyernet
4 | This is free software, distributed under the GNU GPL v3.
5 | You may also use, modify, and distribute this software under the same license.
6 | The code and license is available at https://github.com/khyerdev/tcobalt
7 |
8 | [supported]
9 | bilibili.com & bilibili.tv
10 | bluesky
11 | dailymotion videos
12 | instagram reels, posts & stories (rarely works)
13 | facebook
14 | loom
15 | ok video (full video+audio only)
16 | pinterest videos & stories
17 | reddit videos & gifs
18 | rutube videos
19 | snapchat
20 | soundcloud (audio only)
21 | streamable.com
22 | tiktok videos, photos & audio
23 | tumblr video & audio
24 | twitch clips
25 | twitter videos & voice
26 | vimeo
27 | vine archive
28 | vk video & clips (full video+audio only)
29 | youtube videos, shorts & music
30 |
31 | [default-config]
32 | \[default]
33 | vcodec = h264
34 | vquality = 1080
35 | aformat = mp3
36 | bitrate = 128
37 | download-mode = auto
38 | twitter-gif = false
39 | tt-full-audio = false
40 | tt-h265 = false
41 | dublang = none
42 | no-metadata = false
43 | fname-style = classic
44 | proxy = false
45 | instance = api.cobalt.tools
46 |
47 | \[default.instances]
48 | api.cobalt.tools
49 | dl.khyernet.xyz
50 | co.eepy.today
51 | cobalt.api.timelessnesses.me
52 | beta.cobalt.canine.tools
53 | ca.haloz.at
54 |
--------------------------------------------------------------------------------
/src/strings/mod.rs:
--------------------------------------------------------------------------------
1 | const USAGE_TXT: &str = include_str!("usage.txt");
2 | const INFO_TXT: &str = include_str!("info.txt");
3 |
4 | pub fn get_help() -> String {
5 | let mut string = String::new();
6 | for line in USAGE_TXT.lines().into_iter() {
7 | if line.chars().collect::>().first() == Some(&'[') { break }
8 | string.push_str(line);
9 | string.push('\n');
10 | }
11 | remove_trailing_whitespace(string)
12 | }
13 |
14 | pub fn get_str(module: &str, symbol: &str) -> String {
15 | let text = match module {
16 | "usage" => USAGE_TXT,
17 | "info" => INFO_TXT,
18 | _ => unreachable!()
19 | };
20 |
21 | let mut string = String::new();
22 | let mut select = false;
23 | let mut brackets = 0;
24 | for line in text.lines().into_iter() {
25 | if brackets == 2 { break }
26 | if !select && remove_trailing_whitespace(line) != format!("[{symbol}]") { continue }
27 | select = true;
28 | if line.chars().collect::>().first() == Some(&'[') { brackets += 1; continue }
29 |
30 | string.push_str(line);
31 | string.push('\n');
32 | }
33 | remove_trailing_whitespace(string)
34 | }
35 |
36 | pub fn remove_trailing_whitespace(string: impl ToString) -> String {
37 | let mut string = string.to_string();
38 | if string.len() == 0 { return string }
39 | let chars = string.chars().collect::>();
40 | let mut i = string.len()-1;
41 | while chars.get(i) == Some(&'\n') || chars.get(i) == Some(&' ') {
42 | string.pop();
43 | i -= 1;
44 | }
45 | string
46 | }
47 |
--------------------------------------------------------------------------------
/src/strings/usage.txt:
--------------------------------------------------------------------------------
1 | The tcobalt cli utility downloads videos from the internet straight from your terminal.
2 | This is just a wrapper around "cobalt.tools" made by wukko. I am not affiliated with wukko in any way.
3 | Usage: tcb [optional args]
4 |
5 | Main Methods:
6 | get [options]
7 | list
8 | help [method]
9 | bulk
10 | Misc Methods:
11 | gen-config
12 | version
13 | cobalt-version [instance]
14 |
15 | You can also type the first letter for a method
16 | Type "help " for more information about a method and its options
17 | Type "help examples" for some examples, or "help config" for... config help
18 | Run with TCOBALT_DEBUG=1 to be verbose about the process
19 |
20 | [get]
21 | tcobalt "get" method syntax
22 | Easy downloading for videos/songs with simple syntax
23 | Usage: tcb get [options]
24 |
25 | Global Options:
26 | -q --vquality The quality of the output video. Options: 144, 480, 720, 1080, 1440, 2160, Default: 1080
27 | -f --aformat The format of the audio. Formats: best, mp3, ogg, wav, opus, Default: mp3
28 | The "best" option takes the format of the original audio, and may not be specified on the website you took the media from.
29 | -b --bitrate The bitrate of the audio if it was reformatted. Rates: 320, 256, 128, 96, 64, 8, Default: 128
30 | -a --audio-only Tells cobalt to only download and output the audio of the link
31 | -m --mute-audio Tells cobalt to mute the audio from the downloaded content
32 | -= --auto Tells cobalt to download a video if possible, otherwise downloading audio instead.
33 | This is the default option, only use this if your config default is something else.
34 | -n --no-metadata Prevents the downloaded media from including metadata
35 | -s --fname-style