internal/structs.go

165 lines · 4105 bytes · executable

  1package internal
  2
  3import "time"
  4
  5type AnimeTitle struct {
  6	Romaji   string `json:"title_romanji"`
  7	English  string `json:"title"`
  8	Japanese string `json:"title_japanese"`
  9}
 10
 11type Anime struct {
 12	Title          AnimeTitle `json:"title"`
 13	Ep             Episode    `json:"ep"`
 14	CoverImage     string     `json:"url"`            // Assuming this field corresponds to the cover image URL
 15	TotalEpisodes  int        `json:"total_episodes"` // If provided by the API
 16	MalId          int        `json:"mal_id"`
 17	AnilistId      int        `json:"anilist_id"` // Assuming you have an Anilist ID in your struct
 18	Rewatching     bool
 19	Repeat         int
 20	StartedAt      FuzzyDate
 21	CompletedAt    FuzzyDate
 22	ProviderId     string // Can be populated as necessary
 23	ProviderName   string // newly added for history migration
 24	FillerEpisodes []int
 25	IsAiring       bool
 26}
 27
 28type FuzzyDate struct {
 29	Year  int `json:"year"`
 30	Month int `json:"month"`
 31	Day   int `json:"day"`
 32}
 33
 34type Skip struct {
 35	Start int `json:"start"`
 36	End   int `json:"end"`
 37}
 38
 39type SkipTimes struct {
 40	Op Skip `json:"op"`
 41	Ed Skip `json:"ed"`
 42}
 43
 44type Episode struct {
 45	Title          AnimeTitle   `json:"title"`
 46	Number         int          `json:"number"`
 47	SkipTimes      SkipTimes    `json:"skip_times"`
 48	Player         playingVideo `json:"player"`
 49	Resume         bool         `json:"resume"`
 50	Started        bool         `json:"started"`
 51	Duration       int          `json:"duration"`
 52	Links          []string     `json:"links"`
 53	NextEpisode    NextEpisode  `json:"next_episode"`
 54	IsFiller       bool         `json:"filler"`
 55	IsRecap        bool         `json:"recap"`
 56	Aired          string       `json:"aired"`
 57	Synopsis       string       `json:"synopsis"`
 58	ContinueLast   bool
 59	LastWasSkipped bool // used in filler check
 60	IsCompleted    bool
 61}
 62
 63type NextEpisode struct {
 64	Number int
 65	Links  []string
 66}
 67
 68type playingVideo struct {
 69	Url          string
 70	Speed        float64 `json:"speed"`
 71	PlaybackTime int     `json:"playback_time"`
 72	SocketPath   string
 73}
 74
 75type User struct {
 76	Token     string
 77	Username  string
 78	Id        int
 79	AnimeList AnimeList
 80	ListSync  *AnimeListSync
 81}
 82
 83var globalUser *User
 84
 85func SetGlobalUser(user *User) {
 86	globalUser = user
 87}
 88
 89func GetGlobalUser() *User {
 90	return globalUser
 91}
 92
 93// AniListAnime is the struct for the API response
 94type AniListAnime struct {
 95	ID    int `json:"id"`
 96	Title struct {
 97		Romaji  string `json:"romaji"`
 98		English string `json:"english"`
 99		Native  string `json:"native"`
100	} `json:"title"`
101	CoverImage struct {
102		Large string `json:"large"`
103	} `json:"coverImage"`
104}
105
106// Page represents the page in AniList response
107type Page struct {
108	Media []AniListAnime `json:"media"`
109}
110
111// ResponseData represents the full response structure
112type ResponseData struct {
113	Page Page `json:"Page"`
114}
115
116type Media struct {
117	Duration int        `json:"duration"`
118	Episodes int        `json:"episodes"`
119	ID       int        `json:"id"`
120	MalID    int        `json:"mal_id"`
121	Title    AnimeTitle `json:"title"`
122	Status   string     `json:"status"`
123}
124
125type Entry struct {
126	ListID      int       `json:"id"`
127	Media       Media     `json:"media"`
128	Progress    int       `json:"progress"`
129	Repeat      int       `json:"repeat"`
130	Score       float64   `json:"score"`
131	Status      string    `json:"status"`
132	StartedAt   FuzzyDate `json:"startedAt"`
133	CompletedAt FuzzyDate `json:"completedAt"`
134	CoverImage  string    `json:"coverImage"`
135	UpdatedAt   time.Time `json:"updatedAt"`
136}
137
138type AnimeList struct {
139	Watching   []Entry `json:"watching"`
140	Completed  []Entry `json:"completed"`
141	Paused     []Entry `json:"paused"`
142	Dropped    []Entry `json:"dropped"`
143	Planning   []Entry `json:"planning"`
144	Rewatching []Entry `json:"rewatching"`
145}
146
147type RofiSelectPreview struct {
148	Title      string `json:"title"`
149	CoverImage string `json:"coverImage"`
150}
151
152type SelectionOptionImage struct {
153	Key        string
154	Label      string
155	CoverImage string
156}
157
158// SelectionOption holds the label and the internal key
159type SelectionOption struct {
160	Title     string
161	Label     string
162	Key       string
163	Thumbnail string
164	ExtraData interface{}
165}