2023-07-16 21:03:52 -05:00
|
|
|
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
|
|
|
|
*/
|
2023-07-17 12:16:33 -05:00
|
|
|
func GetStreamerVideoShelves(streamerName string) ([]structs.Shelve, error) {
|
2023-07-16 21:03:52 -05:00
|
|
|
payload := []TwitchPayload{
|
|
|
|
{
|
|
|
|
"operationName": "ChannelVideoShelvesQuery",
|
|
|
|
"variables": map[string]interface{}{
|
2023-07-17 12:16:33 -05:00
|
|
|
"channelLogin": streamerName,
|
2023-07-16 21:03:52 -05:00
|
|
|
"first": 5,
|
|
|
|
},
|
|
|
|
"extensions": map[string]interface{}{
|
|
|
|
"persistedQuery": map[string]interface{}{
|
|
|
|
"version": 1,
|
|
|
|
"sha256Hash": "8afefb1ed16c4d8e20fa55024a7ed1727f63b6eca47d8d33a28500770bad8479",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-07-17 12:16:33 -05:00
|
|
|
{
|
|
|
|
"operationName": "ChannelRoot_AboutPanel",
|
|
|
|
"variables": map[string]interface{}{
|
|
|
|
"channelLogin": streamerName,
|
|
|
|
"skipSchedule": false,
|
|
|
|
},
|
|
|
|
"extensions": map[string]interface{}{
|
|
|
|
"persistedQuery": map[string]interface{}{
|
|
|
|
"version": 1,
|
|
|
|
"sha256Hash": "6089531acef6c09ece01b440c41978f4c8dc60cb4fa0124c9a9d3f896709b6c6",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-07-16 21:03:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_, body, err := parseResponse(payload)
|
|
|
|
if err != nil {
|
|
|
|
return []structs.Shelve{}, err
|
|
|
|
}
|
|
|
|
|
2023-07-17 12:16:33 -05:00
|
|
|
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
|
|
|
|
}
|
2023-07-16 21:03:52 -05:00
|
|
|
/*
|
|
|
|
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() {
|
2023-07-17 12:16:33 -05:00
|
|
|
parsedShelves = append(parsedShelves, ParseShelve(shelve.Get("node"), parsedStreamer))
|
2023-07-16 21:03:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return parsedShelves, nil
|
|
|
|
}
|