Skip to content

Commit

Permalink
use jellyfin builtin rating compare
Browse files Browse the repository at this point in the history
  • Loading branch information
kookxiang committed Jan 22, 2023
1 parent d8c2916 commit 0dfa6b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PluginConfiguration : BasePluginConfiguration

public bool ReportPlaybackStatusToBangumi { get; set; } = true;

public bool SkipNSFWPlaybackReport { get; set; } = false;
public bool SkipNSFWPlaybackReport { get; set; } = true;

public bool ReportManualStatusChangeToBangumi { get; set; } = false;

Expand Down
21 changes: 19 additions & 2 deletions Jellyfin.Plugin.Bangumi/PlaybackScrobbler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,30 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using Microsoft.Extensions.Logging;
using CollectionType = Jellyfin.Plugin.Bangumi.Model.CollectionType;

namespace Jellyfin.Plugin.Bangumi;

public class PlaybackScrobbler : IServerEntryPoint
{
// https://github.com/jellyfin/jellyfin/blob/master/Emby.Server.Implementations/Localization/Ratings/jp.csv
// https://github.com/jellyfin/jellyfin/blob/master/Emby.Server.Implementations/Localization/Ratings/us.csv
private const int RatingNSFW = 10;

private static readonly Dictionary<Guid, HashSet<string>> Store = new();
private readonly BangumiApi _api;
private readonly ILocalizationManager _localizationManager;
private readonly ILogger<PlaybackScrobbler> _log;

private readonly OAuthStore _store;
private readonly IUserDataManager _userDataManager;

public PlaybackScrobbler(IUserManager userManager, IUserDataManager userDataManager, OAuthStore store, BangumiApi api, ILogger<PlaybackScrobbler> log)
public PlaybackScrobbler(IUserManager userManager, IUserDataManager userDataManager, ILocalizationManager localizationManager, OAuthStore store, BangumiApi api, ILogger<PlaybackScrobbler> log)
{
_userDataManager = userDataManager;
_localizationManager = localizationManager;
_store = store;
_api = api;
_log = log;
Expand Down Expand Up @@ -143,7 +150,17 @@ private async Task ReportPlaybackStatus(BaseItem item, Guid userId, bool played)
subjectId = episode.ParentId;
}

if (item.OfficialRating is "X" or "XXX" && Configuration.SkipNSFWPlaybackReport)
var ratingLevel = _localizationManager.GetRatingLevel(item.OfficialRating);
if (ratingLevel == null)
{
foreach (var parent in item.GetParents())
{
ratingLevel = _localizationManager.GetRatingLevel(parent.OfficialRating);
if (ratingLevel != null) break;
}
}

if (ratingLevel >= RatingNSFW && Configuration.SkipNSFWPlaybackReport)
{
_log.LogInformation("item #{Name} marked as NSFW, skipped", item.Name);
return;
Expand Down

0 comments on commit 0dfa6b1

Please sign in to comment.