Skip to content

Commit

Permalink
feat: Added option to change anime name language
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraient committed Nov 21, 2024
1 parent 9dde998 commit 70320e4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
10 changes: 7 additions & 3 deletions internal/anilist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion internal/anime_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type anime struct {
ID string `json:"_id"`
Name string `json:"name"`
EnglishName string `json:"englishName"`
AvailableEpisodes interface{} `json:"availableEpisodes"`
}

Expand Down Expand Up @@ -63,6 +64,7 @@ func SearchAnime(query, mode string) (map[string]string, error) {
edges {
_id
name
englishName
availableEpisodes
__typename
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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",
Expand Down
24 changes: 12 additions & 12 deletions internal/curd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/localTracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70320e4

Please sign in to comment.