Commit b859cc34cf
Unregistered key
Layout: unified · split
cmd/curd/main.go +1
| @@ -79,6 +79,7 @@ func main() { | |||
| 79 | flag.StringVar(&userCurdConfig.DiscordClientId, "discord-client-id", userCurdConfig.DiscordClientId, "Discord client ID for Rich Presence") | 79 | flag.StringVar(&userCurdConfig.DiscordClientId, "discord-client-id", userCurdConfig.DiscordClientId, "Discord client ID for Rich Presence") |
| 80 | flag.BoolVar(&userCurdConfig.VimKeys, "vim-keys", userCurdConfig.VimKeys, "Enable vim motions in selection menus (j/k/h/l, / search) (true/false)") | 80 | flag.BoolVar(&userCurdConfig.VimKeys, "vim-keys", userCurdConfig.VimKeys, "Enable vim motions in selection menus (j/k/h/l, / search) (true/false)") |
| 81 | flag.BoolVar(&userCurdConfig.CheckUpdates, "check-updates", userCurdConfig.CheckUpdates, "Check for curd updates in the background when idle (true/false)") | 81 | flag.BoolVar(&userCurdConfig.CheckUpdates, "check-updates", userCurdConfig.CheckUpdates, "Check for curd updates in the background when idle (true/false)") |
| 82 | flag.BoolVar(&userCurdConfig.ShowNewEpisodes, "show-new-episodes", userCurdConfig.ShowNewEpisodes, "Show new episode indicators in currently watching list (true/false)") | ||
| 82 | continueLast := flag.Bool("c", false, "Continue last episode") | 83 | continueLast := flag.Bool("c", false, "Continue last episode") |
| 83 | addNewAnime := flag.Bool("new", false, "Add new anime") | 84 | addNewAnime := flag.Bool("new", false, "Add new anime") |
| 84 | rofiSelection := flag.Bool("rofi", false, "Open selection in rofi") | 85 | rofiSelection := flag.Bool("rofi", false, "Open selection in rofi") |
internal/anilist.go +15
| @@ -534,6 +534,10 @@ func GetUserData(token string, userID int) (map[string]interface{}, error) { | |||
| 534 | native | 534 | native |
| 535 | } | 535 | } |
| 536 | status | 536 | status |
| 537 | nextAiringEpisode { | ||
| 538 | episode | ||
| 539 | timeUntilAiring | ||
| 540 | } | ||
| 537 | } | 541 | } |
| 538 | status | 542 | status |
| 539 | score | 543 | score |
| @@ -597,6 +601,10 @@ func GetUserDataPreview(token string, userID int) (map[string]interface{}, error | |||
| 597 | native | 601 | native |
| 598 | } | 602 | } |
| 599 | status | 603 | status |
| 604 | nextAiringEpisode { | ||
| 605 | episode | ||
| 606 | timeUntilAiring | ||
| 607 | } | ||
| 600 | } | 608 | } |
| 601 | status | 609 | status |
| 602 | score | 610 | score |
| @@ -1171,6 +1179,13 @@ func ParseAnimeList(input map[string]interface{}) AnimeList { | |||
| 1171 | animeEntry.CoverImage = safeString(coverImage["large"]) | 1179 | animeEntry.CoverImage = safeString(coverImage["large"]) |
| 1172 | } | 1180 | } |
| 1173 | 1181 | ||
| 1182 | if nextEp, ok := media["nextAiringEpisode"].(map[string]interface{}); ok && nextEp != nil { | ||
| 1183 | animeEntry.Media.NextAiringEpisode = &NextAiringEpisodeInfo{ | ||
| 1184 | Episode: toInt(nextEp["episode"]), | ||
| 1185 | TimeUntilAiring: toInt(nextEp["timeUntilAiring"]), | ||
| 1186 | } | ||
| 1187 | } | ||
| 1188 | |||
| 1174 | // Defense in depth: never insert the same media twice even if AniList | 1189 | // Defense in depth: never insert the same media twice even if AniList |
| 1175 | // returns the entry under multiple non-custom lists. | 1190 | // returns the entry under multiple non-custom lists. |
| 1176 | if animeEntry.Media.ID != 0 { | 1191 | if animeEntry.Media.ID != 0 { |
internal/anilist_cache.go +18 −4
| @@ -269,9 +269,16 @@ func buildCategorySelectionOptions(list AnimeList, category string) []SelectionO | |||
| 269 | for _, entry := range getEntriesByCategory(list, category) { | 269 | for _, entry := range getEntriesByCategory(list, category) { |
| 270 | title := mediaDisplayTitle(entry.Media, userCurdConfig) | 270 | title := mediaDisplayTitle(entry.Media, userCurdConfig) |
| 271 | 271 | ||
| 272 | hasNew := false | ||
| 273 | if userCurdConfig.ShowNewEpisodes && entry.Media.NextAiringEpisode != nil { | ||
| 274 | nextWatched := nextEpisodeFromProgress(entry.Progress) | ||
| 275 | hasNew = entry.Media.NextAiringEpisode.Episode > nextWatched | ||
| 276 | } | ||
| 277 | |||
| 272 | options = append(options, SelectionOption{ | 278 | options = append(options, SelectionOption{ |
| 273 | Key: strconv.Itoa(entry.Media.ID), | 279 | Key: strconv.Itoa(entry.Media.ID), |
| 274 | Label: title, | 280 | Label: title, |
| 281 | HasNewEpisodes: hasNew, | ||
| 275 | }) | 282 | }) |
| 276 | } | 283 | } |
| 277 | 284 | ||
| @@ -285,9 +292,16 @@ func buildCategoryPreviewOptions(list AnimeList, category string) map[string]Rof | |||
| 285 | for _, entry := range getEntriesByCategory(list, category) { | 292 | for _, entry := range getEntriesByCategory(list, category) { |
| 286 | title := mediaDisplayTitle(entry.Media, userCurdConfig) | 293 | title := mediaDisplayTitle(entry.Media, userCurdConfig) |
| 287 | 294 | ||
| 295 | hasNew := false | ||
| 296 | if userCurdConfig.ShowNewEpisodes && entry.Media.NextAiringEpisode != nil { | ||
| 297 | nextWatched := nextEpisodeFromProgress(entry.Progress) | ||
| 298 | hasNew = entry.Media.NextAiringEpisode.Episode > nextWatched | ||
| 299 | } | ||
| 300 | |||
| 288 | options[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ | 301 | options[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ |
| 289 | Title: title, | 302 | Title: title, |
| 290 | CoverImage: entry.CoverImage, | 303 | CoverImage: entry.CoverImage, |
| 304 | HasNewEpisodes: hasNew, | ||
| 291 | } | 305 | } |
| 292 | } | 306 | } |
| 293 | 307 | ||
internal/config.go +2
| @@ -76,6 +76,7 @@ type CurdConfig struct { | |||
| 76 | MyAnimeListClientSecret string `config:"MyAnimeListClientSecret"` | 76 | MyAnimeListClientSecret string `config:"MyAnimeListClientSecret"` |
| 77 | MyAnimeListImported bool `config:"MyAnimeListImported"` | 77 | MyAnimeListImported bool `config:"MyAnimeListImported"` |
| 78 | MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` | 78 | MyAnimeListImportDismissed bool `config:"MyAnimeListImportDismissed"` |
| 79 | ShowNewEpisodes bool `config:"ShowNewEpisodes"` | ||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | const ( | 82 | const ( |
| @@ -137,6 +138,7 @@ func defaultConfigMap() map[string]string { | |||
| 137 | "MyAnimeListClientSecret": "", | 138 | "MyAnimeListClientSecret": "", |
| 138 | "MyAnimeListImported": "false", | 139 | "MyAnimeListImported": "false", |
| 139 | "MyAnimeListImportDismissed": "false", | 140 | "MyAnimeListImportDismissed": "false", |
| 141 | "ShowNewEpisodes": "true", | ||
| 140 | } | 142 | } |
| 141 | } | 143 | } |
| 142 | 144 | ||
internal/selection_menu.go +50 −14
| @@ -78,6 +78,11 @@ var ( | |||
| 78 | 78 | ||
| 79 | quitHintStyle = lipgloss.NewStyle(). | 79 | quitHintStyle = lipgloss.NewStyle(). |
| 80 | Foreground(lipgloss.Color("#FFD700")) // Gold | 80 | Foreground(lipgloss.Color("#FFD700")) // Gold |
| 81 | |||
| 82 | newEpisodeItemStyle = lipgloss.NewStyle(). | ||
| 83 | Foreground(lipgloss.Color("#4CAF50")) // Green | ||
| 84 | |||
| 85 | rofiNewEpisodeColor = "#4CAF50" | ||
| 81 | ) | 86 | ) |
| 82 | 87 | ||
| 83 | // Init initializes the model | 88 | // Init initializes the model |
| @@ -318,10 +323,18 @@ func (m Model) View() string { | |||
| 318 | 323 | ||
| 319 | // Render the options within the visible range | 324 | // Render the options within the visible range |
| 320 | for i := start; i < end; i++ { | 325 | for i := start; i < end; i++ { |
| 326 | label := m.filteredKeys[i].Label | ||
| 327 | |||
| 321 | if i == m.selected { | 328 | if i == m.selected { |
| 322 | b.WriteString(selectedItemStyle.Render(m.filteredKeys[i].Label) + "\n") | 329 | if m.filteredKeys[i].HasNewEpisodes { |
| 330 | b.WriteString(newEpisodeItemStyle.Render(" [NEW]") + selectedItemStyle.Render(label) + "\n") | ||
| 331 | } else { | ||
| 332 | b.WriteString(selectedItemStyle.Render(label) + "\n") | ||
| 333 | } | ||
| 334 | } else if m.filteredKeys[i].HasNewEpisodes { | ||
| 335 | b.WriteString(newEpisodeItemStyle.Render(" [NEW]") + regularItemStyle.Render(label) + "\n") | ||
| 323 | } else { | 336 | } else { |
| 324 | b.WriteString(regularItemStyle.Render(m.filteredKeys[i].Label) + "\n") | 337 | b.WriteString(regularItemStyle.Render(label) + "\n") |
| 325 | } | 338 | } |
| 326 | } | 339 | } |
| 327 | } | 340 | } |
| @@ -339,11 +352,19 @@ func (m Model) visibleItemsCount() int { | |||
| 339 | return count | 352 | return count |
| 340 | } | 353 | } |
| 341 | 354 | ||
| 355 | func displayLabel(opt SelectionOption) string { | ||
| 356 | if opt.HasNewEpisodes { | ||
| 357 | return "[NEW]" + opt.Label | ||
| 358 | } | ||
| 359 | return opt.Label | ||
| 360 | } | ||
| 361 | |||
| 342 | // filterOptions filters and sorts options based on the search term | 362 | // filterOptions filters and sorts options based on the search term |
| 343 | func (m *Model) filterOptions() { | 363 | func (m *Model) filterOptions() { |
| 344 | m.filteredKeys = nil | 364 | m.filteredKeys = nil |
| 345 | for _, opt := range m.allOptions { | 365 | for _, opt := range m.allOptions { |
| 346 | if strings.Contains(strings.ToLower(opt.Label), strings.ToLower(m.filter)) { | 366 | // Small function to also consider new episode from list |
| 367 | if strings.Contains(strings.ToLower(displayLabel(opt)), strings.ToLower(m.filter)) { | ||
| 347 | m.filteredKeys = append(m.filteredKeys, opt) | 368 | m.filteredKeys = append(m.filteredKeys, opt) |
| 348 | } | 369 | } |
| 349 | } | 370 | } |
| @@ -498,8 +519,9 @@ func previewOptionsToSortedSelection(options map[string]RofiSelectPreview) []Sel | |||
| 498 | selectionOptions := make([]SelectionOption, 0, len(options)) | 519 | selectionOptions := make([]SelectionOption, 0, len(options)) |
| 499 | for id, opt := range options { | 520 | for id, opt := range options { |
| 500 | selectionOptions = append(selectionOptions, SelectionOption{ | 521 | selectionOptions = append(selectionOptions, SelectionOption{ |
| 501 | Label: opt.Title, | 522 | Label: opt.Title, |
| 502 | Key: id, | 523 | Key: id, |
| 524 | HasNewEpisodes: opt.HasNewEpisodes, | ||
| 503 | }) | 525 | }) |
| 504 | } | 526 | } |
| 505 | 527 | ||
| @@ -531,18 +553,22 @@ func DynamicSelectPreviewWithRefresh(options map[string]RofiSelectPreview, addne | |||
| 531 | Log(fmt.Sprintf("Error caching image: %v", err)) | 553 | Log(fmt.Sprintf("Error caching image: %v", err)) |
| 532 | continue | 554 | continue |
| 533 | } | 555 | } |
| 534 | rofiInput.WriteString(fmt.Sprintf("%s\x00icon\x1f%s\n", opt.Label, cachePath)) | 556 | label := opt.Label |
| 557 | if opt.HasNewEpisodes { | ||
| 558 | label = fmt.Sprintf("<span foreground=\"%s\">[NEW]</span> %s ", rofiNewEpisodeColor, opt.Label) | ||
| 559 | } | ||
| 560 | rofiInput.WriteString(fmt.Sprintf("%s\x00icon\x1f%s\n", label, cachePath)) | ||
| 535 | } | 561 | } |
| 536 | 562 | ||
| 537 | if addnewoption { | 563 | if addnewoption { |
| 538 | |||
| 539 | rofiInput.WriteString("Add new anime\n") | 564 | rofiInput.WriteString("Add new anime\n") |
| 540 | } | 565 | } |
| 541 | rofiInput.WriteString("Back\n") | 566 | rofiInput.WriteString("Back\n") |
| 542 | rofiInput.WriteString("Quit\n") | 567 | rofiInput.WriteString("Quit\n") |
| 543 | 568 | ||
| 544 | configPath := filepath.Join(GetStoragePath(), "selectanimepreview.rasi") | 569 | configPath := filepath.Join(GetStoragePath(), "selectanimepreview.rasi") |
| 545 | cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-show-icons", "-p", "Select Anime", "-i", "-no-custom") | 570 | // NOTE: Need `-markup-rows` to enable pango |
| 571 | cmd := exec.Command("rofi", "-dmenu", "-theme", configPath, "-show-icons", "-markup-rows", "-p", "Select Anime", "-i", "-no-custom") | ||
| 546 | cmd.Stdin = strings.NewReader(rofiInput.String()) | 572 | cmd.Stdin = strings.NewReader(rofiInput.String()) |
| 547 | var stdout, stderr bytes.Buffer | 573 | var stdout, stderr bytes.Buffer |
| 548 | cmd.Stdout = &stdout | 574 | cmd.Stdout = &stdout |
| @@ -613,6 +639,9 @@ func preDownloadImages(options map[string]RofiSelectPreview, count int) { | |||
| 613 | 639 | ||
| 614 | func parsePreviewSelection(rawSelection string, selectionOptions []SelectionOption) (SelectionOption, error) { | 640 | func parsePreviewSelection(rawSelection string, selectionOptions []SelectionOption) (SelectionOption, error) { |
| 615 | selected := strings.TrimSpace(rawSelection) | 641 | selected := strings.TrimSpace(rawSelection) |
| 642 | selected = strings.TrimSpace(pangoStrip.ReplaceAllString(selected, "")) | ||
| 643 | selected = strings.TrimPrefix(selected, "[NEW] ") | ||
| 644 | selected = strings.TrimSpace(selected) | ||
| 616 | 645 | ||
| 617 | switch selected { | 646 | switch selected { |
| 618 | case "": | 647 | case "": |
| @@ -641,7 +670,7 @@ func downloadToCache(imageURL string) (string, error) { | |||
| 641 | } | 670 | } |
| 642 | 671 | ||
| 643 | cacheDir := os.ExpandEnv("${HOME}/.cache/curd/images") | 672 | cacheDir := os.ExpandEnv("${HOME}/.cache/curd/images") |
| 644 | if err := os.MkdirAll(cacheDir, 0755); err != nil { | 673 | if err := os.MkdirAll(cacheDir, 0o755); err != nil { |
| 645 | return "", fmt.Errorf("failed to create cache directory: %w", err) | 674 | return "", fmt.Errorf("failed to create cache directory: %w", err) |
| 646 | } | 675 | } |
| 647 | 676 | ||
| @@ -725,8 +754,7 @@ func rofiSelectInternal(options []SelectionOption, isHomeMenu bool, refreshConfi | |||
| 725 | for { | 754 | for { |
| 726 | optionsString := buildRofiOptionsString(currentOptions, isHomeMenu) | 755 | optionsString := buildRofiOptionsString(currentOptions, isHomeMenu) |
| 727 | configPath := filepath.Join(GetStoragePath(), "selectanime.rasi") | 756 | configPath := filepath.Join(GetStoragePath(), "selectanime.rasi") |
| 728 | // -markup: enable Pango in -mesg (and prompts where supported) | 757 | args := []string{"-dmenu", "-theme", configPath, "-i", "-markup", "-markup-rows", "-p", prompt} |
| 729 | args := []string{"-dmenu", "-theme", configPath, "-i", "-markup", "-p", prompt} | ||
| 730 | if msg := strings.TrimSpace(message); msg != "" { | 758 | if msg := strings.TrimSpace(message); msg != "" { |
| 731 | args = append(args, "-mesg", msg) | 759 | args = append(args, "-mesg", msg) |
| 732 | } | 760 | } |
| @@ -894,7 +922,11 @@ func dynamicSelectInternal(options []SelectionOption, refreshConfig *SelectionRe | |||
| 894 | func buildRofiOptionsString(options []SelectionOption, isHomeMenu bool) string { | 922 | func buildRofiOptionsString(options []SelectionOption, isHomeMenu bool) string { |
| 895 | optionsList := make([]string, 0, len(options)+2) | 923 | optionsList := make([]string, 0, len(options)+2) |
| 896 | for _, opt := range options { | 924 | for _, opt := range options { |
| 897 | optionsList = append(optionsList, opt.Label) | 925 | if opt.HasNewEpisodes { |
| 926 | optionsList = append(optionsList, fmt.Sprintf("<span foreground=\"%s\">[NEW]</span> %s", rofiNewEpisodeColor, opt.Label)) | ||
| 927 | } else { | ||
| 928 | optionsList = append(optionsList, opt.Label) | ||
| 929 | } | ||
| 898 | } | 930 | } |
| 899 | 931 | ||
| 900 | if !isHomeMenu { | 932 | if !isHomeMenu { |
| @@ -917,8 +949,12 @@ func parseRofiSelection(err error, rawSelection string, options []SelectionOptio | |||
| 917 | } | 949 | } |
| 918 | 950 | ||
| 919 | selected := strings.TrimSpace(rawSelection) | 951 | selected := strings.TrimSpace(rawSelection) |
| 920 | // Strip accidental Pango/markup noise if a theme echoes it. | 952 | // strip accidental pango noise if a theme echoes it. |
| 921 | selected = strings.TrimSpace(ansiStrip.ReplaceAllString(selected, "")) | 953 | selected = strings.TrimSpace(pangoStrip.ReplaceAllString( |
| 954 | ansiStrip.ReplaceAllString(selected, ""), "", | ||
| 955 | )) | ||
| 956 | selected = strings.TrimPrefix(selected, "[NEW] ") | ||
| 957 | selected = strings.TrimSpace(selected) | ||
| 922 | switch { | 958 | switch { |
| 923 | case selected == "": | 959 | case selected == "": |
| 924 | if isHomeMenu { | 960 | if isHomeMenu { |
internal/structs.go +22 −14
| @@ -71,6 +71,11 @@ type NextEpisode struct { | |||
| 71 | Mode string | 71 | Mode string |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | type NextAiringEpisodeInfo struct { | ||
| 75 | Episode int | ||
| 76 | TimeUntilAiring int | ||
| 77 | } | ||
| 78 | |||
| 74 | // StreamPlaybackHint carries MPV playback metadata for a resolved stream URL. | 79 | // StreamPlaybackHint carries MPV playback metadata for a resolved stream URL. |
| 75 | type StreamPlaybackHint struct { | 80 | type StreamPlaybackHint struct { |
| 76 | Referrer string | 81 | Referrer string |
| @@ -127,13 +132,14 @@ type ResponseData struct { | |||
| 127 | } | 132 | } |
| 128 | 133 | ||
| 129 | type Media struct { | 134 | type Media struct { |
| 130 | Duration int `json:"duration"` | 135 | Duration int `json:"duration"` |
| 131 | Episodes int `json:"episodes"` | 136 | Episodes int `json:"episodes"` |
| 132 | Format string `json:"format"` | 137 | Format string `json:"format"` |
| 133 | ID int `json:"id"` | 138 | ID int `json:"id"` |
| 134 | MalID int `json:"mal_id"` | 139 | MalID int `json:"mal_id"` |
| 135 | Title AnimeTitle `json:"title"` | 140 | Title AnimeTitle `json:"title"` |
| 136 | Status string `json:"status"` | 141 | Status string `json:"status"` |
| 142 | NextAiringEpisode *NextAiringEpisodeInfo `json:"nextAiringEpisode,omitempty"` | ||
| 137 | } | 143 | } |
| 138 | 144 | ||
| 139 | type Entry struct { | 145 | type Entry struct { |
| @@ -159,8 +165,9 @@ type AnimeList struct { | |||
| 159 | } | 165 | } |
| 160 | 166 | ||
| 161 | type RofiSelectPreview struct { | 167 | type RofiSelectPreview struct { |
| 162 | Title string `json:"title"` | 168 | Title string `json:"title"` |
| 163 | CoverImage string `json:"coverImage"` | 169 | CoverImage string `json:"coverImage"` |
| 170 | HasNewEpisodes bool `json:"-"` | ||
| 164 | } | 171 | } |
| 165 | 172 | ||
| 166 | type SelectionOptionImage struct { | 173 | type SelectionOptionImage struct { |
| @@ -171,9 +178,10 @@ type SelectionOptionImage struct { | |||
| 171 | 178 | ||
| 172 | // SelectionOption holds the label and the internal key | 179 | // SelectionOption holds the label and the internal key |
| 173 | type SelectionOption struct { | 180 | type SelectionOption struct { |
| 174 | Title string | 181 | Title string |
| 175 | Label string | 182 | Label string |
| 176 | Key string | 183 | Key string |
| 177 | Thumbnail string | 184 | Thumbnail string |
| 178 | ExtraData interface{} | 185 | ExtraData interface{} |
| 186 | HasNewEpisodes bool | ||
| 179 | } | 187 | } |
internal/update.go +1
| @@ -287,6 +287,7 @@ var ( | |||
| 287 | mdLinkRe = regexp.MustCompile(`\[([^\]]+)\]\(([^)]+)\)`) | 287 | mdLinkRe = regexp.MustCompile(`\[([^\]]+)\]\(([^)]+)\)`) |
| 288 | mdURLRe = regexp.MustCompile(`https?://[^\s<>\]]+`) | 288 | mdURLRe = regexp.MustCompile(`https?://[^\s<>\]]+`) |
| 289 | ansiStrip = regexp.MustCompile(`\x1b\[[0-9;]*m`) | 289 | ansiStrip = regexp.MustCompile(`\x1b\[[0-9;]*m`) |
| 290 | pangoStrip = regexp.MustCompile(`<[^>]*>`) | ||
| 290 | ) | 291 | ) |
| 291 | 292 | ||
| 292 | // markdownToPango turns common GitHub release markdown into Rofi-friendly Pango. | 293 | // markdownToPango turns common GitHub release markdown into Rofi-friendly Pango. |
rofi/selectanimepreview.rasi +1 −1
| @@ -6,7 +6,7 @@ | |||
| 6 | text-color: #BBBBBB; /* Default text color (light gray) */ | 6 | text-color: #BBBBBB; /* Default text color (light gray) */ |
| 7 | text-color-selected: #FFFFFF; /* Text color when selected (white) */ | 7 | text-color-selected: #FFFFFF; /* Text color when selected (white) */ |
| 8 | primary: rgba(53, 132, 228, 0.75); /* Blusish primary color */ | 8 | primary: rgba(53, 132, 228, 0.75); /* Blusish primary color */ |
| 9 | important: rgba(53, 132, 228, 0.75); /* Bluish primary color */ | 9 | important: rgba(53, 132, 228, 0.75); /* Bluish primary color */ |
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | configuration { | 12 | configuration { |