0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 05:02:58 -05:00

Get ready for chat extraction and websocket server

This commit is contained in:
dragongoose 2023-05-29 22:18:04 -04:00
parent f5c298d91d
commit fecf5f0488
No known key found for this signature in database
GPG key ID: 50DB99B921579009
4 changed files with 17 additions and 13 deletions

View file

@ -1,7 +1,8 @@
package extractor
package twitch
import (
"errors"
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/structs"
"time"
@ -50,7 +51,7 @@ func ParseStream(data string) (*structs.Stream, error) {
StartedAt: time,
Tags: tags,
Viewers: int(gjson.Get(data, "4.data.user.stream.viewersCount").Int()),
Preview: ProxyUrl(gjson.Get(data, "3.data.user.stream.previewImageURL").String()),
Preview: extractor.ProxyUrl(gjson.Get(data, "3.data.user.stream.previewImageURL").String()),
}
return &parsedStream, nil
@ -72,7 +73,7 @@ func ParseCategory(data gjson.Result) (structs.CategoryPreview, error) {
CreatedAt: data.Get("node.originalReleaseDate").Time(),
Tags: parsedTags,
Cursor: data.Get("node.cursor").String(),
Image: ProxyUrl(data.Get("node.avatarURL").String()),
Image: extractor.ProxyUrl(data.Get("node.avatarURL").String()),
}, nil
}
@ -95,11 +96,11 @@ func ParseMinifiedStream(data gjson.Result) (structs.CategoryMinifiedStream, err
parsedStream := structs.CategoryMinifiedStream{
Title: data.Get("node.title").String(),
Viewers: int(data.Get("node.viewersCount").Int()),
Preview: ProxyUrl(data.Get("node.previewImageURL").String()),
Preview: extractor.ProxyUrl(data.Get("node.previewImageURL").String()),
Tags: tags,
Streamer: structs.CategoryMinifiedStreamer{
Name: data.Get("node.broadcaster.login").String(),
Pfp: ProxyUrl(data.Get("node.broadcaster.profileImageURL").String()),
Pfp: extractor.ProxyUrl(data.Get("node.broadcaster.profileImageURL").String()),
ColorHex: streamerColorHex,
},
Cursor: data.Get("cursor").String(),

View file

@ -1,4 +1,4 @@
package extractor
package twitch
import (
"bytes"
@ -6,6 +6,7 @@ import (
"errors"
"io"
"net/http"
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/structs"
"github.com/tidwall/gjson"
@ -162,7 +163,7 @@ func GetStreamerInfo(streamerName string) (structs.Streamer, error) {
parsedStreamer := structs.Streamer{
Username: streamerData.Get("user.displayName").String(),
About: streamerData.Get("user.description").String(),
Pfp: ProxyUrl(streamerData.Get("user.profileImageURL").String()),
Pfp: extractor.ProxyUrl(streamerData.Get("user.profileImageURL").String()),
Followers: int(streamerData.Get("user.followers.totalCount").Int()),
Socials: parsedSocials,
IsLive: isLive,
@ -288,7 +289,7 @@ func GetDiscoveryItem(name string, streamLimit int, cursor string) (structs.Cate
Viewers: int(categoryData.Get("viewersCount").Int()),
Followers: int(categoryData.Get("followersCount").Int()),
Tags: tags,
Cover: ProxyUrl(categoryData.Get("avatarURL").String()),
Cover: extractor.ProxyUrl(categoryData.Get("avatarURL").String()),
Streams: parsedStreams,
}

View file

@ -1,16 +1,17 @@
package discover
import (
"safetwitch-backend/extractor"
"github.com/gin-gonic/gin"
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/twitch"
)
func Routes(route *gin.Engine) {
auth := route.Group("/api/discover")
auth.GET("/", func(context *gin.Context) {
data, err := extractor.GetDiscoveryPage(50, "")
data, err := twitch.GetDiscoveryPage(50, "")
if err != nil {
context.Error(err)
return
@ -20,7 +21,7 @@ func Routes(route *gin.Engine) {
})
auth.GET("/:categoryName", func(context *gin.Context) {
data, err := extractor.GetDiscoveryItem(context.Param("categoryName"), 50, "")
data, err := twitch.GetDiscoveryItem(context.Param("categoryName"), 50, "")
if err != nil {
context.Error(err)
}

View file

@ -2,6 +2,7 @@ package users
import (
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/twitch"
"github.com/gin-gonic/gin"
)
@ -10,7 +11,7 @@ func Routes(route *gin.Engine) {
auth := route.Group("/api/users")
auth.GET("/:streamerName", func(context *gin.Context) {
data, err := extractor.GetStreamerInfo(context.Param("streamerName"))
data, err := twitch.GetStreamerInfo(context.Param("streamerName"))
if err != nil {
if err.Error() == "streamer not found" {
context.JSON(404, gin.H{