mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 03:10:05 -05:00
Add streamer banner
This commit is contained in:
parent
4a333eed57
commit
12116d7c9b
3 changed files with 36 additions and 4 deletions
|
@ -23,6 +23,7 @@ type Streamer struct {
|
||||||
Login string `json:"login"`
|
Login string `json:"login"`
|
||||||
About string `json:"about"`
|
About string `json:"about"`
|
||||||
Pfp string `json:"pfp"`
|
Pfp string `json:"pfp"`
|
||||||
|
Banner *string `json:"banner"`
|
||||||
Followers int `json:"followers"`
|
Followers int `json:"followers"`
|
||||||
Socials []Social `json:"socials"`
|
Socials []Social `json:"socials"`
|
||||||
IsLive bool `json:"isLive"`
|
IsLive bool `json:"isLive"`
|
||||||
|
|
|
@ -3,7 +3,6 @@ package twitch
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"safetwitch-backend/extractor"
|
"safetwitch-backend/extractor"
|
||||||
"safetwitch-backend/extractor/structs"
|
"safetwitch-backend/extractor/structs"
|
||||||
|
@ -13,7 +12,7 @@ import (
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseStreamer(streamerData gjson.Result, isLive bool, socials []structs.Social, stream *structs.Stream, login string) (structs.Streamer, error) {
|
func ParseStreamer(streamerData gjson.Result, isLive bool, socials []structs.Social, stream *structs.Stream, login string, streamerBanner string) (structs.Streamer, error) {
|
||||||
// Store streamerColorHex in memory to use as pointer
|
// Store streamerColorHex in memory to use as pointer
|
||||||
var streamerColorHex *string
|
var streamerColorHex *string
|
||||||
rawStreamerColorHex := streamerData.Get("user.primaryColorHex").String()
|
rawStreamerColorHex := streamerData.Get("user.primaryColorHex").String()
|
||||||
|
@ -23,13 +22,20 @@ func ParseStreamer(streamerData gjson.Result, isLive bool, socials []structs.Soc
|
||||||
streamerColorHex = &rawStreamerColorHex
|
streamerColorHex = &rawStreamerColorHex
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(streamerData.String())
|
var bannerUrl *string = &streamerBanner
|
||||||
|
if *bannerUrl == "" {
|
||||||
|
bannerUrl = nil
|
||||||
|
} else {
|
||||||
|
proxied := extractor.ProxyUrl(*bannerUrl)
|
||||||
|
bannerUrl = &proxied
|
||||||
|
}
|
||||||
|
|
||||||
parsedStreamer := structs.Streamer{
|
parsedStreamer := structs.Streamer{
|
||||||
Username: streamerData.Get("user.displayName").String(),
|
Username: streamerData.Get("user.displayName").String(),
|
||||||
Login: login,
|
Login: login,
|
||||||
About: streamerData.Get("user.description").String(),
|
About: streamerData.Get("user.description").String(),
|
||||||
Pfp: extractor.ProxyUrl(streamerData.Get("user.profileImageURL").String()),
|
Pfp: extractor.ProxyUrl(streamerData.Get("user.profileImageURL").String()),
|
||||||
|
Banner: bannerUrl,
|
||||||
Followers: int(streamerData.Get("user.followers.totalCount").Int()),
|
Followers: int(streamerData.Get("user.followers.totalCount").Int()),
|
||||||
Socials: socials,
|
Socials: socials,
|
||||||
IsLive: isLive,
|
IsLive: isLive,
|
||||||
|
|
|
@ -71,6 +71,7 @@ type TwitchPayload = map[string]interface{}
|
||||||
|
|
||||||
func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
payload := []TwitchPayload{
|
payload := []TwitchPayload{
|
||||||
|
// Streamer data
|
||||||
{
|
{
|
||||||
"operationName": "ChannelRoot_AboutPanel",
|
"operationName": "ChannelRoot_AboutPanel",
|
||||||
"variables": map[string]interface{}{
|
"variables": map[string]interface{}{
|
||||||
|
@ -84,6 +85,8 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Stream metadata
|
||||||
{
|
{
|
||||||
"operationName": "StreamMetadata",
|
"operationName": "StreamMetadata",
|
||||||
"variables": map[string]interface{}{
|
"variables": map[string]interface{}{
|
||||||
|
@ -96,6 +99,8 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Stream tags
|
||||||
{
|
{
|
||||||
"operationName": "StreamTagsTrackingChannel",
|
"operationName": "StreamTagsTrackingChannel",
|
||||||
"variables": map[string]interface{}{
|
"variables": map[string]interface{}{
|
||||||
|
@ -108,6 +113,8 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Stream preview image
|
||||||
{
|
{
|
||||||
"operationName": "VideoPreviewOverlay",
|
"operationName": "VideoPreviewOverlay",
|
||||||
"variables": map[string]interface{}{
|
"variables": map[string]interface{}{
|
||||||
|
@ -120,6 +127,8 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Current views
|
||||||
{
|
{
|
||||||
"operationName": "UseViewCount",
|
"operationName": "UseViewCount",
|
||||||
"variables": map[string]interface{}{
|
"variables": map[string]interface{}{
|
||||||
|
@ -132,6 +141,20 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Get offline banner image
|
||||||
|
{
|
||||||
|
"operationName": "ChannelShell",
|
||||||
|
"variables": map[string]interface{}{
|
||||||
|
"login": streamerName,
|
||||||
|
},
|
||||||
|
"extensions": map[string]interface{}{
|
||||||
|
"persistedQuery": map[string]interface{}{
|
||||||
|
"version": 1,
|
||||||
|
"sha256Hash": "580ab410bcd0c1ad194224957ae2241e5d252b2c5173d8e0cce9d32d5bb14efe",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, body, err := parseResponse(payload)
|
_, body, err := parseResponse(payload)
|
||||||
|
@ -166,7 +189,9 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
|
||||||
isLive = false
|
isLive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedStreamer, err := ParseStreamer(streamerData, isLive, parsedSocials, parsedStream, streamerName)
|
streamerBanner := gjson.Get(string(body), "5.data.userOrError.bannerImageURL").String()
|
||||||
|
|
||||||
|
parsedStreamer, err := ParseStreamer(streamerData, isLive, parsedSocials, parsedStream, streamerName, streamerBanner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return structs.Streamer{}, err
|
return structs.Streamer{}, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue