From 4ae28f25941ecc461087856ddb028863a3a40ec8 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 31 Jul 2021 14:18:02 +0200 Subject: [PATCH] LibraryRepository: Adding more tests --- Kyoo.Common/Controllers/IThumbnailsManager.cs | 2 +- Kyoo.Common/Models/LibraryItem.cs | 2 +- Kyoo.Common/Models/Resources/Collection.cs | 2 +- Kyoo.Common/Models/Resources/Episode.cs | 2 +- .../Resources/Interfaces/IThumbnails.cs | 4 +- Kyoo.Common/Models/Resources/People.cs | 2 +- Kyoo.Common/Models/Resources/Provider.cs | 4 +- Kyoo.Common/Models/Resources/Season.cs | 2 +- Kyoo.Common/Models/Resources/Show.cs | 8 +- .../Database/SpecificTests/LibraryTests.cs | 107 ++++++++++++++++++ Kyoo.Tests/Database/TestSample.cs | 63 +++++++---- Kyoo.Tests/Identifier/Tvdb/ConvertorTests.cs | 12 +- .../Convertors/CollectionConvertors.cs | 8 +- .../Convertors/EpisodeConvertors.cs | 2 +- Kyoo.TheMovieDb/Convertors/MovieConvertors.cs | 10 +- .../Convertors/PeopleConvertors.cs | 11 +- .../Convertors/SeasonConvertors.cs | 2 +- Kyoo.TheMovieDb/Convertors/ShowConvertors.cs | 10 +- Kyoo.TheMovieDb/ProviderTmdb.cs | 2 +- Kyoo.TheTvdb/Convertors.cs | 10 +- Kyoo.TheTvdb/ProviderTvdb.cs | 2 +- .../Repositories/LibraryRepository.cs | 31 ++--- .../Repositories/ProviderRepository.cs | 1 - Kyoo/Controllers/ThumbnailsManager.cs | 6 +- Kyoo/Views/EpisodeApi.cs | 4 +- Kyoo/Views/PeopleApi.cs | 4 +- Kyoo/Views/ProviderApi.cs | 4 +- Kyoo/Views/SeasonApi.cs | 4 +- Kyoo/Views/ShowApi.cs | 6 +- 29 files changed, 224 insertions(+), 103 deletions(-) diff --git a/Kyoo.Common/Controllers/IThumbnailsManager.cs b/Kyoo.Common/Controllers/IThumbnailsManager.cs index 023e566c..aac09210 100644 --- a/Kyoo.Common/Controllers/IThumbnailsManager.cs +++ b/Kyoo.Common/Controllers/IThumbnailsManager.cs @@ -30,7 +30,7 @@ namespace Kyoo.Controllers /// Retrieve the local path of the poster of the given item. /// /// The item to retrieve the poster from. - /// The ID of the image. See for values. + /// The ID of the image. See for values. /// The type of the item /// If the type does not have a poster /// The path of the poster for the given resource (it might or might not exists). diff --git a/Kyoo.Common/Models/LibraryItem.cs b/Kyoo.Common/Models/LibraryItem.cs index 88fd799a..18680b9e 100644 --- a/Kyoo.Common/Models/LibraryItem.cs +++ b/Kyoo.Common/Models/LibraryItem.cs @@ -63,7 +63,7 @@ namespace Kyoo.Models /// This can be disabled using the internal query flag. /// [SerializeAs("{HOST}/api/{Type:l}/{Slug}/poster")] - public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster); + public string Poster => Images?.GetValueOrDefault(Models.Images.Poster); /// /// The type of this item (ether a collection, a show or a movie). diff --git a/Kyoo.Common/Models/Resources/Collection.cs b/Kyoo.Common/Models/Resources/Collection.cs index 50a4ede8..20cc481b 100644 --- a/Kyoo.Common/Models/Resources/Collection.cs +++ b/Kyoo.Common/Models/Resources/Collection.cs @@ -31,7 +31,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/collection/{Slug}/poster")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster); + public string Poster => Images?.GetValueOrDefault(Models.Images.Poster); /// /// The description of this collection. diff --git a/Kyoo.Common/Models/Resources/Episode.cs b/Kyoo.Common/Models/Resources/Episode.cs index 3f29088f..eddb86ba 100644 --- a/Kyoo.Common/Models/Resources/Episode.cs +++ b/Kyoo.Common/Models/Resources/Episode.cs @@ -113,7 +113,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/episodes/{Slug}/thumb")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Thumb => Images?.GetValueOrDefault(Thumbnails.Thumbnail); + public string Thumb => Images?.GetValueOrDefault(Models.Images.Thumbnail); /// /// The title of this episode. diff --git a/Kyoo.Common/Models/Resources/Interfaces/IThumbnails.cs b/Kyoo.Common/Models/Resources/Interfaces/IThumbnails.cs index 074751c4..ba4999de 100644 --- a/Kyoo.Common/Models/Resources/Interfaces/IThumbnails.cs +++ b/Kyoo.Common/Models/Resources/Interfaces/IThumbnails.cs @@ -13,7 +13,7 @@ namespace Kyoo.Models /// The string value should be a path supported by the . /// /// - /// An arbitrary index should not be used, instead use indexes from + /// An arbitrary index should not be used, instead use indexes from /// public Dictionary Images { get; set; } @@ -23,7 +23,7 @@ namespace Kyoo.Models /// /// A class containing constant values for images. To be used as index of a . /// - public static class Thumbnails + public static class Images { /// /// A poster is a 9/16 format image with the cover of the resource. diff --git a/Kyoo.Common/Models/Resources/People.cs b/Kyoo.Common/Models/Resources/People.cs index ff6fd576..7bd59620 100644 --- a/Kyoo.Common/Models/Resources/People.cs +++ b/Kyoo.Common/Models/Resources/People.cs @@ -30,7 +30,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/people/{Slug}/poster")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster); + public string Poster => Images?.GetValueOrDefault(Models.Images.Poster); /// [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } diff --git a/Kyoo.Common/Models/Resources/Provider.cs b/Kyoo.Common/Models/Resources/Provider.cs index db118de2..31b87f3f 100644 --- a/Kyoo.Common/Models/Resources/Provider.cs +++ b/Kyoo.Common/Models/Resources/Provider.cs @@ -32,7 +32,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/providers/{Slug}/logo")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Logo => Images?.GetValueOrDefault(Thumbnails.Logo); + public string Logo => Images?.GetValueOrDefault(Models.Images.Logo); /// /// The list of libraries that uses this provider. @@ -56,7 +56,7 @@ namespace Kyoo.Models Name = name; Images = new Dictionary { - [Thumbnails.Logo] = logo + [Models.Images.Logo] = logo }; } } diff --git a/Kyoo.Common/Models/Resources/Season.cs b/Kyoo.Common/Models/Resources/Season.cs index 2cfadfb9..2c5d59eb 100644 --- a/Kyoo.Common/Models/Resources/Season.cs +++ b/Kyoo.Common/Models/Resources/Season.cs @@ -85,7 +85,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/seasons/{Slug}/thumb")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster); + public string Poster => Images?.GetValueOrDefault(Models.Images.Poster); /// [EditableRelation] [LoadableRelation] public ICollection ExternalIDs { get; set; } diff --git a/Kyoo.Common/Models/Resources/Show.cs b/Kyoo.Common/Models/Resources/Show.cs index 50059692..03c86e5e 100644 --- a/Kyoo.Common/Models/Resources/Show.cs +++ b/Kyoo.Common/Models/Resources/Show.cs @@ -47,7 +47,7 @@ namespace Kyoo.Models /// /// TODO for now, this is set to a youtube url. It should be cached and converted to a local file. [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string TrailerUrl => Images?.GetValueOrDefault(Thumbnails.Trailer); + public string TrailerUrl => Images?.GetValueOrDefault(Models.Images.Trailer); /// /// The date this show started airing. It can be null if this is unknown. @@ -71,7 +71,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/shows/{Slug}/poster")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster); + public string Poster => Images?.GetValueOrDefault(Models.Images.Poster); /// /// The path of this show's logo. @@ -80,7 +80,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/shows/{Slug}/logo")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Logo => Images?.GetValueOrDefault(Thumbnails.Logo); + public string Logo => Images?.GetValueOrDefault(Models.Images.Logo); /// /// The path of this show's backdrop. @@ -89,7 +89,7 @@ namespace Kyoo.Models /// [SerializeAs("{HOST}/api/shows/{Slug}/backdrop")] [Obsolete("Use Images instead of this, this is only kept for the API response.")] - public string Backdrop => Images?.GetValueOrDefault(Thumbnails.Thumbnail); + public string Backdrop => Images?.GetValueOrDefault(Models.Images.Thumbnail); /// /// True if this show represent a movie, false otherwise. diff --git a/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs b/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs index 079f50cf..12449b5e 100644 --- a/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs +++ b/Kyoo.Tests/Database/SpecificTests/LibraryTests.cs @@ -1,7 +1,10 @@ +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Kyoo.Controllers; using Kyoo.Models; +using Microsoft.EntityFrameworkCore; using Xunit; using Xunit.Abstractions; @@ -36,6 +39,39 @@ namespace Kyoo.Tests.Database _repository = Repositories.LibraryManager.LibraryRepository; } + [Fact] + public async Task CreateWithoutPathTest() + { + Library library = TestSample.GetNew(); + library.Paths = null; + await Assert.ThrowsAsync(() => _repository.Create(library)); + } + + [Fact] + public async Task CreateWithEmptySlugTest() + { + Library library = TestSample.GetNew(); + library.Slug = ""; + await Assert.ThrowsAsync(() => _repository.Create(library)); + } + + [Fact] + public async Task CreateWithNumberSlugTest() + { + Library library = TestSample.GetNew(); + library.Slug = "2"; + Library ret = await _repository.Create(library); + Assert.Equal("2!", library.Slug); + } + + [Fact] + public async Task CreateWithoutNameTest() + { + Library library = TestSample.GetNew(); + library.Name = null; + await Assert.ThrowsAsync(() => _repository.Create(library)); + } + [Fact] public async Task CreateWithProvider() { @@ -47,5 +83,76 @@ namespace Kyoo.Tests.Database Assert.Equal(1, retrieved.Providers.Count); Assert.Equal(TestSample.Get().Slug, retrieved.Providers.First().Slug); } + + [Fact] + public async Task EditTest() + { + Library value = await _repository.Get(TestSample.Get().Slug); + value.Paths = new [] {"/super", "/test"}; + value.Name = "New Title"; + Library edited = await _repository.Edit(value, false); + + await using DatabaseContext database = Repositories.Context.New(); + Library show = await database.Libraries.FirstAsync(); + + KAssert.DeepEqual(show, edited); + } + + [Fact] + public async Task EditProvidersTest() + { + Library value = await _repository.Get(TestSample.Get().Slug); + value.Providers = new[] + { + TestSample.GetNew() + }; + Library edited = await _repository.Edit(value, false); + + await using DatabaseContext database = Repositories.Context.New(); + Library show = await database.Libraries + .Include(x => x.Providers) + .FirstAsync(); + + show.Providers.ForEach(x => x.Libraries = null); + edited.Providers.ForEach(x => x.Libraries = null); + KAssert.DeepEqual(show, edited); + } + + [Fact] + public async Task AddProvidersTest() + { + Library value = await _repository.Get(TestSample.Get().Slug); + await Repositories.LibraryManager.Load(value, x => x.Providers); + value.Providers.Add(TestSample.GetNew()); + Library edited = await _repository.Edit(value, false); + + await using DatabaseContext database = Repositories.Context.New(); + Library show = await database.Libraries + .Include(x => x.Providers) + .FirstAsync(); + + show.Providers.ForEach(x => x.Libraries = null); + edited.Providers.ForEach(x => x.Libraries = null); + KAssert.DeepEqual(show, edited); + } + + [Theory] + [InlineData("test")] + [InlineData("super")] + [InlineData("title")] + [InlineData("TiTlE")] + [InlineData("SuPeR")] + public async Task SearchTest(string query) + { + Library value = new() + { + Slug = "super-test", + Name = "This is a test title", + Paths = new [] {"path"} + }; + await _repository.Create(value); + ICollection ret = await _repository.Search(query); + KAssert.DeepEqual(value, ret.First()); + } } } \ No newline at end of file diff --git a/Kyoo.Tests/Database/TestSample.cs b/Kyoo.Tests/Database/TestSample.cs index a3e113bf..d8b06333 100644 --- a/Kyoo.Tests/Database/TestSample.cs +++ b/Kyoo.Tests/Database/TestSample.cs @@ -31,13 +31,26 @@ namespace Kyoo.Tests EndAir = new DateTime(2011, 1, 1), Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, IsMovie = false, Studio = null } + }, + { + typeof(Provider), + () => new Provider + { + ID = 2, + Slug = "new-provider", + Name = "Provider NewSample", + Images = new Dictionary + { + [Images.Logo] = "logo" + } + } } }; @@ -64,7 +77,7 @@ namespace Kyoo.Tests Overview = "A nice collection for tests", Images = new Dictionary { - [Thumbnails.Poster] = "Poster" + [Images.Poster] = "Poster" } } }, @@ -90,9 +103,9 @@ namespace Kyoo.Tests EndAir = new DateTime(2011, 1, 1), Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, IsMovie = false, Studio = null @@ -112,9 +125,9 @@ namespace Kyoo.Tests EndDate = new DateTime(2020, 07, 05), Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, } }, @@ -132,9 +145,9 @@ namespace Kyoo.Tests Path = "/home/kyoo/anohana-s1e1", Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, Title = "Episode 1", Overview = "Summary of the first episode", @@ -168,9 +181,9 @@ namespace Kyoo.Tests Name = "The Actor", Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, } }, @@ -201,9 +214,9 @@ namespace Kyoo.Tests Name = "The TVDB", Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "path/tvdb.svg", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "path/tvdb.svg", + [Images.Thumbnail] = "Thumbnail" } } }, @@ -306,9 +319,9 @@ namespace Kyoo.Tests Path = "/home/kyoo/anohana-3", Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, Title = "Episode 3", Overview = "Summary of the third absolute episode", @@ -326,9 +339,9 @@ namespace Kyoo.Tests Path = "/home/kyoo/john-wick", Images = new Dictionary { - [Thumbnails.Poster] = "Poster", - [Thumbnails.Logo] = "Logo", - [Thumbnails.Thumbnail] = "Thumbnail" + [Images.Poster] = "Poster", + [Images.Logo] = "Logo", + [Images.Thumbnail] = "Thumbnail" }, Title = "John wick", Overview = "A movie episode test", diff --git a/Kyoo.Tests/Identifier/Tvdb/ConvertorTests.cs b/Kyoo.Tests/Identifier/Tvdb/ConvertorTests.cs index 35e389b6..58ce0a8c 100644 --- a/Kyoo.Tests/Identifier/Tvdb/ConvertorTests.cs +++ b/Kyoo.Tests/Identifier/Tvdb/ConvertorTests.cs @@ -32,7 +32,7 @@ namespace Kyoo.Tests.Identifier.Tvdb Assert.Equal("Aliases", show.Aliases[0]); Assert.Equal("overview", show.Overview); Assert.Equal(new DateTime(2021, 7, 23), show.StartAir); - Assert.Equal("https://www.thetvdb.com/poster", show.Poster); + Assert.Equal("https://www.thetvdb.com/poster", show.Images[Images.Poster]); Assert.Single(show.ExternalIDs); Assert.Equal("5", show.ExternalIDs.First().DataID); Assert.Equal(provider, show.ExternalIDs.First().Provider); @@ -63,7 +63,7 @@ namespace Kyoo.Tests.Identifier.Tvdb Assert.Equal("Aliases", show.Aliases[0]); Assert.Equal("overview", show.Overview); Assert.Null(show.StartAir); - Assert.Equal("https://www.thetvdb.com/poster", show.Poster); + Assert.Equal("https://www.thetvdb.com/poster", show.Images[Images.Poster]); Assert.Single(show.ExternalIDs); Assert.Equal("5", show.ExternalIDs.First().DataID); Assert.Equal(provider, show.ExternalIDs.First().Provider); @@ -100,8 +100,8 @@ namespace Kyoo.Tests.Identifier.Tvdb Assert.Equal("Aliases", show.Aliases[0]); Assert.Equal("overview", show.Overview); Assert.Equal(new DateTime(2021, 7, 23), show.StartAir); - Assert.Equal("https://www.thetvdb.com/banners/poster", show.Poster); - Assert.Equal("https://www.thetvdb.com/banners/fanart", show.Backdrop); + Assert.Equal("https://www.thetvdb.com/banners/poster", show.Images[Images.Poster]); + Assert.Equal("https://www.thetvdb.com/banners/fanart", show.Images[Images.Thumbnail]); Assert.Single(show.ExternalIDs); Assert.Equal("5", show.ExternalIDs.First().DataID); Assert.Equal(provider, show.ExternalIDs.First().Provider); @@ -130,7 +130,7 @@ namespace Kyoo.Tests.Identifier.Tvdb Assert.Equal("name", people.Slug); Assert.Equal("Name", people.People.Name); Assert.Equal("role", people.Role); - Assert.Equal("https://www.thetvdb.com/banners/image", people.People.Poster); + Assert.Equal("https://www.thetvdb.com/banners/image", people.People.Images[Images.Poster]); } [Fact] @@ -154,7 +154,7 @@ namespace Kyoo.Tests.Identifier.Tvdb Assert.Equal(3, episode.EpisodeNumber); Assert.Equal(23, episode.AbsoluteNumber); Assert.Equal("overview", episode.Overview); - Assert.Equal("https://www.thetvdb.com/banners/thumb", episode.Thumb); + Assert.Equal("https://www.thetvdb.com/banners/thumb", episode.Images[Images.Thumbnail]); } } } \ No newline at end of file diff --git a/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs b/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs index c0108b81..c5ab7104 100644 --- a/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/CollectionConvertors.cs @@ -24,10 +24,10 @@ namespace Kyoo.TheMovieDb Overview = collection.Overview, Images = new Dictionary { - [Thumbnails.Poster] = collection.PosterPath != null + [Images.Poster] = collection.PosterPath != null ? $"https://image.tmdb.org/t/p/original{collection.PosterPath}" : null, - [Thumbnails.Thumbnail] = collection.BackdropPath != null + [Images.Thumbnail] = collection.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{collection.BackdropPath}" : null }, @@ -57,10 +57,10 @@ namespace Kyoo.TheMovieDb Name = collection.Name, Images = new Dictionary { - [Thumbnails.Poster] = collection.PosterPath != null + [Images.Poster] = collection.PosterPath != null ? $"https://image.tmdb.org/t/p/original{collection.PosterPath}" : null, - [Thumbnails.Thumbnail] = collection.BackdropPath != null + [Images.Thumbnail] = collection.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{collection.BackdropPath}" : null }, diff --git a/Kyoo.TheMovieDb/Convertors/EpisodeConvertors.cs b/Kyoo.TheMovieDb/Convertors/EpisodeConvertors.cs index 97512aec..d1dd499b 100644 --- a/Kyoo.TheMovieDb/Convertors/EpisodeConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/EpisodeConvertors.cs @@ -27,7 +27,7 @@ namespace Kyoo.TheMovieDb ReleaseDate = episode.AirDate, Images = new Dictionary { - [Thumbnails.Thumbnail] = episode.StillPath != null + [Images.Thumbnail] = episode.StillPath != null ? $"https://image.tmdb.org/t/p/original{episode.StillPath}" : null }, diff --git a/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs b/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs index 06ea3108..6a0cf9ba 100644 --- a/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/MovieConvertors.cs @@ -30,13 +30,13 @@ namespace Kyoo.TheMovieDb EndAir = movie.ReleaseDate, Images = new Dictionary { - [Thumbnails.Poster] = movie.PosterPath != null + [Images.Poster] = movie.PosterPath != null ? $"https://image.tmdb.org/t/p/original{movie.PosterPath}" : null, - [Thumbnails.Thumbnail] = movie.BackdropPath != null + [Images.Thumbnail] = movie.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{movie.BackdropPath}" : null, - [Thumbnails.Trailer] = movie.Videos?.Results + [Images.Trailer] = movie.Videos?.Results .Where(x => x.Type is "Trailer" or "Teaser" && x.Site == "YouTube") .Select(x => "https://www.youtube.com/watch?v=" + x.Key).FirstOrDefault(), }, @@ -78,10 +78,10 @@ namespace Kyoo.TheMovieDb EndAir = movie.ReleaseDate, Images = new Dictionary { - [Thumbnails.Poster] = movie.PosterPath != null + [Images.Poster] = movie.PosterPath != null ? $"https://image.tmdb.org/t/p/original{movie.PosterPath}" : null, - [Thumbnails.Thumbnail] = movie.BackdropPath != null + [Images.Thumbnail] = movie.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{movie.BackdropPath}" : null, }, diff --git a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs index 27460cf0..b3d47410 100644 --- a/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/PeopleConvertors.cs @@ -3,6 +3,7 @@ using Kyoo.Models; using TMDbLib.Objects.General; using TMDbLib.Objects.People; using TMDbLib.Objects.Search; +using Images = Kyoo.Models.Images; using TvCast = TMDbLib.Objects.TvShows.Cast; using MovieCast = TMDbLib.Objects.Movies.Cast; @@ -29,7 +30,7 @@ namespace Kyoo.TheMovieDb Name = cast.Name, Images = new Dictionary { - [Thumbnails.Poster] = cast.ProfilePath != null + [Images.Poster] = cast.ProfilePath != null ? $"https://image.tmdb.org/t/p/original{cast.ProfilePath}" : null }, @@ -64,7 +65,7 @@ namespace Kyoo.TheMovieDb Name = cast.Name, Images = new Dictionary { - [Thumbnails.Poster] = cast.ProfilePath != null + [Images.Poster] = cast.ProfilePath != null ? $"https://image.tmdb.org/t/p/original{cast.ProfilePath}" : null }, @@ -99,7 +100,7 @@ namespace Kyoo.TheMovieDb Name = crew.Name, Images = new Dictionary { - [Thumbnails.Poster] = crew.ProfilePath != null + [Images.Poster] = crew.ProfilePath != null ? $"https://image.tmdb.org/t/p/original{crew.ProfilePath}" : null }, @@ -132,7 +133,7 @@ namespace Kyoo.TheMovieDb Name = person.Name, Images = new Dictionary { - [Thumbnails.Poster] = person.ProfilePath != null + [Images.Poster] = person.ProfilePath != null ? $"https://image.tmdb.org/t/p/original{person.ProfilePath}" : null }, @@ -162,7 +163,7 @@ namespace Kyoo.TheMovieDb Name = person.Name, Images = new Dictionary { - [Thumbnails.Poster] = person.ProfilePath != null + [Images.Poster] = person.ProfilePath != null ? $"https://image.tmdb.org/t/p/original{person.ProfilePath}" : null }, diff --git a/Kyoo.TheMovieDb/Convertors/SeasonConvertors.cs b/Kyoo.TheMovieDb/Convertors/SeasonConvertors.cs index f7912f9f..1dcc88a6 100644 --- a/Kyoo.TheMovieDb/Convertors/SeasonConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/SeasonConvertors.cs @@ -26,7 +26,7 @@ namespace Kyoo.TheMovieDb StartDate = season.AirDate, Images = new Dictionary { - [Thumbnails.Poster] = season.PosterPath != null + [Images.Poster] = season.PosterPath != null ? $"https://image.tmdb.org/t/p/original{season.PosterPath}" : null }, diff --git a/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs b/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs index a64cfe3b..7d1b69a0 100644 --- a/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs +++ b/Kyoo.TheMovieDb/Convertors/ShowConvertors.cs @@ -30,13 +30,13 @@ namespace Kyoo.TheMovieDb EndAir = tv.LastAirDate, Images = new Dictionary { - [Thumbnails.Poster] = tv.PosterPath != null + [Images.Poster] = tv.PosterPath != null ? $"https://image.tmdb.org/t/p/original{tv.PosterPath}" : null, - [Thumbnails.Thumbnail] = tv.BackdropPath != null + [Images.Thumbnail] = tv.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{tv.BackdropPath}" : null, - [Thumbnails.Trailer] = tv.Videos?.Results + [Images.Trailer] = tv.Videos?.Results .Where(x => x.Type is "Trailer" or "Teaser" && x.Site == "YouTube") .Select(x => "https://www.youtube.com/watch?v=" + x.Key).FirstOrDefault() }, @@ -76,10 +76,10 @@ namespace Kyoo.TheMovieDb StartAir = tv.FirstAirDate, Images = new Dictionary { - [Thumbnails.Poster] = tv.PosterPath != null + [Images.Poster] = tv.PosterPath != null ? $"https://image.tmdb.org/t/p/original{tv.PosterPath}" : null, - [Thumbnails.Thumbnail] = tv.BackdropPath != null + [Images.Thumbnail] = tv.BackdropPath != null ? $"https://image.tmdb.org/t/p/original{tv.BackdropPath}" : null, }, diff --git a/Kyoo.TheMovieDb/ProviderTmdb.cs b/Kyoo.TheMovieDb/ProviderTmdb.cs index 95c0cc3d..5085b3b1 100644 --- a/Kyoo.TheMovieDb/ProviderTmdb.cs +++ b/Kyoo.TheMovieDb/ProviderTmdb.cs @@ -35,7 +35,7 @@ namespace Kyoo.TheMovieDb Name = "TheMovieDB", Images = new Dictionary { - [Thumbnails.Logo] = "https://www.themoviedb.org/assets/2/v4/logos/v2/" + + [Images.Logo] = "https://www.themoviedb.org/assets/2/v4/logos/v2/" + "blue_short-8e7b30f73a4020692ccca9c88bafe5dcb6f8a62a4c6bc55cd9ba82bb2cd95f6c.svg" } }; diff --git a/Kyoo.TheTvdb/Convertors.cs b/Kyoo.TheTvdb/Convertors.cs index 4cff035a..2e1f39cc 100644 --- a/Kyoo.TheTvdb/Convertors.cs +++ b/Kyoo.TheTvdb/Convertors.cs @@ -58,7 +58,7 @@ namespace Kyoo.TheTvdb StartAir = _ParseDate(result.FirstAired), Images = new Dictionary { - [Thumbnails.Poster] = result.Poster != null + [Images.Poster] = result.Poster != null ? $"https://www.thetvdb.com{result.Poster}" : null, }, @@ -92,10 +92,10 @@ namespace Kyoo.TheTvdb StartAir = _ParseDate(series.FirstAired), Images = new Dictionary { - [Thumbnails.Poster] = series.Poster != null + [Images.Poster] = series.Poster != null ? $"https://www.thetvdb.com/banners/{series.Poster}" : null, - [Thumbnails.Thumbnail] = series.FanArt != null + [Images.Thumbnail] = series.FanArt != null ? $"https://www.thetvdb.com/banners/{series.FanArt}" : null }, @@ -128,7 +128,7 @@ namespace Kyoo.TheTvdb Name = actor.Name, Images = new Dictionary { - [Thumbnails.Poster] = actor.Image != null + [Images.Poster] = actor.Image != null ? $"https://www.thetvdb.com/banners/{actor.Image}" : null }, @@ -164,7 +164,7 @@ namespace Kyoo.TheTvdb Overview = episode.Overview, Images = new Dictionary { - [Thumbnails.Thumbnail] = episode.Filename != null + [Images.Thumbnail] = episode.Filename != null ? $"https://www.thetvdb.com/banners/{episode.Filename}" : null }, diff --git a/Kyoo.TheTvdb/ProviderTvdb.cs b/Kyoo.TheTvdb/ProviderTvdb.cs index 66e330f9..e947ce25 100644 --- a/Kyoo.TheTvdb/ProviderTvdb.cs +++ b/Kyoo.TheTvdb/ProviderTvdb.cs @@ -34,7 +34,7 @@ namespace Kyoo.TheTvdb Name = "TheTVDB", Images = new Dictionary { - [Thumbnails.Logo] = "https://www.thetvdb.com/images/logo.png" + [Images.Logo] = "https://www.thetvdb.com/images/logo.png" } }; diff --git a/Kyoo/Controllers/Repositories/LibraryRepository.cs b/Kyoo/Controllers/Repositories/LibraryRepository.cs index a8e552af..06f57fc1 100644 --- a/Kyoo/Controllers/Repositories/LibraryRepository.cs +++ b/Kyoo/Controllers/Repositories/LibraryRepository.cs @@ -43,7 +43,7 @@ namespace Kyoo.Controllers public override async Task> Search(string query) { return await _database.Libraries - .Where(_database.Like(x => x.Name, $"%{query}%")) + .Where(_database.Like(x => x.Name + " " + x.Slug, $"%{query}%")) .OrderBy(DefaultSort) .Take(20) .ToListAsync(); @@ -54,8 +54,6 @@ namespace Kyoo.Controllers { await base.Create(obj); _database.Entry(obj).State = EntityState.Added; - if (obj.Providers != null) - _database.AttachRange(obj.Providers); await _database.SaveChangesAsync($"Trying to insert a duplicated library (slug {obj.Slug} already exists)."); return obj; } @@ -64,27 +62,30 @@ namespace Kyoo.Controllers protected override async Task Validate(Library resource) { await base.Validate(resource); - if (resource.Providers != null) - { - resource.Providers = await resource.Providers - .SelectAsync(x => _providers.CreateIfNotExists(x)) - .ToListAsync(); - } - } - - /// - protected override async Task EditRelations(Library resource, Library changed, bool resetOld) - { + if (string.IsNullOrEmpty(resource.Slug)) throw new ArgumentException("The library's slug must be set and not empty"); if (string.IsNullOrEmpty(resource.Name)) throw new ArgumentException("The library's name must be set and not empty"); if (resource.Paths == null || !resource.Paths.Any()) throw new ArgumentException("The library should have a least one path."); + + if (resource.Providers != null) + { + resource.Providers = await resource.Providers + .SelectAsync(x => _providers.CreateIfNotExists(x)) + .ToListAsync(); + _database.AttachRange(resource.Providers); + } + } + + /// + protected override async Task EditRelations(Library resource, Library changed, bool resetOld) + { + await Validate(changed); if (changed.Providers != null || resetOld) { - await Validate(changed); await Database.Entry(resource).Collection(x => x.Providers).LoadAsync(); resource.Providers = changed.Providers; } diff --git a/Kyoo/Controllers/Repositories/ProviderRepository.cs b/Kyoo/Controllers/Repositories/ProviderRepository.cs index 5edf451b..f555f5a5 100644 --- a/Kyoo/Controllers/Repositories/ProviderRepository.cs +++ b/Kyoo/Controllers/Repositories/ProviderRepository.cs @@ -68,7 +68,6 @@ namespace Kyoo.Controllers Pagination limit = default) where T : class, IMetadata { - string discriminator = typeof(T).Name; return ApplyFilters(_database.MetadataIds() .Include(y => y.Provider), x => _database.MetadataIds().FirstOrDefaultAsync(y => y.ResourceID == x), diff --git a/Kyoo/Controllers/ThumbnailsManager.cs b/Kyoo/Controllers/ThumbnailsManager.cs index e052cfe5..3f6ffe3a 100644 --- a/Kyoo/Controllers/ThumbnailsManager.cs +++ b/Kyoo/Controllers/ThumbnailsManager.cs @@ -113,9 +113,9 @@ namespace Kyoo.Controllers // TODO handle extensions string imageName = imageID switch { - Thumbnails.Poster => "poster.jpg", - Thumbnails.Logo => "logo.jpg", - Thumbnails.Thumbnail => "thumbnail.jpg", + Images.Poster => "poster.jpg", + Images.Logo => "logo.jpg", + Images.Thumbnail => "thumbnail.jpg", _ => $"{imageID}.jpg" }; diff --git a/Kyoo/Views/EpisodeApi.cs b/Kyoo/Views/EpisodeApi.cs index beaf0273..e98f1f6a 100644 --- a/Kyoo/Views/EpisodeApi.cs +++ b/Kyoo/Views/EpisodeApi.cs @@ -195,7 +195,7 @@ namespace Kyoo.Api try { Episode episode = await _libraryManager.Get(id); - return _files.FileResult(await _thumbnails.GetImagePath(episode, Thumbnails.Thumbnail)); + return _files.FileResult(await _thumbnails.GetImagePath(episode, Images.Thumbnail)); } catch (ItemNotFoundException) { @@ -210,7 +210,7 @@ namespace Kyoo.Api try { Episode episode = await _libraryManager.Get(slug); - return _files.FileResult(await _thumbnails.GetImagePath(episode, Thumbnails.Thumbnail)); + return _files.FileResult(await _thumbnails.GetImagePath(episode, Images.Thumbnail)); } catch (ItemNotFoundException) { diff --git a/Kyoo/Views/PeopleApi.cs b/Kyoo/Views/PeopleApi.cs index 194504ff..bd25491e 100644 --- a/Kyoo/Views/PeopleApi.cs +++ b/Kyoo/Views/PeopleApi.cs @@ -94,7 +94,7 @@ namespace Kyoo.Api People people = await _libraryManager.GetOrDefault(id); if (people == null) return NotFound(); - return _files.FileResult(await _thumbs.GetImagePath(people, Thumbnails.Poster)); + return _files.FileResult(await _thumbs.GetImagePath(people, Images.Poster)); } [HttpGet("{slug}/poster")] @@ -103,7 +103,7 @@ namespace Kyoo.Api People people = await _libraryManager.GetOrDefault(slug); if (people == null) return NotFound(); - return _files.FileResult(await _thumbs.GetImagePath(people, Thumbnails.Poster)); + return _files.FileResult(await _thumbs.GetImagePath(people, Images.Poster)); } } } \ No newline at end of file diff --git a/Kyoo/Views/ProviderApi.cs b/Kyoo/Views/ProviderApi.cs index 06c06eb8..5651f4f7 100644 --- a/Kyoo/Views/ProviderApi.cs +++ b/Kyoo/Views/ProviderApi.cs @@ -36,7 +36,7 @@ namespace Kyoo.Api Provider provider = await _libraryManager.GetOrDefault(id); if (provider == null) return NotFound(); - return _files.FileResult(await _thumbnails.GetImagePath(provider, Thumbnails.Logo)); + return _files.FileResult(await _thumbnails.GetImagePath(provider, Images.Logo)); } [HttpGet("{slug}/logo")] @@ -45,7 +45,7 @@ namespace Kyoo.Api Provider provider = await _libraryManager.GetOrDefault(slug); if (provider == null) return NotFound(); - return _files.FileResult(await _thumbnails.GetImagePath(provider, Thumbnails.Logo)); + return _files.FileResult(await _thumbnails.GetImagePath(provider, Images.Logo)); } } } \ No newline at end of file diff --git a/Kyoo/Views/SeasonApi.cs b/Kyoo/Views/SeasonApi.cs index 0241de55..fdf98959 100644 --- a/Kyoo/Views/SeasonApi.cs +++ b/Kyoo/Views/SeasonApi.cs @@ -151,7 +151,7 @@ namespace Kyoo.Api if (season == null) return NotFound(); await _libraryManager.Load(season, x => x.Show); - return _files.FileResult(await _thumbs.GetImagePath(season, Thumbnails.Poster)); + return _files.FileResult(await _thumbs.GetImagePath(season, Images.Poster)); } [HttpGet("{slug}/poster")] @@ -161,7 +161,7 @@ namespace Kyoo.Api if (season == null) return NotFound(); await _libraryManager.Load(season, x => x.Show); - return _files.FileResult(await _thumbs.GetImagePath(season, Thumbnails.Poster)); + return _files.FileResult(await _thumbs.GetImagePath(season, Images.Poster)); } } } \ No newline at end of file diff --git a/Kyoo/Views/ShowApi.cs b/Kyoo/Views/ShowApi.cs index d7162792..df12c876 100644 --- a/Kyoo/Views/ShowApi.cs +++ b/Kyoo/Views/ShowApi.cs @@ -417,7 +417,7 @@ namespace Kyoo.Api try { Show show = await _libraryManager.Get(slug); - return _files.FileResult(await _thumbs.GetImagePath(show, Thumbnails.Poster)); + return _files.FileResult(await _thumbs.GetImagePath(show, Images.Poster)); } catch (ItemNotFoundException) { @@ -431,7 +431,7 @@ namespace Kyoo.Api try { Show show = await _libraryManager.Get(slug); - return _files.FileResult(await _thumbs.GetImagePath(show, Thumbnails.Logo)); + return _files.FileResult(await _thumbs.GetImagePath(show, Images.Logo)); } catch (ItemNotFoundException) { @@ -446,7 +446,7 @@ namespace Kyoo.Api try { Show show = await _libraryManager.Get(slug); - return _files.FileResult(await _thumbs.GetImagePath(show, Thumbnails.Thumbnail)); + return _files.FileResult(await _thumbs.GetImagePath(show, Images.Thumbnail)); } catch (ItemNotFoundException) {