mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-14 06:09:52 +01:00
MAL progress fetch
This commit is contained in:
35
schaffer.go
35
schaffer.go
@@ -128,3 +128,38 @@ func SearchSeason(animeId int64) (*Anime, error) {
|
||||
}
|
||||
return nil, errors.New("anime not found")
|
||||
}
|
||||
|
||||
func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, error) {
|
||||
// check watching first
|
||||
list, _, err := GetUserAnimeListData(username, malApiStatusW)
|
||||
if err != nil {
|
||||
return 0, time.Time{}, err
|
||||
}
|
||||
for _, a := range list.Data {
|
||||
// check if found
|
||||
if a.Node.ID == animeId {
|
||||
// check if progress changed
|
||||
if progress != a.ListStatus.NumEpisodesWatched {
|
||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
return progress, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
}
|
||||
// check completed
|
||||
list, _, err = GetUserAnimeListData(username, malApiStatusC)
|
||||
if err != nil {
|
||||
return 0, time.Time{}, err
|
||||
}
|
||||
for _, a := range list.Data {
|
||||
// check if found
|
||||
if a.Node.ID == animeId {
|
||||
// check if progress changed
|
||||
if progress != a.ListStatus.NumEpisodesWatched {
|
||||
return a.ListStatus.NumEpisodesWatched, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
return progress, a.ListStatus.UpdatedAt, nil
|
||||
}
|
||||
}
|
||||
// has no progress or dropped/hold
|
||||
return 0, time.Now(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user