From 70320e4cd56d9100acaaa8cbd8873ae5f1ac1a9a Mon Sep 17 00:00:00 2001 From: Wraient Date: Fri, 22 Nov 2024 01:42:07 +0530 Subject: [PATCH] feat: Added option to change anime name language --- internal/anilist.go | 10 +++++++--- internal/anime_list.go | 11 ++++++++++- internal/config.go | 2 ++ internal/curd.go | 24 ++++++++++++------------ internal/localTracking.go | 3 ++- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/internal/anilist.go b/internal/anilist.go index bd4ac2e..451c5af 100644 --- a/internal/anilist.go +++ b/internal/anilist.go @@ -26,12 +26,14 @@ func FindKeyByValue(m map[string]string, value string) (string, error) { // GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value. func GetAnimeMap(animeList AnimeList) map[string]string { animeMap := make(map[string]string) + userCurdConfig := GetGlobalConfig() // Helper function to populate the map from a slice of entries populateMap := func(entries []Entry) { for _, entry := range entries { // Only include entries with a non-empty English title - if entry.Media.Title.English != "" { + + if entry.Media.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" { animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.English } else { animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.Romaji @@ -49,15 +51,17 @@ func GetAnimeMap(animeList AnimeList) map[string]string { return animeMap } -// GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value. +// GetAnimeMapPreview takes an AnimeList and returns a map with media.id as key and media.title.english as value. func GetAnimeMapPreview(animeList AnimeList) map[string]RofiSelectPreview { + userCurdConfig := GetGlobalConfig() animeMap := make(map[string]RofiSelectPreview) // Helper function to populate the map from a slice of entries populateMap := func(entries []Entry) { for _, entry := range entries { // Only include entries with a non-empty English title - if entry.Media.Title.English != "" { + Log(fmt.Sprintf("AnimeNameLanguage: ", userCurdConfig.AnimeNameLanguage), logFile) + if entry.Media.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" { animeMap[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ Title: entry.Media.Title.English, CoverImage: entry.CoverImage, diff --git a/internal/anime_list.go b/internal/anime_list.go index 540f1d2..7c076a9 100644 --- a/internal/anime_list.go +++ b/internal/anime_list.go @@ -14,6 +14,7 @@ import ( type anime struct { ID string `json:"_id"` Name string `json:"name"` + EnglishName string `json:"englishName"` AvailableEpisodes interface{} `json:"availableEpisodes"` } @@ -63,6 +64,7 @@ func SearchAnime(query, mode string) (map[string]string, error) { edges { _id name + englishName availableEpisodes __typename } @@ -138,7 +140,14 @@ func SearchAnime(query, mode string) (map[string]string, error) { episodesStr = "Unknown" } } - animeList[anime.ID] = fmt.Sprintf("%s (%s episodes)", anime.Name, episodesStr) + + // Use English name if available and configured, otherwise use default name + displayName := anime.Name + if anime.EnglishName != "" && userCurdConfig.AnimeNameLanguage == "english" { + displayName = anime.EnglishName + } + + animeList[anime.ID] = fmt.Sprintf("%s (%s episodes)", displayName, episodesStr) } return animeList, nil } diff --git a/internal/config.go b/internal/config.go index 79583f3..7d2a2dc 100644 --- a/internal/config.go +++ b/internal/config.go @@ -16,6 +16,7 @@ type CurdConfig struct { SubsLanguage string `config:"SubsLanguage"` SubOrDub string `config:"SubOrDub"` StoragePath string `config:"StoragePath"` + AnimeNameLanguage string `config:"AnimeNameLanguage"` PercentageToMarkComplete int `config:"PercentageToMarkComplete"` NextEpisodePrompt bool `config:"NextEpisodePrompt"` SkipOp bool `config:"SkipOp"` @@ -35,6 +36,7 @@ func defaultConfigMap() map[string]string { return map[string]string{ "Player": "mpv", "StoragePath": "$HOME/.local/share/curd", + "AnimeNameLanguage": "english", "SubsLanguage": "english", "SubOrDub": "sub", "PercentageToMarkComplete": "85", diff --git a/internal/curd.go b/internal/curd.go index 693ad26..89c93e6 100644 --- a/internal/curd.go +++ b/internal/curd.go @@ -204,7 +204,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { // Include anime from all categories for _, entry := range user.AnimeList.Watching { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -214,7 +214,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { } for _, entry := range user.AnimeList.Completed { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -224,7 +224,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { } for _, entry := range user.AnimeList.Paused { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -234,7 +234,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { } for _, entry := range user.AnimeList.Dropped { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -244,7 +244,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { } for _, entry := range user.AnimeList.Planning { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -257,35 +257,35 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) { // Include anime from all categories for _, entry := range user.AnimeList.Watching { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title } for _, entry := range user.AnimeList.Completed { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title } for _, entry := range user.AnimeList.Paused { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title } for _, entry := range user.AnimeList.Dropped { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title } for _, entry := range user.AnimeList.Planning { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title @@ -623,7 +623,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni animeListMapPreview = make(map[string]RofiSelectPreview) for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ @@ -635,7 +635,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni animeListMap = make(map[string]string) for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { title := entry.Media.Title.English - if title == "" { + if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" { title = entry.Media.Title.Romaji } animeListMap[strconv.Itoa(entry.Media.ID)] = title diff --git a/internal/localTracking.go b/internal/localTracking.go index 2f5d34a..f444e26 100644 --- a/internal/localTracking.go +++ b/internal/localTracking.go @@ -165,7 +165,8 @@ func parseAnimeRow(row []string) *Anime { // Function to get the anime name (English or Romaji) from an Anime struct func GetAnimeName(anime Anime) string { - if anime.Title.English != "" { + userCurdConfig := GetGlobalConfig() + if anime.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" { return anime.Title.English } return anime.Title.Romaji