mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 17:19:53 +01:00
GetAnimeDetail
This commit is contained in:
1
huso.go
1
huso.go
@@ -20,6 +20,7 @@ const (
|
|||||||
seasonApiJikan = "seasons/now"
|
seasonApiJikan = "seasons/now"
|
||||||
userApiJikan = "users/"
|
userApiJikan = "users/"
|
||||||
userApiMal = "users/"
|
userApiMal = "users/"
|
||||||
|
animeApiMal = "anime/"
|
||||||
malApiStatusP = "plan_to_watch"
|
malApiStatusP = "plan_to_watch"
|
||||||
malApiStatusW = "watching"
|
malApiStatusW = "watching"
|
||||||
malApiStatusC = "completed"
|
malApiStatusC = "completed"
|
||||||
|
|||||||
44
klotz.go
44
klotz.go
@@ -26,6 +26,50 @@ type RegisterData struct {
|
|||||||
Sauce string `json:"sauce"`
|
Sauce string `json:"sauce"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AnimeDetailMal struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
MainPicture struct {
|
||||||
|
Medium string `json:"medium"`
|
||||||
|
Large string `json:"large"`
|
||||||
|
} `json:"main_picture"`
|
||||||
|
AlternativeTitles struct {
|
||||||
|
Synonyms []string `json:"synonyms"`
|
||||||
|
En string `json:"en"`
|
||||||
|
Ja string `json:"ja"`
|
||||||
|
} `json:"alternative_titles"`
|
||||||
|
StartDate string `json:"start_date"`
|
||||||
|
Synopsis string `json:"synopsis"`
|
||||||
|
Mean float64 `json:"mean"`
|
||||||
|
Rank int `json:"rank"`
|
||||||
|
Popularity int `json:"popularity"`
|
||||||
|
NumListUsers int `json:"num_list_users"`
|
||||||
|
NumScoringUsers int `json:"num_scoring_users"`
|
||||||
|
Nsfw string `json:"nsfw"`
|
||||||
|
MediaType string `json:"media_type"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Genres []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"genres"`
|
||||||
|
NumEpisodes int `json:"num_episodes"`
|
||||||
|
StartSeason struct {
|
||||||
|
Year int `json:"year"`
|
||||||
|
Season string `json:"season"`
|
||||||
|
} `json:"start_season"`
|
||||||
|
Broadcast struct {
|
||||||
|
DayOfTheWeek string `json:"day_of_the_week"`
|
||||||
|
StartTime string `json:"start_time"`
|
||||||
|
} `json:"broadcast"`
|
||||||
|
Source string `json:"source"`
|
||||||
|
AverageEpisodeDuration int `json:"average_episode_duration"`
|
||||||
|
Rating string `json:"rating"`
|
||||||
|
Studios []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
} `json:"studios"`
|
||||||
|
}
|
||||||
|
|
||||||
type AnimeListMal struct {
|
type AnimeListMal struct {
|
||||||
Data []struct {
|
Data []struct {
|
||||||
Node struct {
|
Node struct {
|
||||||
|
|||||||
14
knecht.go
14
knecht.go
@@ -12,6 +12,20 @@ import (
|
|||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func GetAnimeDetailData(malId int64) (*AnimeDetailMal, []byte, error) {
|
||||||
|
var anime AnimeDetailMal
|
||||||
|
body, err := GetAnimeDetailBytes(malId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, body, err
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(body, &anime)
|
||||||
|
return &anime, body, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAnimeDetailBytes(malId int64) ([]byte, error) {
|
||||||
|
return GetDataMal(animeApiMal + strconv.FormatInt(malId, 10) + "?fields=id,title,main_picture,alternative_titles,start_date,end_date,synopsis,mean,rank,popularity,num_list_users,num_scoring_users,nsfw,media_type,status,genres,my_list_status,num_episodes,start_season,broadcast,source,average_episode_duration,rating,studios")
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error) {
|
func GetUserAnimeListData(username, status string) (*AnimeListMal, []byte, error) {
|
||||||
var list AnimeListMal
|
var list AnimeListMal
|
||||||
body, err := GetUserAnimeListBytes(username, status)
|
body, err := GetUserAnimeListBytes(username, status)
|
||||||
|
|||||||
22
ober.go
22
ober.go
@@ -181,7 +181,7 @@ func Register(ctx *fasthttp.RequestCtx) {
|
|||||||
|
|
||||||
func WatchPost(ctx *fasthttp.RequestCtx) {
|
func WatchPost(ctx *fasthttp.RequestCtx) {
|
||||||
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
auth := ctx.Request.Header.Peek("X-HUSO-AUTH")
|
||||||
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" {
|
if ctx.UserValue("user") == nil || auth == nil || string(auth) == "" || string(ctx.Request.Header.ContentType()) != "application/json" {
|
||||||
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -190,6 +190,26 @@ func WatchPost(ctx *fasthttp.RequestCtx) {
|
|||||||
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
|
ctx.SetStatusCode(fasthttp.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body := ctx.PostBody()
|
||||||
|
var animes []Anime
|
||||||
|
err := json.Unmarshal(body, &animes)
|
||||||
|
if err != nil || len(animes) == 0 {
|
||||||
|
ctx.WriteString(err.Error())
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, anime := range animes {
|
||||||
|
// TODO iterate animes
|
||||||
|
detail, _, err := GetAnimeDetailData(anime.Anime)
|
||||||
|
if err != nil {
|
||||||
|
ctx.WriteString(err.Error())
|
||||||
|
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", detail)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GheddoAuth(username, auth string) bool {
|
func GheddoAuth(username, auth string) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user