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