Skip to content

Commit

Permalink
fix not getting all of users anime
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Jun 14, 2024
1 parent 65c8ebe commit 7e6f840
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,46 @@ public async IAsyncEnumerable<AnimeModel> GetAnime()
}

var result = await _client.Anime()
.OfUser()
.IncludeNsfw()
.WithFields(_fieldNames)
.Find();
.OfUser()
.IncludeNsfw()
.WithFields(_fieldNames)
.Find();

foreach (var item in result.Data)
foreach (var item in ConvertAndFill(result.Data))
{
var model = ConvertModel(item);
yield return item;
}

if (model.Tracking.Status == AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring)
while (!string.IsNullOrEmpty(result.Paging?.Next))
{
result = await _client.GetNextAnimePage(result);

foreach (var item in ConvertAndFill(result.Data))
{
Observable
.FromAsync(_ => _anilistService.GetNextAiringEpisode(item.Id), RxApp.TaskpoolScheduler)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x =>
{
model.AiredEpisodes = x.Episode - 1 ?? 0;
model.NextEpisodeAt = x.Time;
});
yield return item;
}
}

yield return model;
IEnumerable<AnimeModel> ConvertAndFill(IEnumerable<MalApi.Anime> anime)
{
foreach (var item in anime)
{
var model = ConvertModel(item);

if (model.Tracking.Status == AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring)
{
Observable
.FromAsync(_ => _anilistService.GetNextAiringEpisode(item.Id), RxApp.TaskpoolScheduler)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x =>
{
model.AiredEpisodes = x.Episode - 1 ?? 0;
model.NextEpisodeAt = x.Time;
});
}

yield return model;
}
}
}

Expand Down

0 comments on commit 7e6f840

Please sign in to comment.