internal/structs.go
187 lines · 4911 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 SkipRemoteSync bool `json:"-"`
27}
28
29type FuzzyDate struct {
30 Year int `json:"year"`
31 Month int `json:"month"`
32 Day int `json:"day"`
33}
34
35type Skip struct {
36 Start int `json:"start"`
37 End int `json:"end"`
38}
39
40type SkipTimes struct {
41 Op Skip `json:"op"`
42 Ed Skip `json:"ed"`
43}
44
45type Episode struct {
46 Title AnimeTitle `json:"title"`
47 Number int `json:"number"`
48 SkipTimes SkipTimes `json:"skip_times"`
49 Player playingVideo `json:"player"`
50 Resume bool `json:"resume"`
51 Started bool `json:"started"`
52 Duration int `json:"duration"`
53 Links []string `json:"links"`
54 StreamReferrer string `json:"-"`
55 SubtitleURL string `json:"-"`
56 NextEpisode NextEpisode `json:"next_episode"`
57 IsFiller bool `json:"filler"`
58 IsRecap bool `json:"recap"`
59 Aired string `json:"aired"`
60 Synopsis string `json:"synopsis"`
61 ContinueLast bool
62 LastWasSkipped bool // used in filler check
63 IsCompleted bool
64}
65
66type NextEpisode struct {
67 Number int
68 Links []string
69 ProviderName string
70 ProviderId string
71 Mode string
72}
73
74type NextAiringEpisodeInfo struct {
75 Episode int
76 TimeUntilAiring int
77}
78
79// StreamPlaybackHint carries MPV playback metadata for a resolved stream URL.
80type StreamPlaybackHint struct {
81 Referrer string
82 Subtitle string
83}
84
85type playingVideo struct {
86 Url string
87 Speed float64 `json:"speed"`
88 PlaybackTime int `json:"playback_time"`
89 SocketPath string
90}
91
92type User struct {
93 Token string
94 Username string
95 Id int
96 AnimeList AnimeList
97 ListSync *AnimeListSync
98}
99
100var globalUser *User
101
102func SetGlobalUser(user *User) {
103 globalUser = user
104}
105
106func GetGlobalUser() *User {
107 return globalUser
108}
109
110// AniListAnime is the struct for the API response
111type AniListAnime struct {
112 ID int `json:"id"`
113 Episodes int `json:"episodes"`
114 Title struct {
115 Romaji string `json:"romaji"`
116 English string `json:"english"`
117 Native string `json:"native"`
118 } `json:"title"`
119 CoverImage struct {
120 Large string `json:"large"`
121 } `json:"coverImage"`
122}
123
124// Page represents the page in AniList response
125type Page struct {
126 Media []AniListAnime `json:"media"`
127}
128
129// ResponseData represents the full response structure
130type ResponseData struct {
131 Page Page `json:"Page"`
132}
133
134type Media struct {
135 Duration int `json:"duration"`
136 Episodes int `json:"episodes"`
137 Format string `json:"format"`
138 ID int `json:"id"`
139 MalID int `json:"mal_id"`
140 Title AnimeTitle `json:"title"`
141 Status string `json:"status"`
142 NextAiringEpisode *NextAiringEpisodeInfo `json:"nextAiringEpisode,omitempty"`
143}
144
145type Entry struct {
146 ListID int `json:"id"`
147 Media Media `json:"media"`
148 Progress int `json:"progress"`
149 Repeat int `json:"repeat"`
150 Score float64 `json:"score"`
151 Status string `json:"status"`
152 StartedAt FuzzyDate `json:"startedAt"`
153 CompletedAt FuzzyDate `json:"completedAt"`
154 CoverImage string `json:"coverImage"`
155 UpdatedAt time.Time `json:"updatedAt"`
156}
157
158type AnimeList struct {
159 Watching []Entry `json:"watching"`
160 Completed []Entry `json:"completed"`
161 Paused []Entry `json:"paused"`
162 Dropped []Entry `json:"dropped"`
163 Planning []Entry `json:"planning"`
164 Rewatching []Entry `json:"rewatching"`
165}
166
167type RofiSelectPreview struct {
168 Title string `json:"title"`
169 CoverImage string `json:"coverImage"`
170 HasNewEpisodes bool `json:"-"`
171}
172
173type SelectionOptionImage struct {
174 Key string
175 Label string
176 CoverImage string
177}
178
179// SelectionOption holds the label and the internal key
180type SelectionOption struct {
181 Title string
182 Label string
183 Key string
184 Thumbnail string
185 ExtraData interface{}
186 HasNewEpisodes bool
187}