implement command update-title
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s

This commit is contained in:
Thomas Peetz
2026-10-12 17:37:06 +02:00
parent f5e9cbc423
commit 4c603a8eff
8 changed files with 145 additions and 31 deletions
+47
View File
@@ -1,7 +1,11 @@
package helpers
import (
"encoding/json"
"fmt"
"io/ioutil"
"log/slog"
"net/http"
"net/url"
)
@@ -20,3 +24,46 @@ func StripUrl(webLink string, keepParam string) string {
u.RawQuery = values.Encode()
return u.String()
}
func GetParam(webLink string, param string) string {
u, err := url.Parse(webLink)
if err != nil {
slog.Info("StripUrl", "error", err)
return webLink
}
values := u.Query()
for key := range values {
if key == param {
return values.Get(key)
}
}
return ""
}
type OEmbedResponse struct {
Title string `json:"title"`
}
func GetVideoTitle(videoUrl string) (string, error) {
videoID := GetParam(videoUrl, "v")
// Construct the oEmbed URL
url := fmt.Sprintf("https://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=%s&format=json", videoID)
resp, err := http.Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var data OEmbedResponse
if err := json.Unmarshal(body, &data); err != nil {
return "", err
}
return data.Title, nil
}