Skip to content

Commit

Permalink
v1.0.6: add tests, don't call os.exit, add instances listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Lost committed Apr 23, 2024
1 parent 66169be commit 940c975
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ jobs:
goarch: ${{ matrix.goarch }}
binary_name: "cobalt-${{ matrix.goos }}-${{ matrix.goarch }}"
ldflags: -s -w
pre_command: "go install github.com/tc-hib/go-winres@latest && go-winres make"
pre_command: "go install github.com/tc-hib/go-winres@latest && go-winres make && go test -v"
asset_name: "cobalt-${{ matrix.goos }}-${{ matrix.goarch }}"
overwrite: true
65 changes: 56 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ Planned features for cobalt-cli:


## Usage
cobalt-cli has two subcommands:
- download: downloads something using cobalt
- instances: lists all known cobalt instances

### Download
```
usage: cobalt [-h|--help] [-u|--url "<value>"] [-c|--video-codec
usage: cobalt download [-h|--help] [-u|--url "<value>"] [-c|--video-codec
(av1|vp9|h264)] [-q|--video-quality
(144|240|360|480|720|1080|1440|2160)] [-f|--audio-format
(opus|ogg|wav|mp3|best)] [-p|--filename-pattern
(basic|pretty|nerdy|classic)] [-a|--no-video] [-w|--no-watermark]
(basic|pretty|nerdy|classic)] [-a|--no-video] [-V|--vimeo-dash]
[-t|--full-tiktok-audio] [-v|--no-audio] [-d|--dubbed-audio]
[-m|--metadata] [-g|--gif] [-j|--json] [-s|--status] [-i|--api
"<value>"] [-l|--language "<value>"] [-b|--browser]
save what you love directly from command-line, no bullshit
involved.
download something using cobalt
Arguments:
Expand All @@ -81,8 +85,8 @@ Arguments:
Audio Author (soundcloud, 1242868615).mp3. Default:
pretty
-a --no-video Extract audio only. Default: false
-w --no-watermark Remove TikTok watermark from TikTok videos. Default:
false
-V --vimeo-dash Downloads Vimeo videos using dash instead of
progressive. Default: false
-t --full-tiktok-audio Enables download of original sound used in a tiktok
video. Default: false
-v --no-audio Downloads only the video, without audio, when
Expand All @@ -108,6 +112,49 @@ Arguments:
successful. Default: false
```

### Instances
```
usage: cobalt instances [-h|--help] [-j|--json]
get the list of cobalt instances
Arguments:
-h --help Print help information
-j --json Output to stdout as json
```

## JSON Output
See the documentation for the json output of cobalt-cli.
### Download
All json output from the download subcommands follows this format:
```json
{
"error": bool,
"message": "string",
"urls": ["string1", "string2", ...]
}
```
Where:
| **name** | **type** | **info** | **example** |
|---|---|---|---|
| error | bool | true if something went wrong | "error":true |
| message | string | return error messages, otherwise "ok" | "message":"cobalt error: i couldn't connect to the service api. maybe it's down, or cobalt got blocked" |
| urls | []string | array of urls returned by the service, query scaped | "urls":["https%3A%2F%2Fus3-co.wuk.sh%2Fapi%2Fstream%3Ft%3D6kS3Xr97CAoqvPlBYX0r8%26e%3D1713849463113%26h%3DNHPfrLZ-BJejEnH2orowNy0zzTlVXSYw77RBhzIf0MU%26s%3DxvmTt9DTNl4wLslkfYfCUv6UDIPOTv9iZutl7ENM_dc%26i%3DuX7INLhsbzzofNxZaw6o7g"] |

