Skip to content

Commit

Permalink
fix: 重复标记已观看时,同步api检查状态
Browse files Browse the repository at this point in the history
  • Loading branch information
fiochen committed May 8, 2023
1 parent adae824 commit b04e6ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Jellyfin.Plugin.Bangumi/BangumiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ public async Task UpdateCollectionStatus(string accessToken, int subjectId, Coll
await SendRequest(request, accessToken, token);
}

public async Task<EpisodeCollectionInfo?> GetEpisodeStatus(string accessToken, int episodeId, CancellationToken token)
{
return await SendRequest<EpisodeCollectionInfo>($"https://api.bgm.tv/v0/users/-/collections/-/episodes/{episodeId}", accessToken, token);
}

public async Task UpdateEpisodeStatus(string accessToken, int subjectId, int episodeId, EpisodeCollectionType status, CancellationToken token)
{
var request = new HttpRequestMessage(HttpMethod.Put, $"https://api.bgm.tv/v0/users/-/collections/-/episodes/{episodeId}");
Expand Down
10 changes: 7 additions & 3 deletions Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void OnUserDataSaved(object? sender, UserDataSaveEventArgs e)
GetPlaybackHistory(e.UserId).Remove(e.UserData.Key);
_log.LogInformation("mark {Name} (#{Id}) as new for user #{User}", e.Item.Name, e.Item.Id, e.UserId);
if (Configuration.ReportManualStatusChangeToBangumi)
ReportPlaybackStatus(e.Item, e.UserId, true).ConfigureAwait(false);
ReportPlaybackStatus(e.Item, e.UserId, false).ConfigureAwait(false);
break;

case UserDataSaveReason.PlaybackFinished when e.UserData.Played:
Expand Down Expand Up @@ -130,8 +130,12 @@ private async Task ReportPlaybackStatus(BaseItem item, Guid userId, bool played)

if (item.GetUserDataKeys().Intersect(GetPlaybackHistory(userId)).Any())
{
_log.LogInformation("item {Name} (#{Id}) has been played before, ignored", item.Name, item.Id);
return;
var episodeStatus = await _api.GetEpisodeStatus(user.AccessToken, episodeId, CancellationToken.None);
if (played && episodeStatus is {Type: EpisodeCollectionType.Watched})
{
_log.LogInformation("item {Name} (#{Id}) has been marked as watched before, ignored", item.Name, item.Id);
return;
}
}

try
Expand Down

0 comments on commit b04e6ec

Please sign in to comment.