diff --git a/Shoko.Server/API/v3/Controllers/SeriesController.cs b/Shoko.Server/API/v3/Controllers/SeriesController.cs index 691bc33d2..ea8f90979 100644 --- a/Shoko.Server/API/v3/Controllers/SeriesController.cs +++ b/Shoko.Server/API/v3/Controllers/SeriesController.cs @@ -462,18 +462,20 @@ public ActionResult> GetAnidbRelationsBySeriesID([FromRoute /// Limits the number of results per page. Set to 0 to disable the limit. /// Page number. /// If enabled will show recommendations across all the anidb available in Shoko, if disabled will only show for the user's collection. + /// Include restricted (H) series. /// Start date to use if recommending for a watch period. Only setting the and not will result in using the watch history from the start date to the present date. /// End date to use if recommending for a watch period. /// Minumum approval percentage for similar animes. /// [HttpGet("AniDB/RecommendedForYou")] public ActionResult> GetAnimeRecommendedForYou( - [FromQuery] [Range(0, 100)] int pageSize = 30, - [FromQuery] [Range(1, int.MaxValue)] int page = 1, + [FromQuery, Range(0, 100)] int pageSize = 30, + [FromQuery, Range(1, int.MaxValue)] int page = 1, [FromQuery] bool showAll = false, + [FromQuery] bool includeRestricted = false, [FromQuery] DateTime? startDate = null, [FromQuery] DateTime? endDate = null, - [FromQuery] [Range(0, 1)] double? approval = null + [FromQuery, Range(0, 1)] double? approval = null ) { startDate = startDate?.ToLocalTime(); @@ -497,9 +499,9 @@ [FromQuery] [Range(0, 1)] double? approval = null return ValidationProblem(ModelState); var user = User; - var watchedAnimeList = GetWatchedAnimeForPeriod(user, startDate, endDate); + var watchedAnimeList = GetWatchedAnimeForPeriod(user, includeRestricted, startDate, endDate); var unwatchedAnimeDict = GetUnwatchedAnime(user, showAll, - !startDate.HasValue && !endDate.HasValue ? watchedAnimeList : null); + includeRestricted, !startDate.HasValue && !endDate.HasValue ? watchedAnimeList : null); return watchedAnimeList .SelectMany(anime => { @@ -533,11 +535,15 @@ [FromQuery] [Range(0, 1)] double? approval = null /// is omitted then it will return all watched anime for the . /// /// The user to get the watched anime for. + /// Include restricted (H) series. /// The start date of the period. /// The end date of the period. /// The watched anime for the user. [NonAction] - private List GetWatchedAnimeForPeriod(SVR_JMMUser user, DateTime? startDate = null, + private List GetWatchedAnimeForPeriod( + SVR_JMMUser user, + bool includeRestricted = false, + DateTime? startDate = null, DateTime? endDate = null) { startDate = startDate?.ToLocalTime(); @@ -566,7 +572,7 @@ private List GetWatchedAnimeForPeriod(SVR_JMMUser user, DateTim .Where(episode => episode != null) .DistinctBy(episode => episode.AnimeSeriesID) .Select(episode => episode.GetAnimeSeries().GetAnime()) - .Where(anime => user.AllowedAnime(anime)) + .Where(anime => user.AllowedAnime(anime) && (includeRestricted || anime.Restricted != 1)) .ToList(); } @@ -575,10 +581,14 @@ private List GetWatchedAnimeForPeriod(SVR_JMMUser user, DateTim /// /// The user to get the unwatched anime for. /// If true will get a list of all available anime in shoko, regardless of if it's part of the user's collection or not. + /// Include restricted (H) series. /// Optional. Re-use an existing list of the watched anime. /// The unwatched anime for the user. [NonAction] - private Dictionary GetUnwatchedAnime(SVR_JMMUser user, bool showAll, + private Dictionary GetUnwatchedAnime( + SVR_JMMUser user, + bool showAll, + bool includeRestricted = false, IEnumerable watchedAnime = null) { // Get all watched series (reuse if date is not set) @@ -589,14 +599,16 @@ private List GetWatchedAnimeForPeriod(SVR_JMMUser user, DateTim if (showAll) { return RepoFactory.AniDB_Anime.GetAll() - .Where(anime => user.AllowedAnime(anime) && !watchedSeriesSet.Contains(anime.AnimeID)) + .Where(anime => user.AllowedAnime(anime) && !watchedSeriesSet.Contains(anime.AnimeID) && (includeRestricted || anime.Restricted != 1)) .ToDictionary(anime => anime.AnimeID, anime => (anime, null)); } return RepoFactory.AnimeSeries.GetAll() .Where(series => user.AllowedSeries(series) && !watchedSeriesSet.Contains(series.AniDB_ID)) - .ToDictionary(series => series.AniDB_ID, series => (series.GetAnime(), series)); + .Select(series => (anime: series.GetAnime(), series)) + .Where(tuple => includeRestricted || tuple.anime.Restricted != 1) + .ToDictionary(tuple => tuple.anime.AnimeID); } #endregion