| @@ -218,263 +218,293 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User) { |
| 218 | 218 | {Key: "SCORE", Label: "Add/Change Score"}, |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | | // Select update option |
| 222 | | updateSelection, err := DynamicSelect(updateOptions) |
| 223 | | if err != nil { |
| 224 | | Log(fmt.Sprintf("Failed to select update option: %v", err)) |
| 225 | | ExitCurd(fmt.Errorf("Failed to select update option")) |
| 226 | | } |
| 221 | // Navigation loop for update option selection |
| 222 | updateOptionLoop: |
| 223 | for { |
| 224 | // Select update option |
| 225 | updateSelection, err := DynamicSelect(updateOptions) |
| 226 | if err != nil { |
| 227 | Log(fmt.Sprintf("Failed to select update option: %v", err)) |
| 228 | ExitCurd(fmt.Errorf("Failed to select update option")) |
| 229 | } |
| 227 | 230 | |
| 228 | | if updateSelection.Key == "-1" { |
| 229 | | ExitCurd(nil) |
| 230 | | } |
| 231 | if updateSelection.Key == "-1" { |
| 232 | ExitCurd(nil) |
| 233 | } |
| 231 | 234 | |
| 232 | | // Get user's anime list |
| 233 | | var animeListOptions []SelectionOption |
| 234 | | var animeListMapPreview map[string]RofiSelectPreview |
| 235 | // Back from update selection returns to home menu |
| 236 | if updateSelection.Key == "-2" { |
| 237 | return // Return to caller (home menu) |
| 238 | } |
| 235 | 239 | |
| 236 | | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 237 | | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 238 | | // Include anime from all categories |
| 239 | | for _, entry := range user.AnimeList.Watching { |
| 240 | | title := entry.Media.Title.English |
| 241 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 242 | | title = entry.Media.Title.Romaji |
| 243 | | } |
| 244 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 245 | | Title: title, |
| 246 | | CoverImage: entry.CoverImage, |
| 240 | // Get user's anime list |
| 241 | var animeListOptions []SelectionOption |
| 242 | var animeListMapPreview map[string]RofiSelectPreview |
| 243 | |
| 244 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 245 | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 246 | // Include anime from all categories |
| 247 | for _, entry := range user.AnimeList.Watching { |
| 248 | title := entry.Media.Title.English |
| 249 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 250 | title = entry.Media.Title.Romaji |
| 251 | } |
| 252 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 253 | Title: title, |
| 254 | CoverImage: entry.CoverImage, |
| 255 | } |
| 247 | 256 | } |
| 248 | | } |
| 249 | | for _, entry := range user.AnimeList.Completed { |
| 250 | | title := entry.Media.Title.English |
| 251 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 252 | | title = entry.Media.Title.Romaji |
| 257 | for _, entry := range user.AnimeList.Completed { |
| 258 | title := entry.Media.Title.English |
| 259 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 260 | title = entry.Media.Title.Romaji |
| 261 | } |
| 262 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 263 | Title: title, |
| 264 | CoverImage: entry.CoverImage, |
| 265 | } |
| 253 | 266 | } |
| 254 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 255 | | Title: title, |
| 256 | | CoverImage: entry.CoverImage, |
| 267 | for _, entry := range user.AnimeList.Paused { |
| 268 | title := entry.Media.Title.English |
| 269 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 270 | title = entry.Media.Title.Romaji |
| 271 | } |
| 272 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 273 | Title: title, |
| 274 | CoverImage: entry.CoverImage, |
| 275 | } |
| 257 | 276 | } |
| 258 | | } |
| 259 | | for _, entry := range user.AnimeList.Paused { |
| 260 | | title := entry.Media.Title.English |
| 261 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 262 | | title = entry.Media.Title.Romaji |
| 277 | for _, entry := range user.AnimeList.Dropped { |
| 278 | title := entry.Media.Title.English |
| 279 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 280 | title = entry.Media.Title.Romaji |
| 281 | } |
| 282 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 283 | Title: title, |
| 284 | CoverImage: entry.CoverImage, |
| 285 | } |
| 263 | 286 | } |
| 264 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 265 | | Title: title, |
| 266 | | CoverImage: entry.CoverImage, |
| 287 | for _, entry := range user.AnimeList.Planning { |
| 288 | title := entry.Media.Title.English |
| 289 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 290 | title = entry.Media.Title.Romaji |
| 291 | } |
| 292 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 293 | Title: title, |
| 294 | CoverImage: entry.CoverImage, |
| 295 | } |
| 267 | 296 | } |
| 268 | | } |
| 269 | | for _, entry := range user.AnimeList.Dropped { |
| 270 | | title := entry.Media.Title.English |
| 271 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 272 | | title = entry.Media.Title.Romaji |
| 297 | for _, entry := range user.AnimeList.Rewatching { |
| 298 | title := entry.Media.Title.English |
| 299 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 300 | title = entry.Media.Title.Romaji |
| 301 | } |
| 302 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 303 | Title: title, |
| 304 | CoverImage: entry.CoverImage, |
| 305 | } |
| 273 | 306 | } |
| 274 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 275 | | Title: title, |
| 276 | | CoverImage: entry.CoverImage, |
| 307 | } else { |
| 308 | animeListOptions = make([]SelectionOption, 0) |
| 309 | // Include anime from all categories |
| 310 | for _, entry := range user.AnimeList.Watching { |
| 311 | title := entry.Media.Title.English |
| 312 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 313 | title = entry.Media.Title.Romaji |
| 314 | } |
| 315 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 316 | Key: strconv.Itoa(entry.Media.ID), |
| 317 | Label: title, |
| 318 | }) |
| 277 | 319 | } |
| 278 | | } |
| 279 | | for _, entry := range user.AnimeList.Planning { |
| 280 | | title := entry.Media.Title.English |
| 281 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 282 | | title = entry.Media.Title.Romaji |
| 320 | for _, entry := range user.AnimeList.Completed { |
| 321 | title := entry.Media.Title.English |
| 322 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 323 | title = entry.Media.Title.Romaji |
| 324 | } |
| 325 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 326 | Key: strconv.Itoa(entry.Media.ID), |
| 327 | Label: title, |
| 328 | }) |
| 283 | 329 | } |
| 284 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 285 | | Title: title, |
| 286 | | CoverImage: entry.CoverImage, |
| 330 | for _, entry := range user.AnimeList.Paused { |
| 331 | title := entry.Media.Title.English |
| 332 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 333 | title = entry.Media.Title.Romaji |
| 334 | } |
| 335 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 336 | Key: strconv.Itoa(entry.Media.ID), |
| 337 | Label: title, |
| 338 | }) |
| 287 | 339 | } |
| 288 | | } |
| 289 | | for _, entry := range user.AnimeList.Rewatching { |
| 290 | | title := entry.Media.Title.English |
| 291 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 292 | | title = entry.Media.Title.Romaji |
| 340 | for _, entry := range user.AnimeList.Dropped { |
| 341 | title := entry.Media.Title.English |
| 342 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 343 | title = entry.Media.Title.Romaji |
| 344 | } |
| 345 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 346 | Key: strconv.Itoa(entry.Media.ID), |
| 347 | Label: title, |
| 348 | }) |
| 293 | 349 | } |
| 294 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 295 | | Title: title, |
| 296 | | CoverImage: entry.CoverImage, |
| 350 | for _, entry := range user.AnimeList.Planning { |
| 351 | title := entry.Media.Title.English |
| 352 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 353 | title = entry.Media.Title.Romaji |
| 354 | } |
| 355 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 356 | Key: strconv.Itoa(entry.Media.ID), |
| 357 | Label: title, |
| 358 | }) |
| 297 | 359 | } |
| 298 | | } |
| 299 | | } else { |
| 300 | | animeListOptions = make([]SelectionOption, 0) |
| 301 | | // Include anime from all categories |
| 302 | | for _, entry := range user.AnimeList.Watching { |
| 303 | | title := entry.Media.Title.English |
| 304 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 305 | | title = entry.Media.Title.Romaji |
| 360 | for _, entry := range user.AnimeList.Rewatching { |
| 361 | title := entry.Media.Title.English |
| 362 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 363 | title = entry.Media.Title.Romaji |
| 364 | } |
| 365 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 366 | Key: strconv.Itoa(entry.Media.ID), |
| 367 | Label: title, |
| 368 | }) |
| 306 | 369 | } |
| 307 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 308 | | Key: strconv.Itoa(entry.Media.ID), |
| 309 | | Label: title, |
| 310 | | }) |
| 311 | 370 | } |
| 312 | | for _, entry := range user.AnimeList.Completed { |
| 313 | | title := entry.Media.Title.English |
| 314 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 315 | | title = entry.Media.Title.Romaji |
| 371 | |
| 372 | // Anime selection loop |
| 373 | animeSelectLoop: |
| 374 | for { |
| 375 | // Select anime to update |
| 376 | var selectedAnime SelectionOption |
| 377 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 378 | selectedAnime, err = DynamicSelectPreview(animeListMapPreview, false) |
| 379 | } else { |
| 380 | selectedAnime, err = DynamicSelect(animeListOptions) |
| 316 | 381 | } |
| 317 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 318 | | Key: strconv.Itoa(entry.Media.ID), |
| 319 | | Label: title, |
| 320 | | }) |
| 321 | | } |
| 322 | | for _, entry := range user.AnimeList.Paused { |
| 323 | | title := entry.Media.Title.English |
| 324 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 325 | | title = entry.Media.Title.Romaji |
| 382 | if err != nil { |
| 383 | Log(fmt.Sprintf("Failed to select anime: %v", err)) |
| 384 | ExitCurd(fmt.Errorf("Failed to select anime")) |
| 326 | 385 | } |
| 327 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 328 | | Key: strconv.Itoa(entry.Media.ID), |
| 329 | | Label: title, |
| 330 | | }) |
| 331 | | } |
| 332 | | for _, entry := range user.AnimeList.Dropped { |
| 333 | | title := entry.Media.Title.English |
| 334 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 335 | | title = entry.Media.Title.Romaji |
| 386 | |
| 387 | if selectedAnime.Key == "-1" { |
| 388 | ExitCurd(nil) |
| 336 | 389 | } |
| 337 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 338 | | Key: strconv.Itoa(entry.Media.ID), |
| 339 | | Label: title, |
| 340 | | }) |
| 341 | | } |
| 342 | | for _, entry := range user.AnimeList.Planning { |
| 343 | | title := entry.Media.Title.English |
| 344 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 345 | | title = entry.Media.Title.Romaji |
| 390 | |
| 391 | // Back from anime selection goes to update option selection |
| 392 | if selectedAnime.Key == "-2" { |
| 393 | ClearScreen() |
| 394 | continue updateOptionLoop |
| 346 | 395 | } |
| 347 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 348 | | Key: strconv.Itoa(entry.Media.ID), |
| 349 | | Label: title, |
| 350 | | }) |
| 351 | | } |
| 352 | | for _, entry := range user.AnimeList.Rewatching { |
| 353 | | title := entry.Media.Title.English |
| 354 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 355 | | title = entry.Media.Title.Romaji |
| 396 | |
| 397 | animeID, err := strconv.Atoi(selectedAnime.Key) |
| 398 | if err != nil { |
| 399 | Log(fmt.Sprintf("Failed to convert anime ID: %v", err)) |
| 400 | ExitCurd(fmt.Errorf("Failed to convert anime ID")) |
| 356 | 401 | } |
| 357 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 358 | | Key: strconv.Itoa(entry.Media.ID), |
| 359 | | Label: title, |
| 360 | | }) |
| 361 | | } |
| 362 | | } |
| 363 | 402 | |
| 364 | | // Select anime to update |
| 365 | | var selectedAnime SelectionOption |
| 366 | | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 367 | | selectedAnime, err = DynamicSelectPreview(animeListMapPreview, false) |
| 368 | | } else { |
| 369 | | selectedAnime, err = DynamicSelect(animeListOptions) |
| 370 | | } |
| 371 | | if err != nil { |
| 372 | | Log(fmt.Sprintf("Failed to select anime: %v", err)) |
| 373 | | ExitCurd(fmt.Errorf("Failed to select anime")) |
| 374 | | } |
| 403 | // After getting animeID, get the current anime entry |
| 404 | selectedAnilistAnime, err := FindAnimeByAnilistID(user.AnimeList, selectedAnime.Key) |
| 405 | if err != nil { |
| 406 | Log(fmt.Sprintf("Can not find the anime in anilist animelist: %v", err)) |
| 407 | ExitCurd(fmt.Errorf("Can not find the anime in anilist animelist")) |
| 408 | } |
| 409 | ClearScreen() |
| 375 | 410 | |
| 376 | | if selectedAnime.Key == "-1" { |
| 377 | | ExitCurd(nil) |
| 378 | | } |
| 411 | // Final selection loop (for category/progress/score) |
| 412 | for { |
| 413 | switch updateSelection.Key { |
| 414 | case "CATEGORY": |
| 415 | categories := []SelectionOption{ |
| 416 | {Key: "CURRENT", Label: "Currently Watching"}, |
| 417 | {Key: "COMPLETED", Label: "Completed"}, |
| 418 | {Key: "PAUSED", Label: "On Hold"}, |
| 419 | {Key: "DROPPED", Label: "Dropped"}, |
| 420 | {Key: "PLANNING", Label: "Plan to Watch"}, |
| 421 | {Key: "REPEATING", Label: "Rewatching"}, // Anilist uses REPEATING for rewatching |
| 422 | } |
| 379 | 423 | |
| 380 | | animeID, err := strconv.Atoi(selectedAnime.Key) |
| 381 | | if err != nil { |
| 382 | | Log(fmt.Sprintf("Failed to convert anime ID: %v", err)) |
| 383 | | ExitCurd(fmt.Errorf("Failed to convert anime ID")) |
| 384 | | } |
| 424 | currentStatus := "None" |
| 425 | if selectedAnilistAnime.Status != "" { |
| 426 | // Find the label for the current status |
| 427 | for _, cat := range categories { |
| 428 | if cat.Key == selectedAnilistAnime.Status { |
| 429 | currentStatus = cat.Label |
| 430 | break |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | CurdOut(fmt.Sprintf("Current category: %s", currentStatus)) |
| 385 | 435 | |
| 386 | | // After getting animeID, get the current anime entry |
| 387 | | selectedAnilistAnime, err := FindAnimeByAnilistID(user.AnimeList, selectedAnime.Key) |
| 388 | | if err != nil { |
| 389 | | Log(fmt.Sprintf("Can not find the anime in anilist animelist: %v", err)) |
| 390 | | ExitCurd(fmt.Errorf("Can not find the anime in anilist animelist")) |
| 391 | | } |
| 392 | | ClearScreen() |
| 393 | | switch updateSelection.Key { |
| 394 | | case "CATEGORY": |
| 395 | | categories := []SelectionOption{ |
| 396 | | {Key: "CURRENT", Label: "Currently Watching"}, |
| 397 | | {Key: "COMPLETED", Label: "Completed"}, |
| 398 | | {Key: "PAUSED", Label: "On Hold"}, |
| 399 | | {Key: "DROPPED", Label: "Dropped"}, |
| 400 | | {Key: "PLANNING", Label: "Plan to Watch"}, |
| 401 | | {Key: "REPEATING", Label: "Rewatching"}, // Anilist uses REPEATING for rewatching |
| 402 | | } |
| 436 | categorySelection, err := DynamicSelect(categories) |
| 437 | if err != nil { |
| 438 | Log(fmt.Sprintf("Failed to select category: %v", err)) |
| 439 | ExitCurd(fmt.Errorf("Failed to select category")) |
| 440 | } |
| 403 | 441 | |
| 404 | | currentStatus := "None" |
| 405 | | if selectedAnilistAnime.Status != "" { |
| 406 | | // Find the label for the current status |
| 407 | | for _, cat := range categories { |
| 408 | | if cat.Key == selectedAnilistAnime.Status { |
| 409 | | currentStatus = cat.Label |
| 410 | | break |
| 411 | | } |
| 412 | | } |
| 413 | | } |
| 414 | | CurdOut(fmt.Sprintf("Current category: %s", currentStatus)) |
| 442 | if categorySelection.Key == "-1" { |
| 443 | ExitCurd(nil) |
| 444 | } |
| 415 | 445 | |
| 416 | | categorySelection, err := DynamicSelect(categories) |
| 417 | | if err != nil { |
| 418 | | Log(fmt.Sprintf("Failed to select category: %v", err)) |
| 419 | | ExitCurd(fmt.Errorf("Failed to select category")) |
| 420 | | } |
| 446 | // Back from category selection goes to anime selection |
| 447 | if categorySelection.Key == "-2" { |
| 448 | ClearScreen() |
| 449 | continue animeSelectLoop |
| 450 | } |
| 421 | 451 | |
| 422 | | if categorySelection.Key == "-1" { |
| 423 | | ExitCurd(nil) |
| 424 | | } |
| 452 | err = UpdateAnimeStatus(user.Token, animeID, categorySelection.Key) |
| 453 | if err != nil { |
| 454 | Log(fmt.Sprintf("Failed to update anime status: %v", err)) |
| 455 | ExitCurd(fmt.Errorf("Failed to update anime status")) |
| 456 | } |
| 425 | 457 | |
| 426 | | err = UpdateAnimeStatus(user.Token, animeID, categorySelection.Key) |
| 427 | | if err != nil { |
| 428 | | Log(fmt.Sprintf("Failed to update anime status: %v", err)) |
| 429 | | ExitCurd(fmt.Errorf("Failed to update anime status")) |
| 430 | | } |
| 458 | case "PROGRESS": |
| 459 | currentProgress := "None" |
| 460 | if selectedAnilistAnime.Progress > 0 { |
| 461 | currentProgress = strconv.Itoa(selectedAnilistAnime.Progress) |
| 462 | } |
| 431 | 463 | |
| 432 | | case "PROGRESS": |
| 433 | | currentProgress := "None" |
| 434 | | if selectedAnilistAnime.Progress > 0 { |
| 435 | | currentProgress = strconv.Itoa(selectedAnilistAnime.Progress) |
| 436 | | } |
| 464 | var progress string |
| 465 | if userCurdConfig.RofiSelection { |
| 466 | progress, err = GetUserInputFromRofi(fmt.Sprintf("Current progress: %s\nEnter new progress (episode number)", currentProgress)) |
| 467 | if err != nil { |
| 468 | Log(fmt.Sprintf("Failed to get progress input: %v", err)) |
| 469 | ExitCurd(fmt.Errorf("Failed to get progress input")) |
| 470 | } |
| 471 | } else { |
| 472 | CurdOut(fmt.Sprintf("Current progress: %s", currentProgress)) |
| 473 | CurdOut("Enter new progress (episode number):") |
| 474 | fmt.Scanln(&progress) |
| 475 | } |
| 437 | 476 | |
| 438 | | var progress string |
| 439 | | if userCurdConfig.RofiSelection { |
| 440 | | progress, err = GetUserInputFromRofi(fmt.Sprintf("Current progress: %s\nEnter new progress (episode number)", currentProgress)) |
| 441 | | if err != nil { |
| 442 | | Log(fmt.Sprintf("Failed to get progress input: %v", err)) |
| 443 | | ExitCurd(fmt.Errorf("Failed to get progress input")) |
| 444 | | } |
| 445 | | } else { |
| 446 | | CurdOut(fmt.Sprintf("Current progress: %s", currentProgress)) |
| 447 | | CurdOut("Enter new progress (episode number):") |
| 448 | | fmt.Scanln(&progress) |
| 449 | | } |
| 477 | progressNum, err := strconv.Atoi(progress) |
| 478 | if err != nil { |
| 479 | Log(fmt.Sprintf("Failed to convert progress to number: %v", err)) |
| 480 | ExitCurd(fmt.Errorf("Failed to convert progress to number")) |
| 481 | } |
| 450 | 482 | |
| 451 | | progressNum, err := strconv.Atoi(progress) |
| 452 | | if err != nil { |
| 453 | | Log(fmt.Sprintf("Failed to convert progress to number: %v", err)) |
| 454 | | ExitCurd(fmt.Errorf("Failed to convert progress to number")) |
| 455 | | } |
| 483 | err = UpdateAnimeProgress(user.Token, animeID, progressNum) |
| 484 | if err != nil { |
| 485 | Log(fmt.Sprintf("Failed to update anime progress: %v", err)) |
| 486 | ExitCurd(fmt.Errorf("Failed to update anime progress")) |
| 487 | } |
| 456 | 488 | |
| 457 | | err = UpdateAnimeProgress(user.Token, animeID, progressNum) |
| 458 | | if err != nil { |
| 459 | | Log(fmt.Sprintf("Failed to update anime progress: %v", err)) |
| 460 | | ExitCurd(fmt.Errorf("Failed to update anime progress")) |
| 461 | | } |
| 489 | case "SCORE": |
| 490 | currentScore := "None" |
| 491 | if selectedAnilistAnime.Score > 0 { |
| 492 | currentScore = strconv.Itoa(int(selectedAnilistAnime.Score)) |
| 493 | } |
| 494 | CurdOut(fmt.Sprintf("Current score: %s", currentScore)) |
| 462 | 495 | |
| 463 | | case "SCORE": |
| 464 | | currentScore := "None" |
| 465 | | if selectedAnilistAnime.Score > 0 { |
| 466 | | currentScore = strconv.Itoa(int(selectedAnilistAnime.Score)) |
| 467 | | } |
| 468 | | CurdOut(fmt.Sprintf("Current score: %s", currentScore)) |
| 496 | err = RateAnime(user.Token, animeID) |
| 497 | if err != nil { |
| 498 | Log(fmt.Sprintf("Failed to update anime score: %v", err)) |
| 499 | ExitCurd(fmt.Errorf("Failed to update anime score")) |
| 500 | } |
| 501 | } |
| 469 | 502 | |
| 470 | | err = RateAnime(user.Token, animeID) |
| 471 | | if err != nil { |
| 472 | | Log(fmt.Sprintf("Failed to update anime score: %v", err)) |
| 473 | | ExitCurd(fmt.Errorf("Failed to update anime score")) |
| 503 | CurdOut("Anime updated successfully!") |
| 504 | return |
| 505 | } |
| 474 | 506 | } |
| 475 | 507 | } |
| 476 | | |
| 477 | | CurdOut("Anime updated successfully!") |
| 478 | 508 | } |
| 479 | 509 | |
| 480 | 510 | func UpdateCurd(repo, fileName string) error { |
| @@ -714,6 +744,12 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 714 | 744 | user.AnimeList = ParseAnimeList(anilistUserData) |
| 715 | 745 | } |
| 716 | 746 | |
| 747 | // Variables for selection results (used in both branches and after) |
| 748 | var anilistSelectedOption SelectionOption |
| 749 | var selectedAllanimeAnime SelectionOption |
| 750 | var userQuery string |
| 751 | _ = selectedAllanimeAnime // Used later in the function |
| 752 | |
| 717 | 753 | // If continueLast flag is set, directly get the last watched anime |
| 718 | 754 | if anime.Ep.ContinueLast { |
| 719 | 755 | // Get the last anime ID from the curd_id file |
| @@ -738,6 +774,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 738 | 774 | |
| 739 | 775 | // Set the anime details |
| 740 | 776 | anime.AnilistId = animePointer.AnilistId |
| 777 | anilistSelectedOption.Key = strconv.Itoa(animePointer.AnilistId) |
| 741 | 778 | // anime.AllanimeId = animePointer.AllanimeId |
| 742 | 779 | // anime.Title = animePointer.Title |
| 743 | 780 | // anime.Ep.Number = animePointer.Ep.Number |
| @@ -745,126 +782,157 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni |
| 745 | 782 | // anime.Ep.Resume = true |
| 746 | 783 | |
| 747 | 784 | } else { |
| 748 | | // Skip category selection if Current flag is set |
| 749 | | var categorySelection SelectionOption |
| 750 | | if userCurdConfig.CurrentCategory { |
| 751 | | categorySelection = SelectionOption{ |
| 752 | | Key: "CURRENT", |
| 753 | | Label: "Currently Watching", |
| 754 | | } |
| 755 | | } else { |
| 756 | | // Create category selection map |
| 757 | | // Get ordered categories |
| 758 | | orderedCategories := getOrderedCategories(userCurdConfig) |
| 785 | // Navigation loop for category and anime selection |
| 786 | categorySelectionLoop: |
| 787 | for { |
| 788 | // Skip category selection if Current flag is set |
| 789 | var categorySelection SelectionOption |
| 790 | if userCurdConfig.CurrentCategory { |
| 791 | categorySelection = SelectionOption{ |
| 792 | Key: "CURRENT", |
| 793 | Label: "Currently Watching", |
| 794 | } |
| 795 | } else { |
| 796 | // Create category selection map |
| 797 | // Get ordered categories |
| 798 | orderedCategories := getOrderedCategories(userCurdConfig) |
| 759 | 799 | |
| 760 | | // Use DynamicSelect with ordered categories directly |
| 761 | | categorySelection, err = DynamicSelect(orderedCategories) |
| 800 | // Use DynamicSelect with ordered categories directly |
| 801 | categorySelection, err = DynamicSelect(orderedCategories) |
| 762 | 802 | |
| 763 | | if err != nil { |
| 764 | | Log(fmt.Sprintf("Failed to select category: %v", err)) |
| 765 | | ExitCurd(fmt.Errorf("Failed to select category")) |
| 766 | | } |
| 803 | if err != nil { |
| 804 | Log(fmt.Sprintf("Failed to select category: %v", err)) |
| 805 | ExitCurd(fmt.Errorf("Failed to select category")) |
| 806 | } |
| 767 | 807 | |
| 768 | | if categorySelection.Key == "-1" { |
| 769 | | ExitCurd(nil) |
| 770 | | } |
| 808 | if categorySelection.Key == "-1" { |
| 809 | ExitCurd(nil) |
| 810 | } |
| 811 | |
| 812 | // Handle options |
| 813 | if categorySelection.Key == "UPDATE" { |
| 814 | ClearScreen() |
| 815 | UpdateAnimeEntry(userCurdConfig, user) |
| 816 | // If UpdateAnimeEntry returns, user pressed back - continue to category selection |
| 817 | ClearScreen() |
| 818 | continue categorySelectionLoop |
| 819 | } else if categorySelection.Key == "UNTRACKED" { |
| 820 | ClearScreen() |
| 821 | WatchUntracked(userCurdConfig) |
| 822 | // If WatchUntracked returns, user pressed back OR watched is done- continue to category selection |
| 823 | ClearScreen() |
| 824 | continue categorySelectionLoop |
| 825 | } else if categorySelection.Key == "CONTINUE_LAST" { |
| 826 | anime.Ep.ContinueLast = true |
| 827 | } |
| 771 | 828 | |
| 772 | | // Handle options |
| 773 | | if categorySelection.Key == "UPDATE" { |
| 774 | | ClearScreen() |
| 775 | | UpdateAnimeEntry(userCurdConfig, user) |
| 776 | | ExitCurd(nil) |
| 777 | | } else if categorySelection.Key == "UNTRACKED" { |
| 778 | 829 | ClearScreen() |
| 779 | | WatchUntracked(userCurdConfig) |
| 780 | | } else if categorySelection.Key == "CONTINUE_LAST" { |
| 781 | | anime.Ep.ContinueLast = true |
| 782 | 830 | } |
| 783 | 831 | |
| 784 | | ClearScreen() |
| 785 | | } |
| 786 | | |
| 787 | | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 788 | | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 789 | | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 790 | | title := entry.Media.Title.English |
| 791 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 792 | | title = entry.Media.Title.Romaji |
| 793 | | } |
| 794 | | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 795 | | Title: title, |
| 796 | | CoverImage: entry.CoverImage, |
| 832 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 833 | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 834 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 835 | title := entry.Media.Title.English |
| 836 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 837 | title = entry.Media.Title.Romaji |
| 838 | } |
| 839 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 840 | Title: title, |
| 841 | CoverImage: entry.CoverImage, |
| 842 | } |
| 797 | 843 | } |
| 798 | | } |
| 799 | | } else { |
| 800 | | animeListOptions = make([]SelectionOption, 0) |
| 801 | | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 802 | | title := entry.Media.Title.English |
| 803 | | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 804 | | title = entry.Media.Title.Romaji |
| 844 | } else { |
| 845 | animeListOptions = make([]SelectionOption, 0) |
| 846 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 847 | title := entry.Media.Title.English |
| 848 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 849 | title = entry.Media.Title.Romaji |
| 850 | } |
| 851 | animeListOptions = append(animeListOptions, SelectionOption{ |
| 852 | Key: strconv.Itoa(entry.Media.ID), |
| 853 | Label: title, |
| 854 | }) |
| 805 | 855 | } |
| 806 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 807 | | Key: strconv.Itoa(entry.Media.ID), |
| 808 | | Label: title, |
| 809 | | }) |
| 810 | 856 | } |
| 811 | | } |
| 812 | | } |
| 813 | 857 | |
| 814 | | var anilistSelectedOption SelectionOption |
| 815 | | var selectedAllanimeAnime SelectionOption |
| 816 | | var userQuery string |
| 858 | // Anime selection loop (for back navigation) |
| 859 | animeSelectionLoop: |
| 860 | for { |
| 861 | if anime.Ep.ContinueLast { |
| 862 | // Get the last watched anime ID from the curd_id file |
| 863 | curdIDPath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_id") |
| 864 | curdIDBytes, err := os.ReadFile(curdIDPath) |
| 865 | if err != nil { |
| 866 | Log(fmt.Sprintf("Error reading curd_id file: %v", err)) |
| 867 | ExitCurd(fmt.Errorf("Error reading curd_id file")) |
| 868 | } |
| 817 | 869 | |
| 818 | | if anime.Ep.ContinueLast { |
| 819 | | // Get the last watched anime ID from the curd_id file |
| 820 | | curdIDPath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_id") |
| 821 | | curdIDBytes, err := os.ReadFile(curdIDPath) |
| 822 | | if err != nil { |
| 823 | | Log(fmt.Sprintf("Error reading curd_id file: %v", err)) |
| 824 | | ExitCurd(fmt.Errorf("Error reading curd_id file")) |
| 825 | | } |
| 870 | lastWatchedID, err := strconv.Atoi(strings.TrimSpace(string(curdIDBytes))) |
| 871 | if err != nil { |
| 872 | Log(fmt.Sprintf("Error converting curd_id to integer: %v", err)) |
| 873 | ExitCurd(fmt.Errorf("Error converting curd_id to integer")) |
| 874 | } |
| 826 | 875 | |
| 827 | | lastWatchedID, err := strconv.Atoi(strings.TrimSpace(string(curdIDBytes))) |
| 828 | | if err != nil { |
| 829 | | Log(fmt.Sprintf("Error converting curd_id to integer: %v", err)) |
| 830 | | ExitCurd(fmt.Errorf("Error converting curd_id to integer")) |
| 831 | | } |
| 876 | anime.AnilistId = lastWatchedID |
| 877 | anilistSelectedOption.Key = strconv.Itoa(lastWatchedID) |
| 878 | break categorySelectionLoop |
| 879 | } |
| 832 | 880 | |
| 833 | | anime.AnilistId = lastWatchedID |
| 834 | | anilistSelectedOption.Key = strconv.Itoa(lastWatchedID) |
| 835 | | } else { |
| 836 | | // Select anime to watch (Anilist) |
| 837 | | var err error |
| 838 | | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 839 | | anilistSelectedOption, err = DynamicSelectPreview(animeListMapPreview, true) |
| 840 | | } else { |
| 841 | | // Add "Add new anime" option to the slice |
| 842 | | animeListOptions = append(animeListOptions, SelectionOption{ |
| 843 | | Key: "add_new", |
| 844 | | Label: "Add new anime", |
| 845 | | }) |
| 881 | // Select anime to watch (Anilist) |
| 882 | var err error |
| 883 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 884 | anilistSelectedOption, err = DynamicSelectPreview(animeListMapPreview, true) |
| 885 | } else { |
| 886 | // Add "Add new anime" option to the slice |
| 887 | tempOptions := make([]SelectionOption, len(animeListOptions)) |
| 888 | copy(tempOptions, animeListOptions) |
| 889 | tempOptions = append(tempOptions, SelectionOption{ |
| 890 | Key: "add_new", |
| 891 | Label: "Add new anime", |
| 892 | }) |
| 893 | |
| 894 | anilistSelectedOption, err = DynamicSelect(tempOptions) |
| 895 | } |
| 896 | if err != nil { |
| 897 | Log(fmt.Sprintf("Error selecting anime: %v", err)) |
| 898 | ExitCurd(fmt.Errorf("Error selecting anime")) |
| 899 | } |
| 846 | 900 | |
| 847 | | anilistSelectedOption, err = DynamicSelect(animeListOptions) |
| 848 | | } |
| 849 | | if err != nil { |
| 850 | | Log(fmt.Sprintf("Error selecting anime: %v", err)) |
| 851 | | ExitCurd(fmt.Errorf("Error selecting anime")) |
| 852 | | } |
| 901 | Log(anilistSelectedOption) |
| 853 | 902 | |
| 854 | | Log(anilistSelectedOption) |
| 903 | if anilistSelectedOption.Key == "-1" { |
| 904 | ExitCurd(nil) |
| 905 | } |
| 855 | 906 | |
| 856 | | if anilistSelectedOption.Key == "-1" { |
| 857 | | ExitCurd(nil) |
| 858 | | } |
| 907 | // Handle back navigation - go back to category selection |
| 908 | if anilistSelectedOption.Key == "-2" { |
| 909 | if userCurdConfig.CurrentCategory { |
| 910 | // If CurrentCategory is forced, back means quit |
| 911 | ExitCurd(nil) |
| 912 | } |
| 913 | ClearScreen() |
| 914 | continue categorySelectionLoop |
| 915 | } |
| 859 | 916 | |
| 860 | | if anilistSelectedOption.Label == "add_new" || anilistSelectedOption.Key == "add_new" { |
| 861 | | anilistSelectedOption = AddNewAnime(userCurdConfig, anime, user, databaseAnimes) |
| 862 | | } |
| 917 | if anilistSelectedOption.Label == "add_new" || anilistSelectedOption.Key == "add_new" { |
| 918 | addResult := AddNewAnime(userCurdConfig, anime, user, databaseAnimes) |
| 919 | if addResult.Key == "-2" { |
| 920 | // Back from add new anime goes to anime selection |
| 921 | ClearScreen() |
| 922 | continue animeSelectionLoop |
| 923 | } |
| 924 | anilistSelectedOption = addResult |
| 925 | } |
| 863 | 926 | |
| 864 | | anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key) |
| 865 | | if err != nil { |
| 866 | | Log(fmt.Sprintf("Error converting Anilist ID: %v", err)) |
| 867 | | ExitCurd(fmt.Errorf("Error converting Anilist ID")) |
| 927 | anime.AnilistId, err = strconv.Atoi(anilistSelectedOption.Key) |
| 928 | if err != nil { |
| 929 | Log(fmt.Sprintf("Error converting Anilist ID: %v", err)) |
| 930 | ExitCurd(fmt.Errorf("Error converting Anilist ID")) |
| 931 | } |
| 932 | |
| 933 | // Successfully selected anime, break out of both loops |
| 934 | break categorySelectionLoop |
| 935 | } |
| 868 | 936 | } |
| 869 | 937 | } |
| 870 | 938 | // Find anime in Local history |
| @@ -1579,3 +1647,4 @@ func HandleLastEpisodeCompletion(userCurdConfig *CurdConfig, anime *Anime, userT |
| 1579 | 1647 | } |
| 1580 | 1648 | } |
| 1581 | 1649 | } |
| 1650 | |