This commit is contained in:
Nite07 2024-12-23 00:28:55 +08:00
parent ee09d2b468
commit 39c7389a0a
7 changed files with 259 additions and 84 deletions

View File

@ -278,7 +278,7 @@ func GetIGDBAppDetail(id int) (*model.IGDBGameDetail, error) {
return &data, nil return &data, nil
} }
var err error var err error
resp, err := igdbRequest(constant.IGDBGameURL, fmt.Sprintf(`where id=%v ;fields *,alternative_names.name,language_supports.language,language_supports.language_support_type,screenshots.url,cover.url,involved_companies.company,involved_companies.developer,involved_companies.publisher;`, id)) resp, err := igdbRequest(constant.IGDBGameURL, fmt.Sprintf(`where id = %v;fields *,alternative_names.*,language_supports.*,screenshots.*,cover.*,involved_companies.*,involved_companies.*,game_engines.*,game_modes.*,genres.*,player_perspectives.*,release_dates.*,videos.*,websites.*,platforms.*,themes.*,collections.*;`, id))
if err != nil { if err != nil {
return nil, err return nil, err
@ -339,7 +339,6 @@ func GenerateIGDBGameInfo(id int) (*model.GameInfo, error) {
item.Name = detail.Name item.Name = detail.Name
item.Description = detail.Summary item.Description = detail.Summary
item.Cover = strings.Replace(detail.Cover.URL, "t_thumb", "t_original", 1) item.Cover = strings.Replace(detail.Cover.URL, "t_thumb", "t_original", 1)
item.InfoUpdatedAt = time.Now()
for _, lang := range detail.LanguageSupports { for _, lang := range detail.LanguageSupports {
if lang.LanguageSupportType == 3 { if lang.LanguageSupportType == 3 {
@ -374,6 +373,57 @@ func GenerateIGDBGameInfo(id int) (*model.GameInfo, error) {
} }
} }
item.GameEngines = make([]string, 0)
for _, engine := range detail.GameEngines {
item.GameEngines = append(item.GameEngines, engine.Name)
}
item.GameModes = make([]string, 0)
for _, mode := range detail.GameModes {
item.GameModes = append(item.GameModes, mode.Name)
}
item.Genres = make([]string, 0)
for _, genre := range detail.Genres {
item.Genres = append(item.Genres, genre.Name)
}
item.Themes = make([]string, 0)
for _, theme := range detail.Themes {
item.Themes = append(item.Themes, theme.Name)
}
item.Platforms = make([]string, 0)
for _, platform := range detail.Platforms {
item.Platforms = append(item.Platforms, platform.Name)
}
item.PlayerPerspectives = make([]string, 0)
for _, perspective := range detail.PlayerPerspectives {
item.PlayerPerspectives = append(item.PlayerPerspectives, perspective.Name)
}
item.SimilarGames = detail.SimilarGames
item.Videos = make([]string, 0)
for _, video := range detail.Videos {
item.Videos = append(item.Videos, fmt.Sprintf("https://www.youtube.com/watch?v=%s", video.VideoID))
}
item.Websites = make([]string, 0)
for _, website := range detail.Websites {
item.Websites = append(item.Websites, website.URL)
}
item.Collections = make([]model.GameCollection, 0)
for _, collection := range detail.Collections {
item.Collections = append(item.Collections, model.GameCollection{
Games: collection.Games,
Name: collection.Name,
})
}
return item, nil return item, nil
} }

View File

@ -8,7 +8,6 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"time"
"pcgamedb/cache" "pcgamedb/cache"
"pcgamedb/constant" "pcgamedb/constant"
@ -69,7 +68,6 @@ func GenerateSteamGameInfo(id int) (*model.GameInfo, error) {
item.Cover = fmt.Sprintf("https://shared.cloudflare.steamstatic.com/store_item_assets/steam/apps/%v/library_600x900_2x.jpg", id) item.Cover = fmt.Sprintf("https://shared.cloudflare.steamstatic.com/store_item_assets/steam/apps/%v/library_600x900_2x.jpg", id)
item.Developers = detail.Data.Developers item.Developers = detail.Data.Developers
item.Publishers = detail.Data.Publishers item.Publishers = detail.Data.Publishers
item.InfoUpdatedAt = time.Now()
var screenshots []string var screenshots []string
for _, screenshot := range detail.Data.Screenshots { for _, screenshot := range detail.Data.Screenshots {
screenshots = append(screenshots, screenshot.PathFull) screenshots = append(screenshots, screenshot.PathFull)

View File

@ -168,9 +168,6 @@ func SaveGameInfo(item *model.GameInfo) error {
if item.CreatedAt.IsZero() { if item.CreatedAt.IsZero() {
item.CreatedAt = time.Now() item.CreatedAt = time.Now()
} }
if item.InfoUpdatedAt.IsZero() {
item.InfoUpdatedAt = item.CreatedAt
}
item.UpdatedAt = time.Now() item.UpdatedAt = time.Now()
filter := bson.M{"_id": item.ID} filter := bson.M{"_id": item.ID}
update := bson.M{"$set": item} update := bson.M{"$set": item}
@ -194,9 +191,6 @@ func SaveGameInfos(items []*model.GameInfo) error {
if item.CreatedAt.IsZero() { if item.CreatedAt.IsZero() {
item.CreatedAt = time.Now() item.CreatedAt = time.Now()
} }
if item.InfoUpdatedAt.IsZero() {
item.InfoUpdatedAt = item.CreatedAt
}
item.UpdatedAt = time.Now() item.UpdatedAt = time.Now()
operations[i] = mongo.NewUpdateOneModel(). operations[i] = mongo.NewUpdateOneModel().
SetFilter(bson.D{{Key: "_id", Value: item.ID}}). SetFilter(bson.D{{Key: "_id", Value: item.ID}}).
@ -950,5 +944,4 @@ func MergeGameInfo(oldInfo *model.GameInfo, newInfo *model.GameInfo) {
newInfo.IGDBID = oldInfo.IGDBID newInfo.IGDBID = oldInfo.IGDBID
newInfo.SteamID = oldInfo.SteamID newInfo.SteamID = oldInfo.SteamID
newInfo.CreatedAt = oldInfo.CreatedAt newInfo.CreatedAt = oldInfo.CreatedAt
newInfo.InfoUpdatedAt = time.Now()
} }

1
game_infos.json Normal file

File diff suppressed because one or more lines are too long

1
games.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,22 @@ type GameInfo struct {
Games []*GameItem `json:"games" bson:"-"` Games []*GameItem `json:"games" bson:"-"`
CreatedAt time.Time `json:"created_at" bson:"created_at"` CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"` UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`
InfoUpdatedAt time.Time `json:"info_updated_at" bson:"info_updated_at"` FirstReleaseDate time.Time `json:"first_release_date" bson:"first_release_date"`
GameEngines []string `json:"game_engines" bson:"game_engines"`
GameModes []string `json:"game_modes" bson:"game_modes"`
Genres []string `json:"genres" bson:"genres"`
Themes []string `json:"themes" bson:"themes"`
Platforms []string `json:"platforms" bson:"platforms"`
PlayerPerspectives []string `json:"player_perspectives" bson:"player_perspectives"`
SimilarGames []int `json:"similar_games" bson:"similar_games"`
Videos []string `json:"videos" bson:"videos"`
Websites []string `json:"websites" bson:"websites"`
Collections []GameCollection `json:"collections" bson:"collections"`
}
type GameCollection struct {
Games []int `json:"games"`
Name string `json:"name"`
} }
type GameItem struct { type GameItem struct {

View File

@ -1,66 +1,183 @@
package model package model
type IGDBGameDetail struct { type IGDBGameDetail struct {
ID int `json:"id,omitempty"` ID int `json:"id"`
ParentGame int `json:"parent_game,omitempty"` AgeRatings []int `json:"age_ratings"`
AgeRatings []int `json:"age_ratings,omitempty"` AggregatedRating float64 `json:"aggregated_rating"`
AggregatedRatingCount int `json:"aggregated_rating_count"`
Artworks []int `json:"artworks"`
Category int `json:"category"`
Cover struct {
ID int `json:"id"`
AlphaChannel bool `json:"alpha_channel"`
Animated bool `json:"animated"`
Game int `json:"game"`
Height int `json:"height"`
ImageID string `json:"image_id"`
URL string `json:"url"`
Width int `json:"width"`
Checksum string `json:"checksum"`
} `json:"cover"`
CreatedAt int `json:"created_at"`
Dlcs []int `json:"dlcs"`
ExternalGames []int `json:"external_games"`
FirstReleaseDate int `json:"first_release_date"`
GameEngines []struct {
ID int `json:"id"`
Companies []int `json:"companies"`
CreatedAt int `json:"created_at"`
Logo int `json:"logo"`
Name string `json:"name"`
Platforms []int `json:"platforms"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"game_engines"`
GameModes []struct {
ID int `json:"id"`
CreatedAt int `json:"created_at"`
Name string `json:"name"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"game_modes"`
Genres []struct {
ID int `json:"id"`
CreatedAt int `json:"created_at"`
Name string `json:"name"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"genres"`
Hypes int `json:"hypes"`
InvolvedCompanies []struct {
ID int `json:"id"`
Company int `json:"company"`
CreatedAt int `json:"created_at"`
Developer bool `json:"developer"`
Game int `json:"game"`
Porting bool `json:"porting"`
Publisher bool `json:"publisher"`
Supporting bool `json:"supporting"`
UpdatedAt int `json:"updated_at"`
Checksum string `json:"checksum"`
} `json:"involved_companies"`
Name string `json:"name"`
Platforms []struct {
ID int `json:"id"`
Abbreviation string `json:"abbreviation"`
AlternativeName string `json:"alternative_name"`
Category int `json:"category"`
CreatedAt int `json:"created_at"`
Name string `json:"name"`
PlatformLogo int `json:"platform_logo"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Versions []int `json:"versions"`
Websites []int `json:"websites"`
Checksum string `json:"checksum"`
Generation int `json:"generation,omitempty"`
PlatformFamily int `json:"platform_family,omitempty"`
Summary string `json:"summary,omitempty"`
} `json:"platforms"`
PlayerPerspectives []struct {
ID int `json:"id"`
CreatedAt int `json:"created_at"`
Name string `json:"name"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"player_perspectives"`
Rating float64 `json:"rating"`
RatingCount int `json:"rating_count"`
ReleaseDates []struct {
ID int `json:"id"`
Category int `json:"category"`
CreatedAt int `json:"created_at"`
Date int `json:"date"`
Game int `json:"game"`
Human string `json:"human"`
M int `json:"m"`
Platform int `json:"platform"`
Region int `json:"region"`
UpdatedAt int `json:"updated_at"`
Y int `json:"y"`
Checksum string `json:"checksum"`
} `json:"release_dates"`
Screenshots []struct {
ID int `json:"id"`
Game int `json:"game"`
Height int `json:"height"`
ImageID string `json:"image_id"`
URL string `json:"url"`
Width int `json:"width"`
Checksum string `json:"checksum"`
AlphaChannel bool `json:"alpha_channel,omitempty"`
Animated bool `json:"animated,omitempty"`
} `json:"screenshots"`
SimilarGames []int `json:"similar_games"`
Slug string `json:"slug"`
Summary string `json:"summary"`
Tags []int `json:"tags"`
Themes []struct {
ID int `json:"id"`
CreatedAt int `json:"created_at"`
Name string `json:"name"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"themes"`
TotalRating float64 `json:"total_rating"`
TotalRatingCount int `json:"total_rating_count"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Videos []struct {
ID int `json:"id"`
Game int `json:"game"`
Name string `json:"name"`
VideoID string `json:"video_id"`
Checksum string `json:"checksum"`
} `json:"videos"`
Websites []struct {
ID int `json:"id"`
Category int `json:"category"`
Game int `json:"game"`
Trusted bool `json:"trusted"`
URL string `json:"url"`
Checksum string `json:"checksum"`
} `json:"websites"`
Checksum string `json:"checksum"`
LanguageSupports []struct {
ID int `json:"id"`
Game int `json:"game"`
Language int `json:"language"`
LanguageSupportType int `json:"language_support_type"`
CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"`
Checksum string `json:"checksum"`
} `json:"language_supports"`
Collections []struct {
ID int `json:"id"`
CreatedAt int `json:"created_at"`
Games []int `json:"games"`
Name string `json:"name"`
Slug string `json:"slug"`
UpdatedAt int `json:"updated_at"`
URL string `json:"url"`
Checksum string `json:"checksum"`
Type int `json:"type"`
} `json:"collections"`
VersionParent int `json:"version_parent,omitempty"`
VersionTitle string `json:"version_title,omitempty"`
AlternativeNames []struct { AlternativeNames []struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
} `json:"alternative_names,omitempty"` } `json:"alternative_names,omitempty"`
Category int `json:"category,omitempty"`
Cover struct {
URL string `json:"url,omitempty"`
} `json:"cover,omitempty"`
CreatedAt int `json:"created_at,omitempty"`
ExternalGames []int `json:"external_games,omitempty"`
FirstReleaseDate int `json:"first_release_date,omitempty"`
Franchises []int `json:"franchises,omitempty"`
GameModes []int `json:"game_modes,omitempty"`
Genres []int `json:"genres,omitempty"`
InvolvedCompanies []struct {
Company int `json:"company,omitempty"`
Developer bool `json:"developer,omitempty"`
Publisher bool `json:"publisher,omitempty"`
} `json:"involved_companies,omitempty"`
Name string `json:"name,omitempty"`
Platforms []int `json:"platforms,omitempty"`
PlayerPerspectives []int `json:"player_perspectives,omitempty"`
Rating float64 `json:"rating,omitempty"`
RatingCount int `json:"rating_count,omitempty"`
ReleaseDates []int `json:"release_dates,omitempty"`
Screenshots []struct {
URL string `json:"url,omitempty"`
} `json:"screenshots,omitempty"`
SimilarGames []int `json:"similar_games,omitempty"`
Slug string `json:"slug,omitempty"`
Summary string `json:"summary,omitempty"`
Tags []int `json:"tags,omitempty"`
Themes []int `json:"themes,omitempty"`
TotalRating float64 `json:"total_rating,omitempty"`
TotalRatingCount int `json:"total_rating_count,omitempty"`
UpdatedAt int `json:"updated_at,omitempty"`
URL string `json:"url,omitempty"`
VersionParent int `json:"version_parent,omitempty"`
VersionTitle string `json:"version_title,omitempty"`
Checksum string `json:"checksum,omitempty"`
Websites []int `json:"websites,omitempty"`
GameLocalizations []int `json:"game_localizations,omitempty"`
AggregatedRating float64 `json:"aggregated_rating,omitempty"`
AggregatedRatingCount int `json:"aggregated_rating_count,omitempty"`
Artworks []int `json:"artworks,omitempty"`
Bundles []int `json:"bundles,omitempty"`
Collection int `json:"collection,omitempty"`
GameEngines []int `json:"game_engines,omitempty"`
Keywords []int `json:"keywords,omitempty"`
MultiplayerModes []int `json:"multiplayer_modes,omitempty"`
StandaloneExpansions []int `json:"standalone_expansions,omitempty"`
Storyline string `json:"storyline,omitempty"`
Videos []int `json:"videos,omitempty"`
LanguageSupports []struct {
Language int `json:"language,omitempty"`
LanguageSupportType int `json:"language_support_type,omitempty"`
} `json:"language_supports,omitempty"`
Collections []int `json:"collections,omitempty"`
} }
type IGDBGameDetails []*IGDBGameDetail type IGDBGameDetails []*IGDBGameDetail