imdbs/models.go

114 lines
3.3 KiB
Go

package imdbs
import (
"html"
"strings"
"time"
)
// IMDbEntry is a struct that represents an IMDb entry (movie or series)
type IMDbEntry struct {
AlternateName string `json:",omitempty"`
IMDbID string `json:",omitempty"`
Rating float64 `json:",omitempty"`
RuntimeInMins int64 `json:",omitempty"`
Title string `json:",omitempty"`
Type string `json:",omitempty"`
Year int64 `json:",omitempty"`
}
// IMDbJSON is a struct that represents the json encoded data of an IMDb entry
type IMDbJSON struct {
Context string `json:"@context"`
Type string `json:"@type"`
URL string `json:"url"`
Name string `json:"name"`
AlternateName string `json:"alternateName"`
Image string `json:"image"`
Description string `json:"description"`
Review struct {
Type string `json:"@type"`
ItemReviewed struct {
Type string `json:"@type"`
URL string `json:"url"`
} `json:"itemReviewed"`
Author struct {
Type string `json:"@type"`
Name string `json:"name"`
} `json:"author"`
DateCreated string `json:"dateCreated"`
InLanguage string `json:"inLanguage"`
Name string `json:"name"`
ReviewBody string `json:"reviewBody"`
ReviewRating struct {
Type string `json:"@type"`
WorstRating int `json:"worstRating"`
BestRating int `json:"bestRating"`
RatingValue int `json:"ratingValue"`
} `json:"reviewRating"`
} `json:"review"`
AggregateRating struct {
Type string `json:"@type"`
RatingCount int `json:"ratingCount"`
BestRating int `json:"bestRating"`
WorstRating int `json:"worstRating"`
RatingValue float64 `json:"ratingValue"`
} `json:"aggregateRating"`
ContentRating string `json:"contentRating"`
Genre []string `json:"genre"`
DatePublished string `json:"datePublished"`
Keywords string `json:"keywords"`
Trailer struct {
Type string `json:"@type"`
Name string `json:"name"`
EmbedURL string `json:"embedUrl"`
Thumbnail struct {
Type string `json:"@type"`
ContentURL string `json:"contentUrl"`
} `json:"thumbnail"`
ThumbnailURL string `json:"thumbnailUrl"`
URL string `json:"url"`
Description string `json:"description"`
Duration string `json:"duration"`
UploadDate time.Time `json:"uploadDate"`
} `json:"trailer"`
Actor []struct {
Type string `json:"@type"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"actor"`
Director []struct {
Type string `json:"@type"`
URL string `json:"url"`
Name string `json:"name"`
} `json:"director"`
Creator []struct {
Type string `json:"@type"`
URL string `json:"url"`
Name string `json:"name,omitempty"`
} `json:"creator"`
Duration string `json:"duration"`
}
func (s IMDbJSON) TransformIntoIMDbEntry(id string, year int64) IMDbEntry {
if s.Name == "" || s.Type == "" || s.AggregateRating.RatingValue == 0 {
return IMDbEntry{}
}
entry := IMDbEntry{
IMDbID: id,
AlternateName: html.UnescapeString(s.AlternateName),
Rating: s.AggregateRating.RatingValue,
RuntimeInMins: 0,
Title: html.UnescapeString(s.Name),
Type: strings.Replace(s.Type, "TVSeries", "Series", -1),
Year: year,
}
if entry.Type == "Movie" {
entry.RuntimeInMins = convertIMDbRuntimeIntoMinutes(s.Duration)
}
return entry
}