| @@ -176,6 +176,231 @@ func CurdOut(data interface{}) { |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { |
| 180 | // Create update options map |
| 181 | updateOptions := map[string]string{ |
| 182 | "CATEGORY": "Change Anime Category", |
| 183 | "PROGRESS": "Change Progress", |
| 184 | "SCORE": "Add/Change Score", |
| 185 | } |
| 186 | |
| 187 | // Select update option |
| 188 | updateSelection, err := DynamicSelect(updateOptions, false) |
| 189 | if err != nil { |
| 190 | Log(fmt.Sprintf("Failed to select update option: %v", err), logFile) |
| 191 | ExitCurd(fmt.Errorf("Failed to select update option")) |
| 192 | } |
| 193 | |
| 194 | if updateSelection.Key == "-1" { |
| 195 | ExitCurd(nil) |
| 196 | } |
| 197 | |
| 198 | // Get user's anime list |
| 199 | var animeListMap map[string]string |
| 200 | var animeListMapPreview map[string]RofiSelectPreview |
| 201 | |
| 202 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 203 | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 204 | // Include anime from all categories |
| 205 | for _, entry := range user.AnimeList.Watching { |
| 206 | title := entry.Media.Title.English |
| 207 | if title == "" { |
| 208 | title = entry.Media.Title.Romaji |
| 209 | } |
| 210 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 211 | Title: title, |
| 212 | CoverImage: entry.CoverImage, |
| 213 | } |
| 214 | } |
| 215 | for _, entry := range user.AnimeList.Completed { |
| 216 | title := entry.Media.Title.English |
| 217 | if title == "" { |
| 218 | title = entry.Media.Title.Romaji |
| 219 | } |
| 220 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 221 | Title: title, |
| 222 | CoverImage: entry.CoverImage, |
| 223 | } |
| 224 | } |
| 225 | for _, entry := range user.AnimeList.Paused { |
| 226 | title := entry.Media.Title.English |
| 227 | if title == "" { |
| 228 | title = entry.Media.Title.Romaji |
| 229 | } |
| 230 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 231 | Title: title, |
| 232 | CoverImage: entry.CoverImage, |
| 233 | } |
| 234 | } |
| 235 | for _, entry := range user.AnimeList.Dropped { |
| 236 | title := entry.Media.Title.English |
| 237 | if title == "" { |
| 238 | title = entry.Media.Title.Romaji |
| 239 | } |
| 240 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 241 | Title: title, |
| 242 | CoverImage: entry.CoverImage, |
| 243 | } |
| 244 | } |
| 245 | for _, entry := range user.AnimeList.Planning { |
| 246 | title := entry.Media.Title.English |
| 247 | if title == "" { |
| 248 | title = entry.Media.Title.Romaji |
| 249 | } |
| 250 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 251 | Title: title, |
| 252 | CoverImage: entry.CoverImage, |
| 253 | } |
| 254 | } |
| 255 | } else { |
| 256 | animeListMap = make(map[string]string) |
| 257 | // Include anime from all categories |
| 258 | for _, entry := range user.AnimeList.Watching { |
| 259 | title := entry.Media.Title.English |
| 260 | if title == "" { |
| 261 | title = entry.Media.Title.Romaji |
| 262 | } |
| 263 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 264 | } |
| 265 | for _, entry := range user.AnimeList.Completed { |
| 266 | title := entry.Media.Title.English |
| 267 | if title == "" { |
| 268 | title = entry.Media.Title.Romaji |
| 269 | } |
| 270 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 271 | } |
| 272 | for _, entry := range user.AnimeList.Paused { |
| 273 | title := entry.Media.Title.English |
| 274 | if title == "" { |
| 275 | title = entry.Media.Title.Romaji |
| 276 | } |
| 277 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 278 | } |
| 279 | for _, entry := range user.AnimeList.Dropped { |
| 280 | title := entry.Media.Title.English |
| 281 | if title == "" { |
| 282 | title = entry.Media.Title.Romaji |
| 283 | } |
| 284 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 285 | } |
| 286 | for _, entry := range user.AnimeList.Planning { |
| 287 | title := entry.Media.Title.English |
| 288 | if title == "" { |
| 289 | title = entry.Media.Title.Romaji |
| 290 | } |
| 291 | animeListMap[strconv.Itoa(entry.Media.ID)] = title |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | // Select anime to update |
| 296 | var selectedAnime SelectionOption |
| 297 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 298 | selectedAnime, err = DynamicSelectPreview(animeListMapPreview, false) |
| 299 | } else { |
| 300 | selectedAnime, err = DynamicSelect(animeListMap, false) |
| 301 | } |
| 302 | if err != nil { |
| 303 | Log(fmt.Sprintf("Failed to select anime: %v", err), logFile) |
| 304 | ExitCurd(fmt.Errorf("Failed to select anime")) |
| 305 | } |
| 306 | |
| 307 | if selectedAnime.Key == "-1" { |
| 308 | ExitCurd(nil) |
| 309 | } |
| 310 | |
| 311 | animeID, err := strconv.Atoi(selectedAnime.Key) |
| 312 | if err != nil { |
| 313 | Log(fmt.Sprintf("Failed to convert anime ID: %v", err), logFile) |
| 314 | ExitCurd(fmt.Errorf("Failed to convert anime ID")) |
| 315 | } |
| 316 | |
| 317 | // After getting animeID, get the current anime entry |
| 318 | selectedAnilistAnime, err := FindAnimeByAnilistID(user.AnimeList, selectedAnime.Key) |
| 319 | if err != nil { |
| 320 | Log(fmt.Sprintf("Can not find the anime in anilist animelist: %v", err), logFile) |
| 321 | ExitCurd(fmt.Errorf("Can not find the anime in anilist animelist")) |
| 322 | } |
| 323 | ClearScreen() |
| 324 | switch updateSelection.Key { |
| 325 | case "CATEGORY": |
| 326 | categories := map[string]string{ |
| 327 | "CURRENT": "Currently Watching", |
| 328 | "COMPLETED": "Completed", |
| 329 | "PAUSED": "On Hold", |
| 330 | "DROPPED": "Dropped", |
| 331 | "PLANNING": "Plan to Watch", |
| 332 | } |
| 333 | |
| 334 | currentStatus := "None" |
| 335 | if selectedAnilistAnime.Status != "" { |
| 336 | currentStatus = categories[selectedAnilistAnime.Status] |
| 337 | } |
| 338 | CurdOut(fmt.Sprintf("Current category: %s", currentStatus)) |
| 339 | |
| 340 | categorySelection, err := DynamicSelect(categories, false) |
| 341 | if err != nil { |
| 342 | Log(fmt.Sprintf("Failed to select category: %v", err), logFile) |
| 343 | ExitCurd(fmt.Errorf("Failed to select category")) |
| 344 | } |
| 345 | |
| 346 | if categorySelection.Key == "-1" { |
| 347 | ExitCurd(nil) |
| 348 | } |
| 349 | |
| 350 | err = UpdateAnimeStatus(user.Token, animeID, categorySelection.Key) |
| 351 | if err != nil { |
| 352 | Log(fmt.Sprintf("Failed to update anime status: %v", err), logFile) |
| 353 | ExitCurd(fmt.Errorf("Failed to update anime status")) |
| 354 | } |
| 355 | |
| 356 | case "PROGRESS": |
| 357 | currentProgress := "None" |
| 358 | if selectedAnilistAnime.Progress > 0 { |
| 359 | currentProgress = strconv.Itoa(selectedAnilistAnime.Progress) |
| 360 | } |
| 361 | |
| 362 | var progress string |
| 363 | if userCurdConfig.RofiSelection { |
| 364 | progress, err = GetUserInputFromRofi(fmt.Sprintf("Current progress: %s\nEnter new progress (episode number)", currentProgress)) |
| 365 | if err != nil { |
| 366 | Log(fmt.Sprintf("Failed to get progress input: %v", err), logFile) |
| 367 | ExitCurd(fmt.Errorf("Failed to get progress input")) |
| 368 | } |
| 369 | } else { |
| 370 | CurdOut(fmt.Sprintf("Current progress: %s", currentProgress)) |
| 371 | CurdOut("Enter new progress (episode number):") |
| 372 | fmt.Scanln(&progress) |
| 373 | } |
| 374 | |
| 375 | progressNum, err := strconv.Atoi(progress) |
| 376 | if err != nil { |
| 377 | Log(fmt.Sprintf("Failed to convert progress to number: %v", err), logFile) |
| 378 | ExitCurd(fmt.Errorf("Failed to convert progress to number")) |
| 379 | } |
| 380 | |
| 381 | err = UpdateAnimeProgress(user.Token, animeID, progressNum) |
| 382 | if err != nil { |
| 383 | Log(fmt.Sprintf("Failed to update anime progress: %v", err), logFile) |
| 384 | ExitCurd(fmt.Errorf("Failed to update anime progress")) |
| 385 | } |
| 386 | |
| 387 | case "SCORE": |
| 388 | currentScore := "None" |
| 389 | if selectedAnilistAnime.Score > 0 { |
| 390 | currentScore = strconv.Itoa(int(selectedAnilistAnime.Score)) |
| 391 | } |
| 392 | CurdOut(fmt.Sprintf("Current score: %s", currentScore)) |
| 393 | |
| 394 | err = RateAnime(user.Token, animeID) |
| 395 | if err != nil { |
| 396 | Log(fmt.Sprintf("Failed to update anime score: %v", err), logFile) |
| 397 | ExitCurd(fmt.Errorf("Failed to update anime score")) |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | CurdOut("Anime updated successfully!") |
| 402 | } |
| 403 | |
| 179 | 404 | func UpdateCurd(repo, fileName string) error { |
| 180 | 405 | // Get the path of the currently running executable |
| 181 | 406 | executablePath, err := os.Executable() |
| @@ -350,11 +575,13 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 350 | 575 | } else { |
| 351 | 576 | // Create category selection map |
| 352 | 577 | categories := map[string]string{ |
| 578 | "ALL": "Show All", |
| 353 | 579 | "CURRENT": "Currently Watching", |
| 354 | 580 | "PAUSED": "On Hold", |
| 355 | 581 | "PLANNING": "Plan to Watch", |
| 356 | 582 | "COMPLETED": "Completed", |
| 357 | 583 | "DROPPED": "Dropped", |
| 584 | "UPDATE": "Update Anime Entry", |
| 358 | 585 | } |
| 359 | 586 | |
| 360 | 587 | // Select category using DynamicSelect |
| @@ -368,7 +595,15 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 368 | 595 | if categorySelection.Key == "-1" { |
| 369 | 596 | ExitCurd(nil) |
| 370 | 597 | } |
| 371 | | ClearScreen() |
| 598 | |
| 599 | // Handle UPDATE option |
| 600 | if categorySelection.Key == "UPDATE" { |
| 601 | ClearScreen() |
| 602 | UpdateAnimeEntry(userCurdConfig, user, logFile) |
| 603 | ExitCurd(nil) |
| 604 | } |
| 605 | |
| 606 | ClearScreen() |
| 372 | 607 | } |
| 373 | 608 | |
| 374 | 609 | // Filter anime list based on selected category |
| @@ -739,6 +974,15 @@ func CheckAndDownloadFiles(storagePath string, filesToCheck []string) error { |
| 739 | 974 | |
| 740 | 975 | func getEntriesByCategory(list AnimeList, category string) []Entry { |
| 741 | 976 | switch category { |
| 977 | case "ALL": |
| 978 | // Combine all categories into one slice |
| 979 | allEntries := make([]Entry, 0) |
| 980 | allEntries = append(allEntries, list.Watching...) |
| 981 | allEntries = append(allEntries, list.Completed...) |
| 982 | allEntries = append(allEntries, list.Paused...) |
| 983 | allEntries = append(allEntries, list.Dropped...) |
| 984 | allEntries = append(allEntries, list.Planning...) |
| 985 | return allEntries |
| 742 | 986 | case "CURRENT": |
| 743 | 987 | return list.Watching |
| 744 | 988 | case "COMPLETED": |