From 780e3f11b3e07cae1a92c4f36eafd905edf92314 Mon Sep 17 00:00:00 2001 From: kookxiang Date: Mon, 22 May 2023 02:06:56 +0800 Subject: [PATCH] code cleanup by Rider --- Jellyfin.Plugin.Bangumi/BangumiApi.cs | 4 ++-- Jellyfin.Plugin.Bangumi/Extensions.cs | 16 ++++------------ Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs | 10 +++++----- .../Providers/SeriesProvider.cs | 2 -- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Jellyfin.Plugin.Bangumi/BangumiApi.cs b/Jellyfin.Plugin.Bangumi/BangumiApi.cs index 8e7b7f2..1738fe0 100644 --- a/Jellyfin.Plugin.Bangumi/BangumiApi.cs +++ b/Jellyfin.Plugin.Bangumi/BangumiApi.cs @@ -194,7 +194,7 @@ public async Task> GetSubjectPersonInfos(int id, CancellationTo { return await SendRequest("https://api.bgm.tv/v0/me", accessToken, token); } - + public async Task?> GetEpisodeCollectionInfo(string accessToken, int subjectId, int episodeType, CancellationToken token) { return await SendRequest>($"https://api.bgm.tv/v0/users/-/collections/{subjectId}/episodes?episode_type={episodeType}", accessToken, token); @@ -211,7 +211,7 @@ public async Task UpdateCollectionStatus(string accessToken, int subjectId, Coll { return await SendRequest($"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}"); diff --git a/Jellyfin.Plugin.Bangumi/Extensions.cs b/Jellyfin.Plugin.Bangumi/Extensions.cs index 494eedc..7cda444 100644 --- a/Jellyfin.Plugin.Bangumi/Extensions.cs +++ b/Jellyfin.Plugin.Bangumi/Extensions.cs @@ -12,13 +12,13 @@ public static class Extensions } /// -/// Class providing extension methods for working with paths. -/// From: https://github.com/jellyfin/jellyfin/blob/master/Emby.Server.Implementations/Library/PathExtensions.cs#L10 +/// Class providing extension methods for working with paths. +/// From: https://github.com/jellyfin/jellyfin/blob/master/Emby.Server.Implementations/Library/PathExtensions.cs#L10 /// public static class PathExtensions { /// - /// Gets the attribute value. + /// Gets the attribute value. /// /// The STR. /// The attrib. @@ -27,18 +27,12 @@ public static class PathExtensions public static string? GetAttributeValue(this string? str, string attribute) { if (string.IsNullOrEmpty(str)) - { return null; - } if (str.Length == 0) - { throw new ArgumentException("String can't be empty.", nameof(str)); - } if (attribute.Length == 0) - { throw new ArgumentException("String can't be empty.", nameof(attribute)); - } var attributeIndex = str.IndexOf(attribute, StringComparison.OrdinalIgnoreCase); @@ -54,9 +48,7 @@ public static class PathExtensions var closingIndex = str[attributeEnd..].IndexOf(']'); // Must be at least 1 character before the closing bracket. if (closingIndex > 1) - { - return str[(attributeEnd + 1)..(attributeEnd + closingIndex)].Trim().ToString(); - } + return str[(attributeEnd + 1)..(attributeEnd + closingIndex)].Trim(); } str = str[attributeEnd..]; diff --git a/Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs b/Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs index 9da1ebd..91357b6 100644 --- a/Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs +++ b/Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs @@ -130,8 +130,8 @@ private async Task ReportPlaybackStatus(BaseItem item, Guid userId, bool played) if (item.GetUserDataKeys().Intersect(GetPlaybackHistory(userId)).Any()) { - var episodeStatus = await _api.GetEpisodeStatus(user.AccessToken, episodeId, CancellationToken.None); - if (played && episodeStatus is {Type: EpisodeCollectionType.Watched}) + 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; @@ -190,17 +190,17 @@ private async Task ReportPlaybackStatus(BaseItem item, Guid userId, bool played) _log.LogError(e, "report playback status failed"); } } - + // report subject status watched if (played && item is not Book) { // skip if episode type not normal var episode = await _api.GetEpisode(episodeId, CancellationToken.None); - if (episode is {Type: EpisodeType.Normal}) + if (episode is { Type: EpisodeType.Normal }) { // check each episode status var epList = await _api.GetEpisodeCollectionInfo(user.AccessToken, subjectId, (int)EpisodeType.Normal, CancellationToken.None); - if (epList is {Total: > 0}) + if (epList is { Total: > 0 }) { var subjectPlayed = true; epList.Data.ForEach(ep => diff --git a/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs b/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs index b367c41..a235299 100644 --- a/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs +++ b/Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs @@ -39,9 +39,7 @@ public async Task> GetMetadata(SeriesInfo info, Cancellat var bangumiId = baseName.GetAttributeValue("bangumi"); if (!string.IsNullOrEmpty(bangumiId) && !info.HasProviderId(Constants.ProviderName)) - { info.SetProviderId(Constants.ProviderName, bangumiId); - } if (int.TryParse(info.ProviderIds.GetOrDefault(Constants.ProviderName), out var subjectId)) {