mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 05:02:58 -05:00
78 lines
2 KiB
Go
78 lines
2 KiB
Go
package twitch
|
|
|
|
import (
|
|
"safetwitch-backend/extractor/structs"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
/*
|
|
If you don't understand the meaning of shelve in
|
|
this context, go to an offline streamer on twitch
|
|
and look under the videos tag. Each row is considered
|
|
a shelve, and each can be expanded. This is to be used
|
|
on a streamers profile page
|
|
*/
|
|
func GetStreamerVideoShelves(streamerName string) ([]structs.Shelve, error) {
|
|
payload := []TwitchPayload{
|
|
{
|
|
"operationName": "ChannelVideoShelvesQuery",
|
|
"variables": map[string]interface{}{
|
|
"channelLogin": streamerName,
|
|
"first": 5,
|
|
},
|
|
"extensions": map[string]interface{}{
|
|
"persistedQuery": map[string]interface{}{
|
|
"version": 1,
|
|
"sha256Hash": "8afefb1ed16c4d8e20fa55024a7ed1727f63b6eca47d8d33a28500770bad8479",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
"operationName": "ChannelRoot_AboutPanel",
|
|
"variables": map[string]interface{}{
|
|
"channelLogin": streamerName,
|
|
"skipSchedule": false,
|
|
},
|
|
"extensions": map[string]interface{}{
|
|
"persistedQuery": map[string]interface{}{
|
|
"version": 1,
|
|
"sha256Hash": "6089531acef6c09ece01b440c41978f4c8dc60cb4fa0124c9a9d3f896709b6c6",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
_, body, err := parseResponse(payload)
|
|
if err != nil {
|
|
return []structs.Shelve{}, err
|
|
}
|
|
|
|
streamerData := gjson.Get(string(body), "1.data")
|
|
parsedSocials, err := ParseSocials(streamerData.String())
|
|
if err != nil {
|
|
return []structs.Shelve{}, err
|
|
}
|
|
parsedStreamer, err := ParseStreamer(streamerData, false, parsedSocials, nil, streamerName, "")
|
|
if err != nil {
|
|
return []structs.Shelve{}, err
|
|
}
|
|
/*
|
|
Twitch seperates videos by shelves.
|
|
There are 4 shells:
|
|
- Recent broadcasts
|
|
- Recent highlights and uploads
|
|
- Popular clips
|
|
- All videos
|
|
|
|
Each one of these shelves can be expanded to get more data
|
|
*/
|
|
|
|
shelves := gjson.Get(string(body), "0.data.user.videoShelves.edges")
|
|
parsedShelves := []structs.Shelve{}
|
|
for _, shelve := range shelves.Array() {
|
|
parsedShelves = append(parsedShelves, ParseShelve(shelve.Get("node"), parsedStreamer))
|
|
}
|
|
|
|
return parsedShelves, nil
|
|
}
|