Skip to content

Commit

Permalink
v2.0.4: support for api keys
Browse files Browse the repository at this point in the history
  • Loading branch information
lostdusty committed Oct 20, 2024
1 parent 7e0999e commit a8059e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gobalt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"mime"
"net/http"
"net/url"
"os"
"path"
"runtime"
"strconv"
Expand All @@ -25,6 +26,7 @@ var (
Timeout: 10 * time.Second,
} //This allows you to modify the HTTP Client used in requests. This Client will be re-used.
useragent = fmt.Sprintf("gobalt/2.0.2 (+https://github.com/lostdusty/gobalt/v2; go/%v; %v/%v)", runtime.Version(), runtime.GOOS, runtime.GOARCH)
ApiKey = os.Getenv("COBALT_API_KEY") //Some instances need an API key to work, set it here. Default is from environment variable `COBALT_API_KEY`.
)

// ServerInfo is the struct used in the function CobaltServerInfo(). It contains two sub-structs: Cobalt and Git
Expand Down Expand Up @@ -217,6 +219,7 @@ func Run(options Settings) (*CobaltResponse, error) {
req.Header.Add("User-Agent", useragent)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Api-Key "+ApiKey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -293,6 +296,9 @@ type Services struct {

// GetCobaltInstances makes a request to instances.hyper.lol and returns a list of all online cobalt instances.
func GetCobaltInstances() ([]CobaltInstance, error) {
//Temporary disabled due of instance scraping abuse.
return nil, errors.New("service unavailable")

res, err := genericHttpRequest("https://instances.hyper.lol/instances.json", http.MethodGet, nil)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions gobalt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func TestCobaltDownload(t *testing.T) {
dlTest.Url = "https://www.youtube.com/watch?v=bV68_Vy0Uis&list=RD-Sr668sSEIA&index=19"
dlTest.AudioFormat = Ogg
dlTest.YoutubeVideoFormat = VP9
CobaltApi = "https://cobalt-api.kwiatekmiki.com"
runDlTest, err := Run(dlTest)
if err != nil {
t.Fatalf("%v", err)
Expand Down

0 comments on commit a8059e8

Please sign in to comment.