Skip to content

Commit

Permalink
code cleanup by Rider
Browse files Browse the repository at this point in the history
  • Loading branch information
kookxiang committed May 21, 2023
1 parent 39b4801 commit 780e3f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.Bangumi/BangumiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public async Task<List<PersonInfo>> GetSubjectPersonInfos(int id, CancellationTo
{
return await SendRequest<User>("https://api.bgm.tv/v0/me", accessToken, token);
}

public async Task<DataList<EpisodeCollectionInfo>?> GetEpisodeCollectionInfo(string accessToken, int subjectId, int episodeType, CancellationToken token)
{
return await SendRequest<DataList<EpisodeCollectionInfo>>($"https://api.bgm.tv/v0/users/-/collections/{subjectId}/episodes?episode_type={episodeType}", accessToken, token);
Expand All @@ -211,7 +211,7 @@ public async Task UpdateCollectionStatus(string accessToken, int subjectId, Coll
{
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
16 changes: 4 additions & 12 deletions Jellyfin.Plugin.Bangumi/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public static class Extensions
}

/// <summary>
/// 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
/// </summary>
public static class PathExtensions
{
/// <summary>
/// Gets the attribute value.
/// Gets the attribute value.
/// </summary>
/// <param name="str">The STR.</param>
/// <param name="attribute">The attrib.</param>
Expand All @@ -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);

Expand All @@ -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..];
Expand Down
10 changes: 5 additions & 5 deletions Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =>
Expand Down
2 changes: 0 additions & 2 deletions Jellyfin.Plugin.Bangumi/Providers/SeriesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public async Task<MetadataResult<Series>> 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))
{
Expand Down

0 comments on commit 780e3f1

Please sign in to comment.