internal/structs.go

179 lines · 4516 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
 74// StreamPlaybackHint carries MPV playback metadata for a resolved stream URL.
 75type StreamPlaybackHint struct {
 76	Referrer string
 77	Subtitle string
 78}
 79
 80type playingVideo struct {
 81	Url          string
 82	Speed        float64 `json:"speed"`
 83	PlaybackTime int     `json:"playback_time"`
 84	SocketPath   string
 85}
 86
 87type User struct {
 88	Token     string
 89	Username  string
 90	Id        int
 91	AnimeList AnimeList
 92	ListSync  *AnimeListSync
 93}
 94
 95var globalUser *User
 96
 97func SetGlobalUser(user *User) {
 98	globalUser = user
 99}
100
101func GetGlobalUser() *User {
102	return globalUser
103}
104
105// AniListAnime is the struct for the API response
106type AniListAnime struct {
107	ID       int `json:"id"`
108	Episodes int `json:"episodes"`
109	Title    struct {
110		Romaji  string `json:"romaji"`
111		English string `json:"english"`
112		Native  string `json:"native"`
113	} `json:"title"`
114	CoverImage struct {
115		Large string `json:"large"`
116	} `json:"coverImage"`
117}
118
119// Page represents the page in AniList response
120type Page struct {
121	Media []AniListAnime `json:"media"`
122}
123
124// ResponseData represents the full response structure
125type ResponseData struct {
126	Page Page `json:"Page"`
127}
128
129type Media struct {
130	Duration int        `json:"duration"`
131	Episodes int        `json:"episodes"`
132	Format   string     `json:"format"`
133	ID       int        `json:"id"`
134	MalID    int        `json:"mal_id"`
135	Title    AnimeTitle `json:"title"`
136	Status   string     `json:"status"`
137}
138
139type Entry struct {
140	ListID      int       `json:"id"`
141	Media       Media     `json:"media"`
142	Progress    int       `json:"progress"`
143	Repeat      int       `json:"repeat"`
144	Score       float64   `json:"score"`
145	Status      string    `json:"status"`
146	StartedAt   FuzzyDate `json:"startedAt"`
147	CompletedAt FuzzyDate `json:"completedAt"`
148	CoverImage  string    `json:"coverImage"`
149	UpdatedAt   time.Time `json:"updatedAt"`
150}
151
152type AnimeList struct {
153	Watching   []Entry `json:"watching"`
154	Completed  []Entry `json:"completed"`
155	Paused     []Entry `json:"paused"`
156	Dropped    []Entry `json:"dropped"`
157	Planning   []Entry `json:"planning"`
158	Rewatching []Entry `json:"rewatching"`
159}
160
161type RofiSelectPreview struct {
162	Title      string `json:"title"`
163	CoverImage string `json:"coverImage"`
164}
165
166type SelectionOptionImage struct {
167	Key        string
168	Label      string
169	CoverImage string
170}
171
172// SelectionOption holds the label and the internal key
173type SelectionOption struct {
174	Title     string
175	Label     string
176	Key       string
177	Thumbnail string
178	ExtraData interface{}
179}