diff --git a/models/tautulli.go b/models/tautulli.go index 1a8cad2..0f786a2 100644 --- a/models/tautulli.go +++ b/models/tautulli.go @@ -37,23 +37,23 @@ type TautulliHistoryItem struct { Secure interface{} `json:"secure"` Relayed interface{} `json:"relayed"` MediaType string `json:"media_type"` - RatingKey *int `json:"rating_key,omitempty"` - ParentRatingKey *int `json:"parent_rating_key,omitempty"` - GrandparentRatingKey *int `json:"grandparent_rating_key,omitempty"` + RatingKey interface{} `json:"rating_key,omitempty"` + ParentRatingKey interface{} `json:"parent_rating_key,omitempty"` + GrandparentRatingKey interface{} `json:"grandparent_rating_key,omitempty"` FullTitle *string `json:"full_title,omitempty"` Title *string `json:"title,omitempty"` ParentTitle *string `json:"parent_title,omitempty"` GrandparentTitle *string `json:"grandparent_title,omitempty"` OriginalTitle *string `json:"original_title,omitempty"` - Year int `json:"year,omitempty"` - MediaIndex *string `json:"media_index,omitempty"` - ParentMediaIndex *string `json:"parent_media_index,omitempty"` + Year interface{} `json:"year,omitempty"` + MediaIndex interface{} `json:"media_index,omitempty"` + ParentMediaIndex interface{} `json:"parent_media_index,omitempty"` Thumb *string `json:"thumb,omitempty"` OriginallyAvailableAt *string `json:"originally_available_at,omitempty"` GUID string `json:"guid"` TranscodeDecision string `json:"transcode_decision"` PercentComplete int `json:"percent_complete"` - WatchedStatus int `json:"watched_status"` + WatchedStatus interface{} `json:"watched_status"` GroupCount int `json:"group_count"` GroupIds string `json:"group_ids"` State interface{} `json:"state"` diff --git a/modules/statistics.go b/modules/statistics.go index b837a4d..e82cf5c 100644 --- a/modules/statistics.go +++ b/modules/statistics.go @@ -4,6 +4,7 @@ import ( "aunefyren/wrapperr/files" "aunefyren/wrapperr/models" "errors" + "fmt" "log" "strconv" "strings" @@ -236,18 +237,39 @@ func WrapperrDownloadDays(ID int, wrapperr_data []models.WrapperrDay, loop_inter } if tautulli_data[j].FullTitle == nil || - tautulli_data[j].GrandparentRatingKey == nil || tautulli_data[j].GrandparentTitle == nil || tautulli_data[j].OriginalTitle == nil || - tautulli_data[j].ParentRatingKey == nil || tautulli_data[j].ParentTitle == nil || - tautulli_data[j].RatingKey == nil || tautulli_data[j].Title == nil || tautulli_data[j].OriginallyAvailableAt == nil { log.Println("Tautulli item has missing data point(s). Unable to process statistics. Skipping data.") continue } + var year int = 0 + yearInt, err := strconv.Atoi(fmt.Sprintf("%v", tautulli_data[j].Year)) + if err == nil { + year = yearInt + } + + var grandparentRatingKey int = 0 + grandparentRatingKeyInt, err := strconv.Atoi(fmt.Sprintf("%v", tautulli_data[j].GrandparentRatingKey)) + if err == nil { + grandparentRatingKey = grandparentRatingKeyInt + } + + var parentRatingKey int = 0 + parentRatingKeyInt, err := strconv.Atoi(fmt.Sprintf("%v", tautulli_data[j].ParentRatingKey)) + if err == nil { + grandparentRatingKey = parentRatingKeyInt + } + + var ratingKey int = 0 + ratingKeyInt, err := strconv.Atoi(fmt.Sprintf("%v", tautulli_data[j].RatingKey)) + if err == nil { + ratingKey = ratingKeyInt + } + // Translate data to own struct tautulli_entry := models.TautulliEntry{ Date: tautulli_data[j].Date, @@ -255,19 +277,19 @@ func WrapperrDownloadDays(ID int, wrapperr_data []models.WrapperrDay, loop_inter Duration: tautulli_data[j].Duration, FriendlyName: tautulli_data[j].FriendlyName, FullTitle: *tautulli_data[j].FullTitle, - GrandparentRatingKey: *tautulli_data[j].GrandparentRatingKey, + GrandparentRatingKey: grandparentRatingKey, GrandparentTitle: *tautulli_data[j].GrandparentTitle, OriginalTitle: *tautulli_data[j].OriginalTitle, MediaType: tautulli_data[j].MediaType, - ParentRatingKey: *tautulli_data[j].ParentRatingKey, + ParentRatingKey: parentRatingKey, ParentTitle: *tautulli_data[j].ParentTitle, PausedCounter: tautulli_data[j].PausedCounter, PercentComplete: tautulli_data[j].PercentComplete, - RatingKey: *tautulli_data[j].RatingKey, + RatingKey: ratingKey, Title: *tautulli_data[j].Title, User: tautulli_data[j].User, UserID: tautulli_data[j].UserID, - Year: tautulli_data[j].Year, + Year: year, OriginallyAvailableAt: *tautulli_data[j].OriginallyAvailableAt, }