0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-03 03:10:05 -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 ( import (
"errors" "errors"
"safetwitch-backend/extractor"
"safetwitch-backend/extractor/structs" "safetwitch-backend/extractor/structs"
"time" "time"
@ -50,7 +51,7 @@ func ParseStream(data string) (*structs.Stream, error) {
StartedAt: time, StartedAt: time,
Tags: tags, Tags: tags,
Viewers: int(gjson.Get(data, "4.data.user.stream.viewersCount").Int()), 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 return &parsedStream, nil
@ -72,7 +73,7 @@ func ParseCategory(data gjson.Result) (structs.CategoryPreview, error) {
CreatedAt: data.Get("node.originalReleaseDate").Time(), CreatedAt: data.Get("node.originalReleaseDate").Time(),
Tags: parsedTags, Tags: parsedTags,
Cursor: data.Get("node.cursor").String(), Cursor: data.Get("node.cursor").String(),
Image: ProxyUrl(data.Get("node.avatarURL").String()), Image: extractor.ProxyUrl(data.Get("node.avatarURL").String()),
}, nil }, nil
} }
@ -95,11 +96,11 @@ func ParseMinifiedStream(data gjson.Result) (structs.CategoryMinifiedStream, err
parsedStream := structs.CategoryMinifiedStream{ parsedStream := structs.CategoryMinifiedStream{
Title: data.Get("node.title").String(), Title: data.Get("node.title").String(),
Viewers: int(data.Get("node.viewersCount").Int()), Viewers: int(data.Get("node.viewersCount").Int()),
Preview: ProxyUrl(data.Get("node.previewImageURL").String()), Preview: extractor.ProxyUrl(data.Get("node.previewImageURL").String()),
Tags: tags, Tags: tags,
Streamer: structs.CategoryMinifiedStreamer{ Streamer: structs.CategoryMinifiedStreamer{
Name: data.Get("node.broadcaster.login").String(), 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, ColorHex: streamerColorHex,
}, },
Cursor: data.Get("cursor").String(), Cursor: data.Get("cursor").String(),

View file

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

View file

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

View file

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