Commit 53899cc4c9
Unsigned
Layout: unified · split
cmd/curd/main.go +10 −6
| @@ -222,6 +222,9 @@ func main() { | |||
| 222 | 222 | ||
| 223 | // If not filler/recap (or skip is disabled), break and continue with playback | 223 | // If not filler/recap (or skip is disabled), break and continue with playback |
| 224 | if !((anime.Ep.IsFiller && userCurdConfig.SkipFiller) || (anime.Ep.IsRecap && userCurdConfig.SkipRecap)) { | 224 | if !((anime.Ep.IsFiller && userCurdConfig.SkipFiller) || (anime.Ep.IsRecap && userCurdConfig.SkipRecap)) { |
| 225 | if anime.Ep.LastWasSkipped { | ||
| 226 | go internal.UpdateAnimeProgress(user.Token, anime.AnilistId, anime.Ep.Number-1) | ||
| 227 | } | ||
| 225 | break | 228 | break |
| 226 | } | 229 | } |
| 227 | 230 | ||
| @@ -231,11 +234,12 @@ func main() { | |||
| 231 | } else { | 234 | } else { |
| 232 | internal.CurdOut(fmt.Sprint("Recap episode, skipping: ", anime.Ep.Number)) | 235 | internal.CurdOut(fmt.Sprint("Recap episode, skipping: ", anime.Ep.Number)) |
| 233 | } | 236 | } |
| 234 | 237 | ||
| 235 | anime.Ep.Number++ | 238 | anime.Ep.Number++ |
| 239 | anime.Ep.LastWasSkipped = true | ||
| 236 | anime.Ep.Started = false | 240 | anime.Ep.Started = false |
| 237 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, 0, 0, internal.GetAnimeName(anime)) | 241 | internal.LocalUpdateAnime(databaseFile, anime.AnilistId, anime.AllanimeId, anime.Ep.Number, 0, 0, internal.GetAnimeName(anime)) |
| 238 | 242 | ||
| 239 | // Check if we've reached the end of the series | 243 | // Check if we've reached the end of the series |
| 240 | if anime.Ep.Number > anime.TotalEpisodes { | 244 | if anime.Ep.Number > anime.TotalEpisodes { |
| 241 | internal.CurdOut("Reached end of series") | 245 | internal.CurdOut("Reached end of series") |
| @@ -447,9 +451,8 @@ func main() { | |||
| 447 | } | 451 | } |
| 448 | } | 452 | } |
| 449 | _, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"}) | 453 | _, err := internal.MPVSendCommand(anime.Ep.Player.SocketPath, []interface{}{"get_property", "time-pos"}) |
| 450 | if err == nil && anime.Ep.Started{ | 454 | if err == nil && anime.Ep.Started { |
| 451 | anime.Ep.Player.Speed, err = internal.GetMPVPlaybackSpeed(anime.Ep.Player.SocketPath) | 455 | anime.Ep.Player.Speed, err = internal.GetMPVPlaybackSpeed(anime.Ep.Player.SocketPath) |
| 452 | internal.Log(anime.Ep.Player.Speed, logFile) | ||
| 453 | if err != nil { | 456 | if err != nil { |
| 454 | internal.Log("Failed to get mpv speed "+err.Error(), logFile) | 457 | internal.Log("Failed to get mpv speed "+err.Error(), logFile) |
| 455 | } | 458 | } |
| @@ -466,6 +469,7 @@ func main() { | |||
| 466 | wg = sync.WaitGroup{} | 469 | wg = sync.WaitGroup{} |
| 467 | 470 | ||
| 468 | if anime.Ep.IsCompleted && !anime.Rewatching { | 471 | if anime.Ep.IsCompleted && !anime.Rewatching { |
| 472 | // Update progress for both regular episodes and skipped fillers | ||
| 469 | go func() { | 473 | go func() { |
| 470 | err = internal.UpdateAnimeProgress(user.Token, anime.AnilistId, anime.Ep.Number-1) | 474 | err = internal.UpdateAnimeProgress(user.Token, anime.AnilistId, anime.Ep.Number-1) |
| 471 | if err != nil { | 475 | if err != nil { |
| @@ -481,7 +485,7 @@ func main() { | |||
| 481 | err = internal.RateAnime(user.Token, anime.AnilistId) | 485 | err = internal.RateAnime(user.Token, anime.AnilistId) |
| 482 | if err != nil { | 486 | if err != nil { |
| 483 | internal.Log("Error rating anime: "+err.Error(), logFile) | 487 | internal.Log("Error rating anime: "+err.Error(), logFile) |
| 484 | internal.CurdOut("Error rating anime: "+err.Error()) | 488 | internal.CurdOut("Error rating anime: " + err.Error()) |
| 485 | } | 489 | } |
| 486 | internal.LocalDeleteAnime(databaseFile, anime.AnilistId, anime.AllanimeId) | 490 | internal.LocalDeleteAnime(databaseFile, anime.AnilistId, anime.AllanimeId) |
| 487 | internal.ExitCurd(nil) | 491 | internal.ExitCurd(nil) |
| @@ -499,7 +503,7 @@ func main() { | |||
| 499 | "yes": "Yes", | 503 | "yes": "Yes", |
| 500 | "no": "No", | 504 | "no": "No", |
| 501 | } | 505 | } |
| 502 | 506 | ||
| 503 | selectedOption, err := internal.DynamicSelect(options, false) | 507 | selectedOption, err := internal.DynamicSelect(options, false) |
| 504 | if err != nil { | 508 | if err != nil { |
| 505 | internal.ExitCurd(err) | 509 | internal.ExitCurd(err) |
internal/curd.go +97 −63
| @@ -555,6 +555,11 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | |||
| 555 | var anilistUserData map[string]interface{} | 555 | var anilistUserData map[string]interface{} |
| 556 | var anilistUserDataPreview map[string]interface{} | 556 | var anilistUserDataPreview map[string]interface{} |
| 557 | 557 | ||
| 558 | // Filter anime list based on selected category | ||
| 559 | var animeListMap map[string]string | ||
| 560 | var animeListMapPreview map[string]RofiSelectPreview | ||
| 561 | |||
| 562 | |||
| 558 | // Get user id, username and Anime list | 563 | // Get user id, username and Anime list |
| 559 | user.Id, user.Username, err = GetAnilistUserID(user.Token) | 564 | user.Id, user.Username, err = GetAnilistUserID(user.Token) |
| 560 | if err != nil { | 565 | if err != nil { |
| @@ -579,77 +584,106 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni | |||
| 579 | user.AnimeList = ParseAnimeList(anilistUserData) | 584 | user.AnimeList = ParseAnimeList(anilistUserData) |
| 580 | } | 585 | } |
| 581 | 586 | ||
| 582 | // Skip category selection if Current flag is set | 587 | // If continueLast flag is set, directly get the last watched anime |
| 583 | var categorySelection SelectionOption | 588 | if anime.Ep.ContinueLast { |
| 584 | if userCurdConfig.CurrentCategory { | 589 | // Get the last anime ID from the curd_id file |
| 585 | categorySelection = SelectionOption{ | 590 | idFilePath := filepath.Join(os.ExpandEnv(userCurdConfig.StoragePath), "curd_id") |
| 586 | Key: "CURRENT", | 591 | idBytes, err := os.ReadFile(idFilePath) |
| 587 | Label: "Currently Watching", | 592 | if err != nil { |
| 588 | } | 593 | Log("Error reading curd_id file: "+err.Error(), logFile) |
| 589 | } else { | 594 | ExitCurd(fmt.Errorf("No last watched anime found")) |
| 590 | // Create category selection map | ||
| 591 | categories := map[string]string{ | ||
| 592 | "ALL": "Show All", | ||
| 593 | "CURRENT": "Currently Watching", | ||
| 594 | "PAUSED": "On Hold", | ||
| 595 | "PLANNING": "Plan to Watch", | ||
| 596 | "COMPLETED": "Completed", | ||
| 597 | "DROPPED": "Dropped", | ||
| 598 | "UPDATE": "Update Anime Entry", | ||
| 599 | "UNTRACKED": "Untracked Watching", | ||
| 600 | } | 595 | } |
| 601 | 596 | ||
| 602 | // Select category using DynamicSelect | 597 | anilistID, err := strconv.Atoi(string(idBytes)) |
| 603 | var err error | ||
| 604 | categorySelection, err = DynamicSelect(categories, false) | ||
| 605 | if err != nil { | 598 | if err != nil { |
| 606 | Log(fmt.Sprintf("Failed to select category: %v", err), logFile) | 599 | Log("Error converting anilist ID: "+err.Error(), logFile) |
| 607 | ExitCurd(fmt.Errorf("Failed to select category")) | 600 | ExitCurd(fmt.Errorf("Invalid anime ID in curd_id file")) |
| 608 | } | 601 | } |
| 609 | 602 | ||
| 610 | if categorySelection.Key == "-1" { | 603 | // Find the anime in database |
| 611 | ExitCurd(nil) | 604 | animePointer := LocalFindAnime(*databaseAnimes, anilistID, "") |
| 605 | if animePointer == nil { | ||
| 606 | ExitCurd(fmt.Errorf("Last watched anime not found in database")) | ||
| 612 | } | 607 | } |
| 613 | 608 | ||
| 614 | // Handle UPDATE option | 609 | // Set the anime details |
| 615 | if categorySelection.Key == "UPDATE" { | 610 | anime.AnilistId = animePointer.AnilistId |
| 616 | ClearScreen() | 611 | // anime.AllanimeId = animePointer.AllanimeId |
| 617 | UpdateAnimeEntry(userCurdConfig, user, logFile) | 612 | // anime.Title = animePointer.Title |
| 618 | ExitCurd(nil) | 613 | // anime.Ep.Number = animePointer.Ep.Number |
| 619 | } else if categorySelection.Key == "UNTRACKED" { | 614 | // anime.Ep.Player.PlaybackTime = animePointer.Ep.Player.PlaybackTime |
| 620 | ClearScreen() | 615 | // anime.Ep.Resume = true |
| 621 | WatchUntracked(userCurdConfig, logFile) | 616 | |
| 622 | } | 617 | } else { |
| 618 | // Skip category selection if Current flag is set | ||
| 619 | var categorySelection SelectionOption | ||
| 620 | if userCurdConfig.CurrentCategory { | ||
| 621 | categorySelection = SelectionOption{ | ||
| 622 | Key: "CURRENT", | ||
| 623 | Label: "Currently Watching", | ||
| 624 | } | ||
| 625 | } else { | ||
| 626 | // Create category selection map | ||
| 627 | categories := map[string]string{ | ||
| 628 | "ALL": "Show All", | ||
| 629 | "CURRENT": "Currently Watching", | ||
| 630 | "PAUSED": "On Hold", | ||
| 631 | "PLANNING": "Plan to Watch", | ||
| 632 | "COMPLETED": "Completed", | ||
| 633 | "DROPPED": "Dropped", | ||
| 634 | "UPDATE": "Update Anime Entry", | ||
| 635 | "UNTRACKED": "Untracked Watching", | ||
| 636 | } | ||
| 623 | 637 | ||
| 624 | ClearScreen() | 638 | // Select category using DynamicSelect |
| 625 | } | 639 | var err error |
| 640 | categorySelection, err = DynamicSelect(categories, false) | ||
| 641 | if err != nil { | ||
| 642 | Log(fmt.Sprintf("Failed to select category: %v", err), logFile) | ||
| 643 | ExitCurd(fmt.Errorf("Failed to select category")) | ||
| 644 | } | ||
| 626 | 645 | ||
| 627 | // Filter anime list based on selected category | 646 | if categorySelection.Key == "-1" { |
| 628 | var animeListMap map[string]string | 647 | ExitCurd(nil) |
| 629 | var animeListMapPreview map[string]RofiSelectPreview | 648 | } |
| 630 | 649 | ||
| 631 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { | 650 | // Handle UPDATE option |
| 632 | animeListMapPreview = make(map[string]RofiSelectPreview) | 651 | if categorySelection.Key == "UPDATE" { |
| 633 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { | 652 | ClearScreen() |
| 634 | title := entry.Media.Title.English | 653 | UpdateAnimeEntry(userCurdConfig, user, logFile) |
| 635 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { | 654 | ExitCurd(nil) |
| 636 | title = entry.Media.Title.Romaji | 655 | } else if categorySelection.Key == "UNTRACKED" { |
| 637 | } | 656 | ClearScreen() |
| 638 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ | 657 | WatchUntracked(userCurdConfig, logFile) |
| 639 | Title: title, | 658 | } |
| 640 | CoverImage: entry.CoverImage, | 659 | |
| 641 | } | 660 | ClearScreen() |
| 642 | } | 661 | } |
| 643 | } else { | 662 | |
| 644 | animeListMap = make(map[string]string) | 663 | |
| 645 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { | 664 | if userCurdConfig.RofiSelection && userCurdConfig.ImagePreview { |
| 646 | title := entry.Media.Title.English | 665 | animeListMapPreview = make(map[string]RofiSelectPreview) |
| 647 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { | 666 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { |
| 648 | title = entry.Media.Title.Romaji | 667 | title := entry.Media.Title.English |
| 649 | } | 668 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { |
| 650 | animeListMap[strconv.Itoa(entry.Media.ID)] = title | 669 | title = entry.Media.Title.Romaji |
| 651 | } | 670 | } |
| 652 | } | 671 | animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 672 | Title: title, | ||
| 673 | CoverImage: entry.CoverImage, | ||
| 674 | } | ||
| 675 | } | ||
| 676 | } else { | ||
| 677 | animeListMap = make(map[string]string) | ||
| 678 | for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { | ||
| 679 | title := entry.Media.Title.English | ||
| 680 | if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { | ||
| 681 | title = entry.Media.Title.Romaji | ||
| 682 | } | ||
| 683 | animeListMap[strconv.Itoa(entry.Media.ID)] = title | ||
| 684 | } | ||
| 685 | } | ||
| 686 | } | ||
| 653 | 687 | ||
| 654 | var anilistSelectedOption SelectionOption | 688 | var anilistSelectedOption SelectionOption |
| 655 | var selectedAllanimeAnime SelectionOption | 689 | var selectedAllanimeAnime SelectionOption |
internal/structs.go +41 −40
| @@ -8,13 +8,13 @@ type AnimeTitle struct { | |||
| 8 | 8 | ||
| 9 | type Anime struct { | 9 | type Anime struct { |
| 10 | Title AnimeTitle `json:"title"` | 10 | Title AnimeTitle `json:"title"` |
| 11 | Ep Episode `json:"ep"` | 11 | Ep Episode `json:"ep"` |
| 12 | CoverImage string `json:"url"` // Assuming this field corresponds to the cover image URL | 12 | CoverImage string `json:"url"` // Assuming this field corresponds to the cover image URL |
| 13 | TotalEpisodes int `json:"total_episodes"` // If provided by the API | 13 | TotalEpisodes int `json:"total_episodes"` // If provided by the API |
| 14 | MalId int `json:"mal_id"` | 14 | MalId int `json:"mal_id"` |
| 15 | AnilistId int `json:"anilist_id"` // Assuming you have an Anilist ID in your struct | 15 | AnilistId int `json:"anilist_id"` // Assuming you have an Anilist ID in your struct |
| 16 | Rewatching bool | 16 | Rewatching bool |
| 17 | AllanimeId string // Can be populated as necessary | 17 | AllanimeId string // Can be populated as necessary |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | type Skip struct { | 20 | type Skip struct { |
| @@ -28,34 +28,35 @@ type SkipTimes struct { | |||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | type Episode struct { | 30 | type Episode struct { |
| 31 | Title AnimeTitle `json:"title"` | 31 | Title AnimeTitle `json:"title"` |
| 32 | Number int `json:"number"` | 32 | Number int `json:"number"` |
| 33 | SkipTimes SkipTimes `json:"skip_times"` | 33 | SkipTimes SkipTimes `json:"skip_times"` |
| 34 | Player playingVideo `json:"player"` | 34 | Player playingVideo `json:"player"` |
| 35 | Resume bool `json:"resume"` | 35 | Resume bool `json:"resume"` |
| 36 | Started bool `json:"started"` | 36 | Started bool `json:"started"` |
| 37 | Duration int `json:"duration"` | 37 | Duration int `json:"duration"` |
| 38 | Links []string `json:"links"` | 38 | Links []string `json:"links"` |
| 39 | IsFiller bool `json:"filler"` | 39 | IsFiller bool `json:"filler"` |
| 40 | IsRecap bool `json:"recap"` | 40 | IsRecap bool `json:"recap"` |
| 41 | Aired string `json:"aired"` | 41 | Aired string `json:"aired"` |
| 42 | Synopsis string `json:"synopsis"` | 42 | Synopsis string `json:"synopsis"` |
| 43 | ContinueLast bool | 43 | ContinueLast bool |
| 44 | IsCompleted bool | 44 | LastWasSkipped bool // used in filler check |
| 45 | IsCompleted bool | ||
| 45 | } | 46 | } |
| 46 | 47 | ||
| 47 | type playingVideo struct { | 48 | type playingVideo struct { |
| 48 | Url string | 49 | Url string |
| 49 | Speed float64 `json:"speed"` | 50 | Speed float64 `json:"speed"` |
| 50 | PlaybackTime int `json:"playback_time"` | 51 | PlaybackTime int `json:"playback_time"` |
| 51 | SocketPath string | 52 | SocketPath string |
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | type User struct { | 55 | type User struct { |
| 55 | Token string | 56 | Token string |
| 56 | Username string | 57 | Username string |
| 57 | Id int | 58 | Id int |
| 58 | AnimeList AnimeList | 59 | AnimeList AnimeList |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | // AniListAnime is the struct for the API response | 62 | // AniListAnime is the struct for the API response |
| @@ -82,29 +83,29 @@ type ResponseData struct { | |||
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | type Media struct { | 85 | type Media struct { |
| 85 | Duration int `json:"duration"` | 86 | Duration int `json:"duration"` |
| 86 | Episodes int `json:"episodes"` | 87 | Episodes int `json:"episodes"` |
| 87 | ID int `json:"id"` | 88 | ID int `json:"id"` |
| 88 | Title AnimeTitle `json:"title"` | 89 | Title AnimeTitle `json:"title"` |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | type Entry struct { | 92 | type Entry struct { |
| 92 | Media Media `json:"media"` | 93 | Media Media `json:"media"` |
| 93 | Progress int `json:"progress"` | 94 | Progress int `json:"progress"` |
| 94 | Score float64 `json:"score"` | 95 | Score float64 `json:"score"` |
| 95 | Status string `json:"status"` | 96 | Status string `json:"status"` |
| 96 | CoverImage string `json:"coverImage"` | 97 | CoverImage string `json:"coverImage"` |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | type AnimeList struct { | 100 | type AnimeList struct { |
| 100 | Watching []Entry `json:"watching"` | 101 | Watching []Entry `json:"watching"` |
| 101 | Completed []Entry `json:"completed"` | 102 | Completed []Entry `json:"completed"` |
| 102 | Paused []Entry `json:"paused"` | 103 | Paused []Entry `json:"paused"` |
| 103 | Dropped []Entry `json:"dropped"` | 104 | Dropped []Entry `json:"dropped"` |
| 104 | Planning []Entry `json:"planning"` | 105 | Planning []Entry `json:"planning"` |
| 105 | } | 106 | } |
| 106 | 107 | ||
| 107 | type RofiSelectPreview struct { | 108 | type RofiSelectPreview struct { |
| 108 | Title string `json:"title"` | 109 | Title string `json:"title"` |
| 109 | CoverImage string `json:"coverImage"` | 110 | CoverImage string `json:"coverImage"` |
| 110 | }\ No newline at end of file | 111 | } |