mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 05:02:58 -05:00
Make clips not need streamer name
This commit is contained in:
parent
9c11f0e8f4
commit
0953928e5e
2 changed files with 36 additions and 4 deletions
|
@ -8,7 +8,39 @@ import (
|
|||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func GetClipMetadata(clipSlug string, streamerName string) (structs.Video, error) {
|
||||
func GetClipUsername(clipSlug string) (string, error) {
|
||||
payload := []TwitchPayload{
|
||||
{
|
||||
"operationName": "VideoPlayerStreamInfoOverlayClip",
|
||||
"variables": map[string]interface{}{
|
||||
"slug": clipSlug,
|
||||
},
|
||||
"extensions": map[string]interface{}{
|
||||
"persistedQuery": map[string]interface{}{
|
||||
"version": 1,
|
||||
"sha256Hash": "d026f1fc6ec6862869684a9768c20e3f6d51f6fd520a2a351dc274356e9c6eb0",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
_, body, err := parseResponse(payload)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
videoData := gjson.Get(string(body), "0.data.clip")
|
||||
streamerName := videoData.Get("broadcaster.login").String()
|
||||
return streamerName, nil
|
||||
|
||||
}
|
||||
|
||||
func GetClipMetadata(clipSlug string) (structs.Video, error) {
|
||||
streamerName, err := GetClipUsername(clipSlug)
|
||||
if err != nil {
|
||||
return structs.Video{}, err
|
||||
}
|
||||
|
||||
payload := []TwitchPayload{
|
||||
{
|
||||
"operationName": "ClipMetadata",
|
||||
|
@ -56,6 +88,7 @@ func GetClipMetadata(clipSlug string, streamerName string) (structs.Video, error
|
|||
videoData := gjson.Get(string(body), "0.data.clip")
|
||||
|
||||
return structs.Video{
|
||||
Type: "clip",
|
||||
Title: videoData.Get("title").String(),
|
||||
Preview: extractor.ProxyUrl(videoData.Get("previewThumbnailURL").String()),
|
||||
Duration: int(videoData.Get("lengthSeconds").Int()),
|
||||
|
|
|
@ -21,10 +21,9 @@ func Routes(route *gin.Engine) {
|
|||
context.JSON(200, extractor.FormatMessage(data, true))
|
||||
})
|
||||
|
||||
clips.GET("/:streamerName/:slug", func(context *gin.Context) {
|
||||
clips.GET("/:slug", func(context *gin.Context) {
|
||||
slug := context.Param("slug")
|
||||
streamerName := context.Param("streamerName")
|
||||
data, err := twitch.GetClipMetadata(slug, streamerName)
|
||||
data, err := twitch.GetClipMetadata(slug)
|
||||
if err != nil {
|
||||
context.Error(err)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue