Commit 70320e4cd5

70320e4cd56d9100acaaa8cbd8873ae5f1ac1a9a

parent: 9dde998141

Unsigned

Wraient <wraient.911@gmail.com> · 2024-11-21 20:12 UTC

feat: Added option to change anime name language

Layout: unified · split

internal/anilist.go +7 −3
@@ -26,12 +26,14 @@ func FindKeyByValue(m map[string]string, value string) (string, error) {
26// GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value. 26// GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value.
27func GetAnimeMap(animeList AnimeList) map[string]string { 27func GetAnimeMap(animeList AnimeList) map[string]string {
28 animeMap := make(map[string]string) 28 animeMap := make(map[string]string)
29 userCurdConfig := GetGlobalConfig()
29 30
30 // Helper function to populate the map from a slice of entries 31 // Helper function to populate the map from a slice of entries
31 populateMap := func(entries []Entry) { 32 populateMap := func(entries []Entry) {
32 for _, entry := range entries { 33 for _, entry := range entries {
33 // Only include entries with a non-empty English title 34 // Only include entries with a non-empty English title
34 if entry.Media.Title.English != "" { 35
36 if entry.Media.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" {
35 animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.English 37 animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.English
36 } else { 38 } else {
37 animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.Romaji 39 animeMap[strconv.Itoa(entry.Media.ID)] = entry.Media.Title.Romaji
@@ -49,15 +51,17 @@ func GetAnimeMap(animeList AnimeList) map[string]string {
49 return animeMap 51 return animeMap
50} 52}
51 53
52// GetAnimeMap takes an AnimeList and returns a map with media.id as key and media.title.english as value. 54// GetAnimeMapPreview takes an AnimeList and returns a map with media.id as key and media.title.english as value.
53func GetAnimeMapPreview(animeList AnimeList) map[string]RofiSelectPreview { 55func GetAnimeMapPreview(animeList AnimeList) map[string]RofiSelectPreview {
56 userCurdConfig := GetGlobalConfig()
54 animeMap := make(map[string]RofiSelectPreview) 57 animeMap := make(map[string]RofiSelectPreview)
55 58
56 // Helper function to populate the map from a slice of entries 59 // Helper function to populate the map from a slice of entries
57 populateMap := func(entries []Entry) { 60 populateMap := func(entries []Entry) {
58 for _, entry := range entries { 61 for _, entry := range entries {
59 // Only include entries with a non-empty English title 62 // Only include entries with a non-empty English title
60 if entry.Media.Title.English != "" { 63 Log(fmt.Sprintf("AnimeNameLanguage: ", userCurdConfig.AnimeNameLanguage), logFile)
64 if entry.Media.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" {
61 animeMap[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 65 animeMap[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
62 Title: entry.Media.Title.English, 66 Title: entry.Media.Title.English,
63 CoverImage: entry.CoverImage, 67 CoverImage: entry.CoverImage,
internal/anime_list.go +10 −1
@@ -14,6 +14,7 @@ import (
14type anime struct { 14type anime struct {
15 ID string `json:"_id"` 15 ID string `json:"_id"`
16 Name string `json:"name"` 16 Name string `json:"name"`
17 EnglishName string `json:"englishName"`
17 AvailableEpisodes interface{} `json:"availableEpisodes"` 18 AvailableEpisodes interface{} `json:"availableEpisodes"`
18} 19}
19 20
@@ -63,6 +64,7 @@ func SearchAnime(query, mode string) (map[string]string, error) {
63 edges { 64 edges {
64 _id 65 _id
65 name 66 name
67 englishName
66 availableEpisodes 68 availableEpisodes
67 __typename 69 __typename
68 } 70 }
@@ -138,7 +140,14 @@ func SearchAnime(query, mode string) (map[string]string, error) {
138 episodesStr = "Unknown" 140 episodesStr = "Unknown"
139 } 141 }
140 } 142 }
141 animeList[anime.ID] = fmt.Sprintf("%s (%s episodes)", anime.Name, episodesStr) 143
144 // Use English name if available and configured, otherwise use default name
145 displayName := anime.Name
146 if anime.EnglishName != "" && userCurdConfig.AnimeNameLanguage == "english" {
147 displayName = anime.EnglishName
148 }
149
150 animeList[anime.ID] = fmt.Sprintf("%s (%s episodes)", displayName, episodesStr)
142 } 151 }
143 return animeList, nil 152 return animeList, nil
144} 153}
internal/config.go +2
@@ -16,6 +16,7 @@ type CurdConfig struct {
16 SubsLanguage string `config:"SubsLanguage"` 16 SubsLanguage string `config:"SubsLanguage"`
17 SubOrDub string `config:"SubOrDub"` 17 SubOrDub string `config:"SubOrDub"`
18 StoragePath string `config:"StoragePath"` 18 StoragePath string `config:"StoragePath"`
19 AnimeNameLanguage string `config:"AnimeNameLanguage"`
19 PercentageToMarkComplete int `config:"PercentageToMarkComplete"` 20 PercentageToMarkComplete int `config:"PercentageToMarkComplete"`
20 NextEpisodePrompt bool `config:"NextEpisodePrompt"` 21 NextEpisodePrompt bool `config:"NextEpisodePrompt"`
21 SkipOp bool `config:"SkipOp"` 22 SkipOp bool `config:"SkipOp"`
@@ -35,6 +36,7 @@ func defaultConfigMap() map[string]string {
35 return map[string]string{ 36 return map[string]string{
36 "Player": "mpv", 37 "Player": "mpv",
37 "StoragePath": "$HOME/.local/share/curd", 38 "StoragePath": "$HOME/.local/share/curd",
39 "AnimeNameLanguage": "english",
38 "SubsLanguage": "english", 40 "SubsLanguage": "english",
39 "SubOrDub": "sub", 41 "SubOrDub": "sub",
40 "PercentageToMarkComplete": "85", 42 "PercentageToMarkComplete": "85",
internal/curd.go +12 −12
@@ -204,7 +204,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
204 // Include anime from all categories 204 // Include anime from all categories
205 for _, entry := range user.AnimeList.Watching { 205 for _, entry := range user.AnimeList.Watching {
206 title := entry.Media.Title.English 206 title := entry.Media.Title.English
207 if title == "" { 207 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
208 title = entry.Media.Title.Romaji 208 title = entry.Media.Title.Romaji
209 } 209 }
210 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 210 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -214,7 +214,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
214 } 214 }
215 for _, entry := range user.AnimeList.Completed { 215 for _, entry := range user.AnimeList.Completed {
216 title := entry.Media.Title.English 216 title := entry.Media.Title.English
217 if title == "" { 217 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
218 title = entry.Media.Title.Romaji 218 title = entry.Media.Title.Romaji
219 } 219 }
220 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 220 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -224,7 +224,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
224 } 224 }
225 for _, entry := range user.AnimeList.Paused { 225 for _, entry := range user.AnimeList.Paused {
226 title := entry.Media.Title.English 226 title := entry.Media.Title.English
227 if title == "" { 227 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
228 title = entry.Media.Title.Romaji 228 title = entry.Media.Title.Romaji
229 } 229 }
230 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 230 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -234,7 +234,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
234 } 234 }
235 for _, entry := range user.AnimeList.Dropped { 235 for _, entry := range user.AnimeList.Dropped {
236 title := entry.Media.Title.English 236 title := entry.Media.Title.English
237 if title == "" { 237 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
238 title = entry.Media.Title.Romaji 238 title = entry.Media.Title.Romaji
239 } 239 }
240 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 240 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -244,7 +244,7 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
244 } 244 }
245 for _, entry := range user.AnimeList.Planning { 245 for _, entry := range user.AnimeList.Planning {
246 title := entry.Media.Title.English 246 title := entry.Media.Title.English
247 if title == "" { 247 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
248 title = entry.Media.Title.Romaji 248 title = entry.Media.Title.Romaji
249 } 249 }
250 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 250 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -257,35 +257,35 @@ func UpdateAnimeEntry(userCurdConfig *CurdConfig, user *User, logFile string) {
257 // Include anime from all categories 257 // Include anime from all categories
258 for _, entry := range user.AnimeList.Watching { 258 for _, entry := range user.AnimeList.Watching {
259 title := entry.Media.Title.English 259 title := entry.Media.Title.English
260 if title == "" { 260 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
261 title = entry.Media.Title.Romaji 261 title = entry.Media.Title.Romaji
262 } 262 }
263 animeListMap[strconv.Itoa(entry.Media.ID)] = title 263 animeListMap[strconv.Itoa(entry.Media.ID)] = title
264 } 264 }
265 for _, entry := range user.AnimeList.Completed { 265 for _, entry := range user.AnimeList.Completed {
266 title := entry.Media.Title.English 266 title := entry.Media.Title.English
267 if title == "" { 267 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
268 title = entry.Media.Title.Romaji 268 title = entry.Media.Title.Romaji
269 } 269 }
270 animeListMap[strconv.Itoa(entry.Media.ID)] = title 270 animeListMap[strconv.Itoa(entry.Media.ID)] = title
271 } 271 }
272 for _, entry := range user.AnimeList.Paused { 272 for _, entry := range user.AnimeList.Paused {
273 title := entry.Media.Title.English 273 title := entry.Media.Title.English
274 if title == "" { 274 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
275 title = entry.Media.Title.Romaji 275 title = entry.Media.Title.Romaji
276 } 276 }
277 animeListMap[strconv.Itoa(entry.Media.ID)] = title 277 animeListMap[strconv.Itoa(entry.Media.ID)] = title
278 } 278 }
279 for _, entry := range user.AnimeList.Dropped { 279 for _, entry := range user.AnimeList.Dropped {
280 title := entry.Media.Title.English 280 title := entry.Media.Title.English
281 if title == "" { 281 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
282 title = entry.Media.Title.Romaji 282 title = entry.Media.Title.Romaji
283 } 283 }
284 animeListMap[strconv.Itoa(entry.Media.ID)] = title 284 animeListMap[strconv.Itoa(entry.Media.ID)] = title
285 } 285 }
286 for _, entry := range user.AnimeList.Planning { 286 for _, entry := range user.AnimeList.Planning {
287 title := entry.Media.Title.English 287 title := entry.Media.Title.English
288 if title == "" { 288 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
289 title = entry.Media.Title.Romaji 289 title = entry.Media.Title.Romaji
290 } 290 }
291 animeListMap[strconv.Itoa(entry.Media.ID)] = title 291 animeListMap[strconv.Itoa(entry.Media.ID)] = title
@@ -623,7 +623,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
623 animeListMapPreview = make(map[string]RofiSelectPreview) 623 animeListMapPreview = make(map[string]RofiSelectPreview)
624 for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { 624 for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) {
625 title := entry.Media.Title.English 625 title := entry.Media.Title.English
626 if title == "" { 626 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
627 title = entry.Media.Title.Romaji 627 title = entry.Media.Title.Romaji
628 } 628 }
629 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{ 629 animeListMapPreview[strconv.Itoa(entry.Media.ID)] = RofiSelectPreview{
@@ -635,7 +635,7 @@ func SetupCurd(userCurdConfig *CurdConfig, anime *Anime, user *User, databaseAni
635 animeListMap = make(map[string]string) 635 animeListMap = make(map[string]string)
636 for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) { 636 for _, entry := range getEntriesByCategory(user.AnimeList, categorySelection.Key) {
637 title := entry.Media.Title.English 637 title := entry.Media.Title.English
638 if title == "" { 638 if title == "" || userCurdConfig.AnimeNameLanguage == "romaji" {
639 title = entry.Media.Title.Romaji 639 title = entry.Media.Title.Romaji
640 } 640 }
641 animeListMap[strconv.Itoa(entry.Media.ID)] = title 641 animeListMap[strconv.Itoa(entry.Media.ID)] = title
internal/localTracking.go +2 −1
@@ -165,7 +165,8 @@ func parseAnimeRow(row []string) *Anime {
165 165
166// Function to get the anime name (English or Romaji) from an Anime struct 166// Function to get the anime name (English or Romaji) from an Anime struct
167func GetAnimeName(anime Anime) string { 167func GetAnimeName(anime Anime) string {
168 if anime.Title.English != "" { 168 userCurdConfig := GetGlobalConfig()
169 if anime.Title.English != "" && userCurdConfig.AnimeNameLanguage == "english" {
169 return anime.Title.English 170 return anime.Title.English
170 } 171 }
171 return anime.Title.Romaji 172 return anime.Title.Romaji