Skip to content

Commit

Permalink
v2.0.0: support for the new api
Browse files Browse the repository at this point in the history
  • Loading branch information
lostdusty committed Oct 15, 2024
1 parent 8df52f5 commit 4cadf7c
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 426 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.syso
*.linux
*.mac
*.old

# Test binary, built with `go test -c`
*.test
Expand Down
138 changes: 42 additions & 96 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
![GitHub License](https://img.shields.io/github/license/princessmortix/cobalt?style=for-the-badge&logo=unlicense)
</div>

Unofficial [cobalt](https://cobalt.tools) command line client made in go. cobalt-cli uses [gobalt library](https://github.com/princessmortix/gobalt) for communication between your machine <-> cobalt servers.
Unofficial [cobalt](https://cobalt.tools) command line client made in go. cobalt-cli uses [gobalt library](https://github.com/lostdusty/gobalt) for communication between your machine <-> cobalt servers.

- [Features](#features)
- [Download](#downloading)
Expand All @@ -20,10 +20,9 @@ Unofficial [cobalt](https://cobalt.tools) command line client made in go. cobalt
## Features
- Get directly link from the service cdn (if possible);
- More than 15 services supported;
- JSON output using the flag `-j` or `--json`;
- Option to check status of cobalt servers;
- Use custom cobalt instances (see https://instances.hyper.lol);
- Get dubbed youtube audio.
- Download the file directly to your computer.

## Download
| **Platform/OS** | **Download link** |
Expand All @@ -39,52 +38,45 @@ Alternatively, if you have Go installed, you can use `go install github.com/lost
## Roadmap
Planned features for cobalt-cli:

- [x] Json output;
- [ ] Time expiration for the returned url.
- [ ] Option to save file to the current/custom folder, likely `-s` flag;
- [ ] Display progress bar to track download progress (when supported by cobalt).
- [x] Option to save file to the current/custom folder, likely `-s` flag;
- [x] Display progress bar to track download progress (when supported by cobalt).
- [ ] Hability to use custom downloader program (wget, curl, got, etc);
- [ ] Translations.


## Usage
cobalt-cli has two subcommands:
- download: downloads something using cobalt
- instances: lists all known cobalt instances
cobalt-cli is similar to yt-dlp, just use `cobalt [url]`. If you use `cobalt help`, it will now show the help message.

```
Usage: cobalt <command>
Commands:
download - Use this command to download something.
instances - Use this command to view stats about other cobalt instances.
Error: No command was provided. Please specify a command.
```
To save a file to the current directory, use the `-s` flag, like: `cobalt https://www.youtube.com/watch?v=n1a7o44WxNo -s`

### Download
### Help
```
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] [-T|--tiktok-h265]
[-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]
download something using cobalt
usage: cobalt-cli [-h|--help] [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)]
[-Q|--audio-quality (64|128|192|256|320)]
[-p|--filename-pattern (basic|pretty|nerdy|classic)]
[-m|--mode (auto|audio|mute)] [-x|--proxy]
[-d|--disable-metadata] [-t|--tiktok-h265]
[-T|--tiktok-full-audio] [-g|--gif] [-s|--save] [-a|--api
"<value>"] [-i|--instances] [-v|--verbose]
save what you want, directly from the terminal, no unwanted
distractions involved. powered by cobalt's api
Arguments:
-h --help Print help information
-u --url The url to download using cobalt
<url> url to save
-c --video-codec Video codec to be used. Applies only to youtube
downloads. AV1: 8K/HDR, lower support | VP9: 4K/HDR,
best quality | H264: 1080p, works everywhere.
Default: h264
-q --video-quality Quality of the video, also applies only to youtube
-q --video-quality Quality of the video, applies only to youtube
downloads. Default: 1080
-f --audio-format Audio format/codec to be used. "best" doesn't
re-encodes the audio. Default: best
re-encodes audio. Default: best
-Q --audio-quality Audio quality in kbps. Default: 320
-p --filename-pattern File name pattern. Classic:
youtube_yPYZpwSpKmA_1920x1080_h264.mp4 | audio:
youtube_yPYZpwSpKmA_audio.mp3 // Basic: Video Title
Expand All @@ -95,76 +87,30 @@ Arguments:
youtube, yPYZpwSpKmA).mp4 | audio: Audio Title -
Audio Author (soundcloud, 1242868615).mp3. Default:
pretty
-a --no-video Downloads only the audio, and removes the video.
Default: false
-T --tiktok-h265 Downloads TikTok videos using h265 codec. Default:
-m --mode Mode to download the video. Auto: video with audio |
Audio: only audio | Mute: video without audio.
Default: auto
-x --proxy Tunnel the download through cobalt's servers,
bypassing potential restrictions and protecting your
identity and privacy. Default: false
-d --disable-metadata Disable metadata in the downloaded file. Default:
false
-t --full-tiktok-audio Download the original sound used in a tiktok video.
Default: false
-v --no-audio Downloads only the video, without audio, when
possible. Default: false
-d --dubbed-audio Downloads youtube audio dubbed, if present. Change
the language using -l <ISO 639-1 format>. Default:
false
-m --metadata Disables file metadata. Default: false
-g --gif Convert twitter gifs to .gif. Default: true
-j --json Output to stdout as json
-s --status Check status of the selected cobalt server, prints
and exits. All other options will be ignored, except
-j | --json. Default: false
-i --api Change the cobalt api url used. See others instances
in https://instances.hyper.lol. Default:
https://api.cobalt.tools
-l --language Downloads dubbed youtube audio according to the
language set following the ISO 639-1 format. Only
takes effect if -d was passed as an argument.
Default: en
-b --browser Downloads the requested media in your browser.
Default: false
-t --tiktok-h265 Use H265 codec for TikTok downloads. Default: false
-T --tiktok-full-audio Download TikTok videos with the original sound used
in a TikTok video. Default: false
-g --gif Convert Twitter videos to GIFs. Default: false
-s --save Save the downloaded file to disk. Default: true
-a --api Which API to use. Default is hyperdefined cobalt's
API. If you are hosting a custom API, or want to use
a different server, you can use it here. Default:
https://cobalt-backend.canine.tools
-i --instances Show community instances and exit. Default: false
-v --verbose Enable verbose logging. Default: false
```

### Instances
```
usage: cobalt instances [-h|--help] [-j|--json]
The command changed, now to view other instances, use `cobalt -i`

get the list of cobalt instances
Arguments:
-h --help Print help information
-j --json Output to stdout as json
```

## JSON Output
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 Down
24 changes: 0 additions & 24 deletions cobalt_test.go

This file was deleted.

25 changes: 17 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
module github.com/lostdusty/cobalt

go 1.21.6
go 1.22

toolchain go1.23.1

require (
github.com/akamensky/argparse v1.4.0
github.com/emvi/iso-639-1 v1.1.0
github.com/lostdusty/gobalt v1.0.7
github.com/mergestat/timediff v0.0.3
github.com/jedib0t/go-pretty/v6 v6.6.0
github.com/lostdusty/gobalt/v2 v2.0.3
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/jedib0t/go-pretty/v6 v6.5.9
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.21.0 // indirect
github.com/schollz/progressbar/v3 v3.16.1 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/term v0.25.0 // indirect
)

require (
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 // indirect
github.com/tgoncuoglu/argparse v0.0.0-20221031134704-ee5bd450c7a2
)
45 changes: 31 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,42 @@
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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/jedib0t/go-pretty/v6 v6.5.9 h1:ACteMBRrrmm1gMsXe9PSTOClQ63IXDUt03H5U+UV8OU=
github.com/jedib0t/go-pretty/v6 v6.5.9/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/lostdusty/gobalt v1.0.7 h1:8iL4eqp4NGn4lw9URYHD9DZYtIBMs2m81MWE+a9w/NM=
github.com/lostdusty/gobalt v1.0.7/go.mod h1:gv+Hmbv0SC3lWpJvUvxJYRmmcuBjlmhKCIRskk0lSjY=
github.com/jedib0t/go-pretty/v6 v6.6.0 h1:wmZVuAcEkZRT+Aq1xXpE8IGat4vE5WXOMmBpbQqERXw=
github.com/jedib0t/go-pretty/v6 v6.6.0/go.mod h1:zbn98qrYlh95FIhwwsbIip0LYpwSG8SUOScs+v9/t0E=
github.com/lostdusty/gobalt/v2 v2.0.3 h1:jCV/VXyz6wbK0lLQRosDsuSR7bBUPjdGhTu9OJeC3N4=
github.com/lostdusty/gobalt/v2 v2.0.3/go.mod h1:LiuOQrhZ81oUD8EtVIOXvdI0+iibamw0XYUeOhe8ibw=
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/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2 h1:YocNLcTBdEdvY3iDK6jfWXvEaM5OCKkjxPKoJRdB3Gg=
github.com/mcuadros/go-version v0.0.0-20190830083331-035f6764e8d2/go.mod h1:76rfSfYPWj01Z85hUf/ituArm797mNKcvINh1OlsZKo=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
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 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
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.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ=
github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tgoncuoglu/argparse v0.0.0-20221031134704-ee5bd450c7a2 h1:rm0HxutQnzd1+0MeWtUzzWyty7GQ+bsj2uJbHpIJcrU=
github.com/tgoncuoglu/argparse v0.0.0-20221031134704-ee5bd450c7a2/go.mod h1:Y4qUI357fa9S6td9QzayjCtO8uN0Ft7A/S8s0s+DLGI=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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 4cadf7c

Please sign in to comment.