Skip to content

Commit

Permalink
Integer parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Dec 12, 2023
1 parent 449e618 commit 35b9d28
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
14 changes: 7 additions & 7 deletions models/tautulli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
36 changes: 29 additions & 7 deletions modules/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"aunefyren/wrapperr/files"
"aunefyren/wrapperr/models"
"errors"
"fmt"
"log"
"strconv"
"strings"
Expand Down Expand Up @@ -236,38 +237,59 @@ 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,
RowID: tautulli_data[j].RowID,
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,
}

Expand Down

0 comments on commit 35b9d28

Please sign in to comment.