fixed a bug in simkl where nothing loads if it does not have an anilist id
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user