https://github.com/lostdusty/gobalt
Go library to work with the HTTP API of cobalt.tools
https://github.com/lostdusty/gobalt
Last synced: about 1 year ago
JSON representation
Go library to work with the HTTP API of cobalt.tools
- Host: GitHub
- URL: https://github.com/lostdusty/gobalt
- Owner: lostdusty
- License: mit
- Created: 2024-01-01T14:58:47.000Z (over 2 years ago)
- Default Branch: v2
- Last Pushed: 2024-12-29T22:37:41.000Z (over 1 year ago)
- Last Synced: 2025-03-27T11:12:27.840Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 22
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://discord.gg/pQPt8HBUPu)
[](https://github.com/wukko/cobalt?tab=readme-ov-file#supported-services)
gobalt v2
(cobalt api v10.0.0+)
> [!NOTE]
> This is the version 2 of the gobalt library, intended for interecting with cobalt recent version (v10.0.0 and up). If you're upgrading from v1, note that there some breaking changes.
>
> This version IS NOT compatible with cobalt previous version (v7.15 and lower), use the v1 version if you want to use the older api, it will be maintained until 31/December/2024.
Gobalt provides a way to communicate with [cobalt.tools](https://cobalt.tools) using Go. To use it in your projects, simply run this command:
```sh
go get -u github.com/lostdusty/gobalt/v2
```
## Usage
First, make sure you call `gobalt.CreateDefaultSettings()` to create the `Settings` struct with default values, then set an url.
```go
//Creates a Settings struct with default values, and save it to downloadMedia variable.
downloadMedia := gobalt.CreateDefaultSettings()
//Sets the URL, you MUST set one before downloading the media.
downloadMedia.Url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
//After changing the url, Do() will make the necessary requests to cobalt to download your media
destination, err := gobalt.Do(downloadMedia)
if err != nil {
//Handle errors here
}
//Prints out the url from cobalt to download the requested media.
fmt.Println(destination.URL)
//Output example: https://us4-co.wuk.sh/api/stream?t=wTn-71aaWAcV2RBejNFNV&e=1711777798864&h=fMtwwtW8AUmtTLB24DGjJJjrq1EJDBFaCDoDuZpX0pA&s=_YVZhz8fnzBBKKo7UZmGWOqfe4wWwH5P1azdgBqwf-I&i=6tGZqAXbW08_6KmAiLevZA
```
## Features
### Server info
You can query information about any cobalt server by using `CobaltServerInfo(apiurl)`. This will return a `ServerInfo` struct with [this info](https://github.com/wukko/cobalt/blob/current/docs/api.md#response-body-variables-1).
Example code:
```go
server, err := gobalt.CobaltServerInfo(gobalt.CobaltApi)
if err != nil {
//Handle the error here
}
fmt.Printf("Downloading from %v!\n", server.URL)
//Output: Downloading from https://us4-co.wuk.sh/!
```
### Use/Query other cobalt instances
Using `GetCobaltInstances()` fetches a community maintaned list of third-party cobalt instances ran by the community, except for ``*-co.wuk.sh``, none of them are "official" cobalt instances. Use them if you can't download from the main instance for whatever reason.
Example:
```go
cobalt, err := gobalt.GetCobaltInstances()
if err != nil {
//Handle errors here
}
fmt.Printf("Found %v online cobalt servers: ", len(cobalt))
for _, value := range cobalt {
fmt.Printf("%v, ", value.URL)
}
/* Output:
* Found 8 online cobalt servers: co.wuk.sh, cobalt-api.hyper.lol, cobalt.api.timelessnesses.me, api-dl.cgm.rs, cobalt.synzr.space, capi.oak.li, co.tskau.team, api.co.rooot.gay
*/
```