2023-10-01 09:00:33 +02:00
|
|
|
package imdbs
|
|
|
|
|
2023-10-18 20:49:56 +02:00
|
|
|
import (
|
2023-10-25 19:00:21 +02:00
|
|
|
"html"
|
2023-10-18 20:49:56 +02:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
2023-10-01 09:00:33 +02:00
|
|
|
|
|
|
|
// 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,
|
2023-10-25 19:00:21 +02:00
|
|
|
AlternateName: html.UnescapeString(s.AlternateName),
|
2023-10-01 09:00:33 +02:00
|
|
|
Rating: s.AggregateRating.RatingValue,
|
|
|
|
RuntimeInMins: 0,
|
2023-10-25 19:00:21 +02:00
|
|
|
Title: html.UnescapeString(s.Name),
|
2023-10-18 20:49:56 +02:00
|
|
|
Type: strings.Replace(s.Type, "TVSeries", "Series", -1),
|
2023-10-01 09:00:33 +02:00
|
|
|
Year: year,
|
|
|
|
}
|
|
|
|
|
|
|
|
if entry.Type == "Movie" {
|
|
|
|
entry.RuntimeInMins = convertIMDbRuntimeIntoMinutes(s.Duration)
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry
|
|
|
|
}
|