YouTube API for Go.
Clean example request for the media downloader endpoint. Replace YOUR API and the media URL, then run the code.
Checking
Clean example request for the media downloader endpoint. Replace YOUR API and the media URL, then run the code.
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"
)
const (
apiKey = "YOUR API"
videoURL = "URL YOUTUBE"
endpoint = "https://senpai-bot.store/youtubedl"
)
type Result struct {
AudioURL string `json:"audio_url"`
Author string `json:"author"`
Description string `json:"description"`
Duration int `json:"duration"`
Thumbnail string `json:"thumbnail"`
Title string `json:"title"`
TitleLength int `json:"title_length"`
VideoURL string `json:"video_url"`
}
type ApiResponse struct {
Code int `json:"code"`
Result Result `json:"result"`
}
func main() {
encodedVideoURL := url.QueryEscape(videoURL)
fullURL := fmt.Sprintf("%s?apikey=%s&url=%s", endpoint, apiKey, encodedVideoURL)
resp, err := http.Get(fullURL)
if err != nil {
log.Fatalf("Error making request: %v", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("Error reading response: %v", err)
}
var response ApiResponse
if err := json.Unmarshal(body, &response); err != nil {
log.Fatalf("Error parsing JSON: %v", err)
}
if response.Code != 200 {
log.Fatalf("API returned error code: %d", response.Code)
}
r := response.Result
fmt.Println("Title:", r.Title)
fmt.Println("Title Length:", r.TitleLength)
fmt.Println("Author:", r.Author)
if r.Description != "" {
fmt.Println("Description:", r.Description)
} else {
fmt.Println("Description: (empty)")
}
fmt.Println("Duration:", r.Duration)
fmt.Println("Audio URL:", r.AudioURL)
fmt.Println("Video URL:", r.VideoURL)
fmt.Println("Thumbnail:", r.Thumbnail)
}