From 42ff22ad131afff8dcc2a8ea597fede55807c3e9 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 13 Mar 2021 22:51:45 +0100 Subject: [PATCH] Finishing to rework image's path serialization --- .../Implementations/LibraryManager.cs | 9 ++- Kyoo.Common/Models/LibraryItem.cs | 4 +- Kyoo.Common/Models/Resources/People.cs | 2 +- Kyoo.Common/Models/WatchItem.cs | 68 ++++++++++--------- Kyoo.CommonAPI/JsonSerializer.cs | 3 +- .../Repositories/ProviderRepository.cs | 2 +- Kyoo/Views/API/PeopleApi.cs | 2 +- Kyoo/Views/WebClient | 2 +- 8 files changed, 52 insertions(+), 40 deletions(-) diff --git a/Kyoo.Common/Controllers/Implementations/LibraryManager.cs b/Kyoo.Common/Controllers/Implementations/LibraryManager.cs index 9974dab8..9a54b7af 100644 --- a/Kyoo.Common/Controllers/Implementations/LibraryManager.cs +++ b/Kyoo.Common/Controllers/Implementations/LibraryManager.cs @@ -261,7 +261,10 @@ namespace Kyoo.Controllers return obj; } - private async Task SetRelation(T1 obj, Task> loader, Action> setter, Action inverse) + private async Task SetRelation(T1 obj, + Task> loader, + Action> setter, + Action inverse) { ICollection loaded = await loader; setter(obj, loaded); @@ -300,8 +303,8 @@ namespace Kyoo.Controllers (Show s, nameof(Show.ExternalIDs)) => SetRelation(s, ProviderRepository.GetMetadataID(x => x.ShowID == obj.ID), - (x, y) => x.ExternalIDs = y, - (x, y) => x.Show = y), + (x, y) => x.ExternalIDs = y, + (x, y) => { x.Show = y; x.ShowID = y.ID; }), (Show s, nameof(Show.Genres)) => GenreRepository .GetAll(x => x.Shows.Any(y => y.ID == obj.ID)) diff --git a/Kyoo.Common/Models/LibraryItem.cs b/Kyoo.Common/Models/LibraryItem.cs index 4264a469..6fe964d4 100644 --- a/Kyoo.Common/Models/LibraryItem.cs +++ b/Kyoo.Common/Models/LibraryItem.cs @@ -1,5 +1,6 @@ using System; using System.Linq.Expressions; +using Kyoo.Models.Attributes; namespace Kyoo.Models { @@ -20,7 +21,8 @@ namespace Kyoo.Models public string TrailerUrl { get; set; } public int? StartYear { get; set; } public int? EndYear { get; set; } - public string Poster { get; set; } + [SerializeAs("{HOST}/api/{_type}/{Slug}/poster")] public string Poster { get; set; } + private string _type => Type == ItemType.Collection ? "collection" : "show"; public ItemType Type { get; set; } public LibraryItem() {} diff --git a/Kyoo.Common/Models/Resources/People.cs b/Kyoo.Common/Models/Resources/People.cs index ca1aec5d..2743cf3c 100644 --- a/Kyoo.Common/Models/Resources/People.cs +++ b/Kyoo.Common/Models/Resources/People.cs @@ -9,7 +9,7 @@ namespace Kyoo.Models public int ID { get; set; } public string Slug { get; set; } public string Name { get; set; } - public string Poster { get; set; } + [SerializeAs("{HOST}/api/people/{Slug}/poster")] public string Poster { get; set; } [EditableRelation] [LoadableRelation] public virtual ICollection ExternalIDs { get; set; } [EditableRelation] [LoadableRelation] public virtual ICollection Roles { get; set; } diff --git a/Kyoo.Common/Models/WatchItem.cs b/Kyoo.Common/Models/WatchItem.cs index f552efce..fc260699 100644 --- a/Kyoo.Common/Models/WatchItem.cs +++ b/Kyoo.Common/Models/WatchItem.cs @@ -25,31 +25,34 @@ namespace Kyoo.Models public class WatchItem { - public readonly int EpisodeID; + public int EpisodeID { get; set; } - public string ShowTitle; - public string ShowSlug; - public int SeasonNumber; - public int EpisodeNumber; - public string Title; - public string Slug; - public DateTime? ReleaseDate; - [SerializeIgnore] public string Path; - public Episode PreviousEpisode; - public Episode NextEpisode; - public bool IsMovie; + public string ShowTitle { get; set; } + public string ShowSlug { get; set; } + public int SeasonNumber { get; set; } + public int EpisodeNumber { get; set; } + public string Title { get; set; } + public string Slug { get; set; } + public DateTime? ReleaseDate { get; set; } + [SerializeIgnore] public string Path { get; set; } + public Episode PreviousEpisode { get; set; } + public Episode NextEpisode { get; set; } + public bool IsMovie { get; set; } - public string Container; - public Track Video; - public ICollection Audios; - public ICollection Subtitles; - public ICollection Chapters; + [SerializeAs("{HOST}/api/show/{ShowSlug}/poster")] public string Poster { get; set; } + [SerializeAs("{HOST}/api/show/{ShowSlug}/logo")] public string Logo { get; set; } + [SerializeAs("{HOST}/api/show/{ShowSlug}/backdrop")] public string Backdrop { get; set; } + + public string Container { get; set; } + public Track Video { get; set; } + public ICollection Audios { get; set; } + public ICollection Subtitles { get; set; } + public ICollection Chapters { get; set; } public WatchItem() { } private WatchItem(int episodeID, - string showTitle, - string showSlug, + Show show, int seasonNumber, int episodeNumber, string title, @@ -57,21 +60,25 @@ namespace Kyoo.Models string path) { EpisodeID = episodeID; - ShowTitle = showTitle; - ShowSlug = showSlug; + ShowTitle = show.Title; + ShowSlug = show.Slug; SeasonNumber = seasonNumber; EpisodeNumber = episodeNumber; Title = title; ReleaseDate = releaseDate; Path = path; + IsMovie = show.IsMovie; + + Poster = show.Poster; + Logo = show.Logo; + Backdrop = show.Backdrop; Container = Path.Substring(Path.LastIndexOf('.') + 1); Slug = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber); } private WatchItem(int episodeID, - string showTitle, - string showSlug, + Show show, int seasonNumber, int episodeNumber, string title, @@ -80,7 +87,7 @@ namespace Kyoo.Models Track video, ICollection audios, ICollection subtitles) - : this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path) + : this(episodeID, show, seasonNumber, episodeNumber, title, releaseDate, path) { Video = video; Audios = audios; @@ -89,11 +96,13 @@ namespace Kyoo.Models public static async Task FromEpisode(Episode ep, ILibraryManager library) { - Show show = await library.GetShow(ep.ShowID); Episode previous = null; Episode next = null; - if (!show.IsMovie) + await library.Load(ep, x => x.Show); + await library.Load(ep, x => x.Tracks); + + if (!ep.Show.IsMovie) { if (ep.EpisodeNumber > 1) previous = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber - 1); @@ -109,11 +118,9 @@ namespace Kyoo.Models else next = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber + 1); } - - await library.Load(ep, x => x.Tracks); + return new WatchItem(ep.ID, - show.Title, - show.Slug, + ep.Show, ep.SeasonNumber, ep.EpisodeNumber, ep.Title, @@ -123,7 +130,6 @@ namespace Kyoo.Models ep.Tracks.Where(x => x.Type == StreamType.Audio).ToArray(), ep.Tracks.Where(x => x.Type == StreamType.Subtitle).ToArray()) { - IsMovie = show.IsMovie, PreviousEpisode = previous, NextEpisode = next, Chapters = await GetChapters(ep.Path) diff --git a/Kyoo.CommonAPI/JsonSerializer.cs b/Kyoo.CommonAPI/JsonSerializer.cs index 8702e66b..ce19ba29 100644 --- a/Kyoo.CommonAPI/JsonSerializer.cs +++ b/Kyoo.CommonAPI/JsonSerializer.cs @@ -119,7 +119,8 @@ namespace Kyoo.Controllers if (value == "HOST") return _host; - PropertyInfo properties = target.GetType().GetProperties() + PropertyInfo properties = target.GetType() + .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .FirstOrDefault(y => y.Name == value); if (properties == null) return null; diff --git a/Kyoo/Controllers/Repositories/ProviderRepository.cs b/Kyoo/Controllers/Repositories/ProviderRepository.cs index 72f4d354..2e2e7c2c 100644 --- a/Kyoo/Controllers/Repositories/ProviderRepository.cs +++ b/Kyoo/Controllers/Repositories/ProviderRepository.cs @@ -51,7 +51,7 @@ namespace Kyoo.Controllers Sort sort = default, Pagination limit = default) { - return ApplyFilters(_database.MetadataIds, + return ApplyFilters(_database.MetadataIds.Include(y => y.Provider), x => _database.MetadataIds.FirstOrDefaultAsync(y => y.ID == x), x => x.ID, where, diff --git a/Kyoo/Views/API/PeopleApi.cs b/Kyoo/Views/API/PeopleApi.cs index 88088757..602c022c 100644 --- a/Kyoo/Views/API/PeopleApi.cs +++ b/Kyoo/Views/API/PeopleApi.cs @@ -23,7 +23,7 @@ namespace Kyoo.Api : base(libraryManager.PeopleRepository, configuration) { _libraryManager = libraryManager; - _peoplePath = configuration.GetValue("peoplePath"); + _peoplePath = Path.GetFullPath(configuration.GetValue("peoplePath")); } [HttpGet("{id:int}/role")] diff --git a/Kyoo/Views/WebClient b/Kyoo/Views/WebClient index 35e6a601..f36ac1bb 160000 --- a/Kyoo/Views/WebClient +++ b/Kyoo/Views/WebClient @@ -1 +1 @@ -Subproject commit 35e6a601edc494d1bea142fd419c7750c18d21d9 +Subproject commit f36ac1bb9bf60329a7f04ba76730f43ded7b0d9d