Skip to content

Go library to work with the HTTP API of cobalt.tools

License

Notifications You must be signed in to change notification settings

KwiatekMiki/gobalt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go API Reference Latest Release

Static Badge Static Badge

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 using Go. To use it in your projects, simply run this command:

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.

//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.

Example code:

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:

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
*/

About

Go library to work with the HTTP API of cobalt.tools

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%