diff --git a/SimklFunctions.go b/SimklFunctions.go index c57208f..9c611ff 100644 --- a/SimklFunctions.go +++ b/SimklFunctions.go @@ -230,7 +230,7 @@ func (a *App) SimklSyncStatus(anime SimklAnime, status string) SimklAnime { return anime } -func (a *App) SimklSearch(aniId int) SimklAnime { +func (a *App) SimklSearch(aniListAnime MediaList) SimklAnime { var result SimklAnime if reflect.DeepEqual(WatchList, SimklWatchList{}) { @@ -243,23 +243,39 @@ func (a *App) SimklSearch(aniId int) SimklAnime { if err != nil { fmt.Println("AniList ID does not exist on " + anime.Show.Title) } - if id == aniId { + if id == aniListAnime.Media.ID { result = anime } } if reflect.DeepEqual(result, SimklAnime{}) { var anime SimklSearchType - url := "https://api.simkl.com/search/id?anilist=" + strconv.Itoa(aniId) + url := "https://api.simkl.com/search/id?anilist=" + strconv.Itoa(aniListAnime.Media.ID) respBody := SimklHelper("GET", url, nil) err := json.Unmarshal(respBody, &anime) + + if len(anime) == 0 { + fmt.Println("reached search by mal") + url = "https://api.simkl.com/search/id?mal=" + strconv.Itoa(aniListAnime.Media.IDMal) + respBody = SimklHelper("GET", url, nil) + fmt.Println(string(respBody)) + err = json.Unmarshal(respBody, &anime) + } + if err != nil { log.Printf("Failed at unmarshal, %s\n", err) } - if len(anime) > 0 { + for _, watchListAnime := range WatchList.Anime { + id := watchListAnime.Show.Ids.Simkl + if id == anime[0].Ids.Simkl { + result = watchListAnime + } + } + + if reflect.DeepEqual(result, SimklSearchType{}) && len(anime) > 0 { result.Show.Title = anime[0].Title result.Show.Poster = anime[0].Poster result.Show.Ids.Simkl = anime[0].Ids.Simkl diff --git a/frontend/src/helperComponents/Anime.svelte b/frontend/src/helperComponents/Anime.svelte index 4b06636..8411a0c 100644 --- a/frontend/src/helperComponents/Anime.svelte +++ b/frontend/src/helperComponents/Anime.svelte @@ -63,7 +63,7 @@ const completedAtDate = convertAniListDateToString(currentAniListAnime.data.MediaList.completedAt) if (isAniListLoggedIn) AddAnimeServiceToTable({ - id: currentAniListAnime.data.MediaList.id, + id: currentAniListAnime.data.MediaList.mediaId, title, service: "AniList", progress: currentAniListAnime.data.MediaList.progress, @@ -168,7 +168,7 @@ return newValue }) AddAnimeServiceToTable({ - id: currentAniListAnime.data.MediaList.id, + id: currentAniListAnime.data.MediaList.mediaId, title, service: "AniList", progress: currentAniListAnime.data.MediaList.progress, diff --git a/frontend/wailsjs/go/main/App.d.ts b/frontend/wailsjs/go/main/App.d.ts index 004a4bc..e060917 100755 --- a/frontend/wailsjs/go/main/App.d.ts +++ b/frontend/wailsjs/go/main/App.d.ts @@ -42,7 +42,7 @@ export function SimklGetUserWatchlist():Promise; export function SimklLogin():Promise; -export function SimklSearch(arg1:number):Promise; +export function SimklSearch(arg1:main.MediaList):Promise; export function SimklSyncEpisodes(arg1:main.SimklAnime,arg2:number):Promise;