mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
LibraryRepository: Adding more tests
This commit is contained in:
parent
47f855bdb9
commit
4ae28f2594
@ -30,7 +30,7 @@ namespace Kyoo.Controllers
|
||||
/// Retrieve the local path of the poster of the given item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to retrieve the poster from.</param>
|
||||
/// <param name="imageID">The ID of the image. See <see cref="Thumbnails"/> for values.</param>
|
||||
/// <param name="imageID">The ID of the image. See <see cref="Images"/> for values.</param>
|
||||
/// <typeparam name="T">The type of the item</typeparam>
|
||||
/// <exception cref="NotSupportedException">If the type does not have a poster</exception>
|
||||
/// <returns>The path of the poster for the given resource (it might or might not exists).</returns>
|
||||
|
@ -63,7 +63,7 @@ namespace Kyoo.Models
|
||||
/// This can be disabled using the internal query flag.
|
||||
/// </summary>
|
||||
[SerializeAs("{HOST}/api/{Type:l}/{Slug}/poster")]
|
||||
public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster);
|
||||
public string Poster => Images?.GetValueOrDefault(Models.Images.Poster);
|
||||
|
||||
/// <summary>
|
||||
/// The type of this item (ether a collection, a show or a movie).
|
||||
|
@ -31,7 +31,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// The description of this collection.
|
||||
|
@ -113,7 +113,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// The title of this episode.
|
||||
|
@ -13,7 +13,7 @@ namespace Kyoo.Models
|
||||
/// The string value should be a path supported by the <see cref="IFileSystem"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An arbitrary index should not be used, instead use indexes from <see cref="Thumbnails"/>
|
||||
/// An arbitrary index should not be used, instead use indexes from <see cref="Models.Images"/>
|
||||
/// </remarks>
|
||||
public Dictionary<int, string> Images { get; set; }
|
||||
|
||||
@ -23,7 +23,7 @@ namespace Kyoo.Models
|
||||
/// <summary>
|
||||
/// A class containing constant values for images. To be used as index of a <see cref="IThumbnails.Images"/>.
|
||||
/// </summary>
|
||||
public static class Thumbnails
|
||||
public static class Images
|
||||
{
|
||||
/// <summary>
|
||||
/// A poster is a 9/16 format image with the cover of the resource.
|
||||
|
@ -30,7 +30,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <inheritdoc />
|
||||
[EditableRelation] [LoadableRelation] public ICollection<MetadataID> ExternalIDs { get; set; }
|
||||
|
@ -32,7 +32,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// The list of libraries that uses this provider.
|
||||
@ -56,7 +56,7 @@ namespace Kyoo.Models
|
||||
Name = name;
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[Thumbnails.Logo] = logo
|
||||
[Models.Images.Logo] = logo
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <inheritdoc />
|
||||
[EditableRelation] [LoadableRelation] public ICollection<MetadataID> ExternalIDs { get; set; }
|
||||
|
@ -47,7 +47,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
/// 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);
|
||||
|
||||
/// <summary>
|
||||
/// The date this show started airing. It can be null if this is unknown.
|
||||
@ -71,7 +71,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// The path of this show's logo.
|
||||
@ -80,7 +80,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// The path of this show's backdrop.
|
||||
@ -89,7 +89,7 @@ namespace Kyoo.Models
|
||||
/// </summary>
|
||||
[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);
|
||||
|
||||
/// <summary>
|
||||
/// True if this show represent a movie, false otherwise.
|
||||
|
@ -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>();
|
||||
library.Paths = null;
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => _repository.Create(library));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateWithEmptySlugTest()
|
||||
{
|
||||
Library library = TestSample.GetNew<Library>();
|
||||
library.Slug = "";
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => _repository.Create(library));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateWithNumberSlugTest()
|
||||
{
|
||||
Library library = TestSample.GetNew<Library>();
|
||||
library.Slug = "2";
|
||||
Library ret = await _repository.Create(library);
|
||||
Assert.Equal("2!", library.Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CreateWithoutNameTest()
|
||||
{
|
||||
Library library = TestSample.GetNew<Library>();
|
||||
library.Name = null;
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => _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<Provider>().Slug, retrieved.Providers.First().Slug);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EditTest()
|
||||
{
|
||||
Library value = await _repository.Get(TestSample.Get<Library>().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<Library>().Slug);
|
||||
value.Providers = new[]
|
||||
{
|
||||
TestSample.GetNew<Provider>()
|
||||
};
|
||||
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<Library>().Slug);
|
||||
await Repositories.LibraryManager.Load(value, x => x.Providers);
|
||||
value.Providers.Add(TestSample.GetNew<Provider>());
|
||||
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<Library> ret = await _repository.Search(query);
|
||||
KAssert.DeepEqual(value, ret.First());
|
||||
}
|
||||
}
|
||||
}
|
@ -31,13 +31,26 @@ namespace Kyoo.Tests
|
||||
EndAir = new DateTime(2011, 1, 1),
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[Images.Logo] = "logo"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -64,7 +77,7 @@ namespace Kyoo.Tests
|
||||
Overview = "A nice collection for tests",
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[Thumbnails.Poster] = "Poster"
|
||||
[Images.Poster] = "Poster"
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -90,9 +103,9 @@ namespace Kyoo.Tests
|
||||
EndAir = new DateTime(2011, 1, 1),
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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",
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,10 +24,10 @@ namespace Kyoo.TheMovieDb
|
||||
Overview = collection.Overview,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ namespace Kyoo.TheMovieDb
|
||||
ReleaseDate = episode.AirDate,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[Thumbnails.Thumbnail] = episode.StillPath != null
|
||||
[Images.Thumbnail] = episode.StillPath != null
|
||||
? $"https://image.tmdb.org/t/p/original{episode.StillPath}"
|
||||
: null
|
||||
},
|
||||
|
@ -30,13 +30,13 @@ namespace Kyoo.TheMovieDb
|
||||
EndAir = movie.ReleaseDate,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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,
|
||||
},
|
||||
|
@ -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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[Thumbnails.Poster] = person.ProfilePath != null
|
||||
[Images.Poster] = person.ProfilePath != null
|
||||
? $"https://image.tmdb.org/t/p/original{person.ProfilePath}"
|
||||
: null
|
||||
},
|
||||
|
@ -26,7 +26,7 @@ namespace Kyoo.TheMovieDb
|
||||
StartDate = season.AirDate,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[Thumbnails.Poster] = season.PosterPath != null
|
||||
[Images.Poster] = season.PosterPath != null
|
||||
? $"https://image.tmdb.org/t/p/original{season.PosterPath}"
|
||||
: null
|
||||
},
|
||||
|
@ -30,13 +30,13 @@ namespace Kyoo.TheMovieDb
|
||||
EndAir = tv.LastAirDate,
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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,
|
||||
},
|
||||
|
@ -35,7 +35,7 @@ namespace Kyoo.TheMovieDb
|
||||
Name = "TheMovieDB",
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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"
|
||||
}
|
||||
};
|
||||
|
@ -58,7 +58,7 @@ namespace Kyoo.TheTvdb
|
||||
StartAir = _ParseDate(result.FirstAired),
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[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<int, string>
|
||||
{
|
||||
[Thumbnails.Thumbnail] = episode.Filename != null
|
||||
[Images.Thumbnail] = episode.Filename != null
|
||||
? $"https://www.thetvdb.com/banners/{episode.Filename}"
|
||||
: null
|
||||
},
|
||||
|
@ -34,7 +34,7 @@ namespace Kyoo.TheTvdb
|
||||
Name = "TheTVDB",
|
||||
Images = new Dictionary<int, string>
|
||||
{
|
||||
[Thumbnails.Logo] = "https://www.thetvdb.com/images/logo.png"
|
||||
[Images.Logo] = "https://www.thetvdb.com/images/logo.png"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace Kyoo.Controllers
|
||||
public override async Task<ICollection<Library>> Search(string query)
|
||||
{
|
||||
return await _database.Libraries
|
||||
.Where(_database.Like<Library>(x => x.Name, $"%{query}%"))
|
||||
.Where(_database.Like<Library>(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,17 +62,7 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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))
|
||||
@ -82,9 +70,22 @@ namespace Kyoo.Controllers
|
||||
if (resource.Paths == null || !resource.Paths.Any())
|
||||
throw new ArgumentException("The library should have a least one path.");
|
||||
|
||||
if (changed.Providers != null || resetOld)
|
||||
if (resource.Providers != null)
|
||||
{
|
||||
resource.Providers = await resource.Providers
|
||||
.SelectAsync(x => _providers.CreateIfNotExists(x))
|
||||
.ToListAsync();
|
||||
_database.AttachRange(resource.Providers);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task EditRelations(Library resource, Library changed, bool resetOld)
|
||||
{
|
||||
await Validate(changed);
|
||||
|
||||
if (changed.Providers != null || resetOld)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.Providers).LoadAsync();
|
||||
resource.Providers = changed.Providers;
|
||||
}
|
||||
|
@ -68,7 +68,6 @@ namespace Kyoo.Controllers
|
||||
Pagination limit = default)
|
||||
where T : class, IMetadata
|
||||
{
|
||||
string discriminator = typeof(T).Name;
|
||||
return ApplyFilters(_database.MetadataIds<T>()
|
||||
.Include(y => y.Provider),
|
||||
x => _database.MetadataIds<T>().FirstOrDefaultAsync(y => y.ResourceID == x),
|
||||
|
@ -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"
|
||||
};
|
||||
|
||||
|
@ -195,7 +195,7 @@ namespace Kyoo.Api
|
||||
try
|
||||
{
|
||||
Episode episode = await _libraryManager.Get<Episode>(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<Episode>(slug);
|
||||
return _files.FileResult(await _thumbnails.GetImagePath(episode, Thumbnails.Thumbnail));
|
||||
return _files.FileResult(await _thumbnails.GetImagePath(episode, Images.Thumbnail));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ namespace Kyoo.Api
|
||||
People people = await _libraryManager.GetOrDefault<People>(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<People>(slug);
|
||||
if (people == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbs.GetImagePath(people, Thumbnails.Poster));
|
||||
return _files.FileResult(await _thumbs.GetImagePath(people, Images.Poster));
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ namespace Kyoo.Api
|
||||
Provider provider = await _libraryManager.GetOrDefault<Provider>(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<Provider>(slug);
|
||||
if (provider == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbnails.GetImagePath(provider, Thumbnails.Logo));
|
||||
return _files.FileResult(await _thumbnails.GetImagePath(provider, Images.Logo));
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
@ -417,7 +417,7 @@ namespace Kyoo.Api
|
||||
try
|
||||
{
|
||||
Show show = await _libraryManager.Get<Show>(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<Show>(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<Show>(slug);
|
||||
return _files.FileResult(await _thumbs.GetImagePath(show, Thumbnails.Thumbnail));
|
||||
return _files.FileResult(await _thumbs.GetImagePath(show, Images.Thumbnail));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user