### Instances
Returns almost the original json from [https://instances.hyper.lol/](https://instances.hyper.lol/instances.json), except we add two extra keys: error and message, just like above.

Example JSON:
```json
[{"error":false,"message":"success!"},[{"version":"7.12.6","commit":"50a98c8","branch":"current","name":"us3","url":"co.wuk.sh","cors":1,"startTime":"1713626380117","FrontendUrl":"cobalt.tools","ApiOnline":true,"FrontEndOnline":true},{"version":"7.12.6","commit":"50a98c8","branch":"current","name":"us-east","url":"cobalt.canine.tools","cors":1,"startTime":"1713837765475","FrontendUrl":"cobalt.canine.tools","ApiOnline":true,"FrontEndOnline":true},{"version":"7.12.6","commit":"50a98c8","branch":"current","name":"us-mw","url":"coapi.selfstacked.com","cors":1,"startTime":"1713626820678","FrontendUrl":"co.selfstacked.com","ApiOnline":true,"FrontEndOnline":true}]]
```

Error example:
```json
{"error":true,"message":"Get \"https://instances.hyper.lol/instances.json\": dial tcp: lookup instances.hyper.lol: no such host"}
```

## Compiling
Make sure you have the lastest go compiler. [Download it here](https://go.dev/dl).

Expand All @@ -124,7 +171,7 @@ Then run `go-winres make` on the root of this repository, it will create two .sy
After that, building with `go build` will automatically embed these files on the Windows executable.

# About & Thanks
- [cobalt](https://github.com/wukko/cobalt) made by [wukko](https://github.com/wukko), super cool guy;
- [argparse](https://github.com/akamensky/argparse), for handling args
- Icon made by [me](https://princessmortix.link);
- [cobalt](https://github.com/wukko/cobalt) made by [wukko](https://github.com/wukko) && [jj](https://github.com/dumbmoron), super cool people;
- [argparse](https://github.com/akamensky/argparse), for handling args;
- Icon made by [me](https://lostdusty.com.br);
- You, for using my application!
24 changes: 24 additions & 0 deletions cobalt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"testing"

"github.com/lostdusty/gobalt"
)

//These tests allows me to test the application directly w/o the need to run `go run . <sub> [flags]`.

func TestInstacesListing(t *testing.T) {
t.Log("testing instance listing")
err := getInstances(false)
if err != nil {
t.Fatalf("failed to fetch custom instaces: %v", err)
}
}

func TestCobaltHealth(t *testing.T) {
err := checkStatus(gobalt.CobaltApi, true)
if err != nil {
t.Fatalf("failed to get cobalt instance health: %v", err)
}
}
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module github.com/princessmortix/cobalt
module github.com/lostdusty/cobalt

go 1.21.6

require (
github.com/akamensky/argparse v1.4.0
github.com/emvi/iso-639-1 v1.1.0
github.com/lostdusty/gobalt v1.0.5
github.com/lostdusty/gobalt v1.0.6
github.com/mergestat/timediff v0.0.3
)

require (
github.com/jedib0t/go-pretty/v6 v6.5.8
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.19.0 // indirect
)
21 changes: 19 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emvi/iso-639-1 v1.1.0 h1:EhZiYVA+ysa/b7+0T2DD9hcX7E/5sh4o1KyDAIPu7VE=
github.com/emvi/iso-639-1 v1.1.0/go.mod h1:CSA53/Tx0xF9bk2DEA0Mr0wTdIxq7pqoVZgBOfoL5GI=
github.com/lostdusty/gobalt v1.0.5 h1:SdCW+tHDCBaRE/TYs8FPSUwgDLzinRUY5hlw5KC3flA=
github.com/lostdusty/gobalt v1.0.5/go.mod h1:gv+Hmbv0SC3lWpJvUvxJYRmmcuBjlmhKCIRskk0lSjY=
github.com/jedib0t/go-pretty/v6 v6.5.8 h1:8BCzJdSvUbaDuRba4YVh+SKMGcAAKdkcF3SVFbrHAtQ=
github.com/jedib0t/go-pretty/v6 v6.5.8/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/lostdusty/gobalt v1.0.6 h1:vCVAlZS7dyc8x3Xdt4WmMeO9v2wriSIXwaK+binNz2U=
github.com/lostdusty/gobalt v1.0.6/go.mod h1:gv+Hmbv0SC3lWpJvUvxJYRmmcuBjlmhKCIRskk0lSjY=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mergestat/timediff v0.0.3 h1:ucCNh4/ZrTPjFZ081PccNbhx9spymCJkFxSzgVuPU+Y=
github.com/mergestat/timediff v0.0.3/go.mod h1:yvMUaRu2oetc+9IbPLYBJviz6sA7xz8OXMDfhBl7YSI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit 940c975

Please sign in to comment.