Skip to content

Commit

Permalink
fix: distinct images
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Oct 21, 2024
1 parent 40b09c7 commit c77f76a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
30 changes: 29 additions & 1 deletion Shoko.Server/Models/SVR_AniDB_Anime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ public IReadOnlyList<IImageMetadata> GetImages(ImageEntityType? entityType = nul
}
foreach (var xref in TmdbShowCrossReferences)
images.AddRange(xref.GetImages(entityType, preferredImages));
foreach (var xref in TmdbSeasonCrossReferences)
images.AddRange(xref.GetImages(entityType, preferredImages));
foreach (var xref in TmdbMovieCrossReferences)
images.AddRange(xref.GetImages(entityType, preferredImages));

return images;
return images
.DistinctBy(image => (image.ImageType, image.Source, image.ID))
.ToList();
}

#endregion
Expand Down Expand Up @@ -299,6 +303,30 @@ public IReadOnlyList<TMDB_Image> TmdbShowBackdrops
.SelectMany(xref => RepoFactory.TMDB_Image.GetByTmdbShowIDAndType(xref.TmdbShowID, ImageEntityType.Backdrop))
.ToList();

public IReadOnlyList<CrossRef_AniDB_TMDB_Episode> TmdbEpisodeCrossReferences => RepoFactory.CrossRef_AniDB_TMDB_Episode.GetByAnidbAnimeID(AnimeID);

public IReadOnlyList<CrossRef_AniDB_TMDB_Episode> GetTmdbEpisodeCrossReferences(int? tmdbShowId = null) => tmdbShowId.HasValue
? RepoFactory.CrossRef_AniDB_TMDB_Episode.GetOnlyByAnidbAnimeAndTmdbShowIDs(AnimeID, tmdbShowId.Value)
: RepoFactory.CrossRef_AniDB_TMDB_Episode.GetByAnidbAnimeID(AnimeID);

public IReadOnlyList<CrossRef_AniDB_TMDB_Season> TmdbSeasonCrossReferences =>
TmdbEpisodeCrossReferences
.Select(xref => xref.TmdbSeasonCrossReference)
.WhereNotNull()
.DistinctBy(xref => xref.TmdbSeasonID)
.ToList();

public IReadOnlyList<TMDB_Season> TmdbSeasons => TmdbSeasonCrossReferences
.Select(xref => xref.TmdbSeason)
.WhereNotNull()
.ToList();

public IReadOnlyList<CrossRef_AniDB_TMDB_Season> GetTmdbSeasonCrossReferences(int? tmdbShowId = null) =>
GetTmdbEpisodeCrossReferences(tmdbShowId)
.Select(xref => xref.TmdbSeasonCrossReference)
.WhereNotNull().Distinct()
.ToList();


public IReadOnlyList<CrossRef_AniDB_TMDB_Movie> TmdbMovieCrossReferences
=> RepoFactory.CrossRef_AniDB_TMDB_Movie.GetByAnidbAnimeID(AnimeID);
Expand Down
4 changes: 3 additions & 1 deletion Shoko.Server/Models/SVR_AniDB_Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public IReadOnlyList<IImageMetadata> GetImages(ImageEntityType? entityType = nul
foreach (var tmdbMovie in TmdbMovies)
images.AddRange(tmdbMovie.GetImages(entityType, preferredImages));

return images;
return images
.DistinctBy(image => (image.ImageType, image.Source, image.ID))
.ToList();
}

#endregion
Expand Down
4 changes: 3 additions & 1 deletion Shoko.Server/Models/SVR_AnimeEpisode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ public IReadOnlyList<IImageMetadata> GetImages(ImageEntityType? entityType = nul
foreach (var xref in TmdbMovieCrossReferences)
images.AddRange(xref.GetImages(entityType, preferredImages));

return images;
return images
.DistinctBy(image => (image.ImageType, image.Source, image.ID))
.ToList();
}

#endregion
Expand Down
4 changes: 3 additions & 1 deletion Shoko.Server/Models/SVR_AnimeSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ public IReadOnlyList<IImageMetadata> GetImages(ImageEntityType? entityType = nul
foreach (var xref in TmdbMovieCrossReferences.DistinctBy(xref => xref.TmdbMovieID))
images.AddRange(xref.GetImages(entityType, preferredImages));

return images;
return images
.DistinctBy(image => (image.ImageType, image.Source, image.ID))
.ToList();
}

#endregion
Expand Down

0 comments on commit c77f76a

Please sign in to comment.