Finishing to rework image's path serialization

This commit is contained in:
Zoe Roux 2021-03-13 22:51:45 +01:00
parent 779702f969
commit 42ff22ad13
8 changed files with 52 additions and 40 deletions

View File

@ -261,7 +261,10 @@ namespace Kyoo.Controllers
return obj; return obj;
} }
private async Task SetRelation<T1, T2>(T1 obj, Task<ICollection<T2>> loader, Action<T1, ICollection<T2>> setter, Action<T2, T1> inverse) private async Task SetRelation<T1, T2>(T1 obj,
Task<ICollection<T2>> loader,
Action<T1, ICollection<T2>> setter,
Action<T2, T1> inverse)
{ {
ICollection<T2> loaded = await loader; ICollection<T2> loaded = await loader;
setter(obj, loaded); setter(obj, loaded);
@ -300,8 +303,8 @@ namespace Kyoo.Controllers
(Show s, nameof(Show.ExternalIDs)) => SetRelation(s, (Show s, nameof(Show.ExternalIDs)) => SetRelation(s,
ProviderRepository.GetMetadataID(x => x.ShowID == obj.ID), ProviderRepository.GetMetadataID(x => x.ShowID == obj.ID),
(x, y) => x.ExternalIDs = y, (x, y) => x.ExternalIDs = y,
(x, y) => x.Show = y), (x, y) => { x.Show = y; x.ShowID = y.ID; }),
(Show s, nameof(Show.Genres)) => GenreRepository (Show s, nameof(Show.Genres)) => GenreRepository
.GetAll(x => x.Shows.Any(y => y.ID == obj.ID)) .GetAll(x => x.Shows.Any(y => y.ID == obj.ID))

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Linq.Expressions; using System.Linq.Expressions;
using Kyoo.Models.Attributes;
namespace Kyoo.Models namespace Kyoo.Models
{ {
@ -20,7 +21,8 @@ namespace Kyoo.Models
public string TrailerUrl { get; set; } public string TrailerUrl { get; set; }
public int? StartYear { get; set; } public int? StartYear { get; set; }
public int? EndYear { 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 ItemType Type { get; set; }
public LibraryItem() {} public LibraryItem() {}

View File

@ -9,7 +9,7 @@ namespace Kyoo.Models
public int ID { get; set; } public int ID { get; set; }
public string Slug { get; set; } public string Slug { get; set; }
public string Name { 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<MetadataID> ExternalIDs { get; set; } [EditableRelation] [LoadableRelation] public virtual ICollection<MetadataID> ExternalIDs { get; set; }
[EditableRelation] [LoadableRelation] public virtual ICollection<PeopleRole> Roles { get; set; } [EditableRelation] [LoadableRelation] public virtual ICollection<PeopleRole> Roles { get; set; }

View File

@ -25,31 +25,34 @@ namespace Kyoo.Models
public class WatchItem public class WatchItem
{ {
public readonly int EpisodeID; public int EpisodeID { get; set; }
public string ShowTitle; public string ShowTitle { get; set; }
public string ShowSlug; public string ShowSlug { get; set; }
public int SeasonNumber; public int SeasonNumber { get; set; }
public int EpisodeNumber; public int EpisodeNumber { get; set; }
public string Title; public string Title { get; set; }
public string Slug; public string Slug { get; set; }
public DateTime? ReleaseDate; public DateTime? ReleaseDate { get; set; }
[SerializeIgnore] public string Path; [SerializeIgnore] public string Path { get; set; }
public Episode PreviousEpisode; public Episode PreviousEpisode { get; set; }
public Episode NextEpisode; public Episode NextEpisode { get; set; }
public bool IsMovie; public bool IsMovie { get; set; }
public string Container; [SerializeAs("{HOST}/api/show/{ShowSlug}/poster")] public string Poster { get; set; }
public Track Video; [SerializeAs("{HOST}/api/show/{ShowSlug}/logo")] public string Logo { get; set; }
public ICollection<Track> Audios; [SerializeAs("{HOST}/api/show/{ShowSlug}/backdrop")] public string Backdrop { get; set; }
public ICollection<Track> Subtitles;
public ICollection<Chapter> Chapters; public string Container { get; set; }
public Track Video { get; set; }
public ICollection<Track> Audios { get; set; }
public ICollection<Track> Subtitles { get; set; }
public ICollection<Chapter> Chapters { get; set; }
public WatchItem() { } public WatchItem() { }
private WatchItem(int episodeID, private WatchItem(int episodeID,
string showTitle, Show show,
string showSlug,
int seasonNumber, int seasonNumber,
int episodeNumber, int episodeNumber,
string title, string title,
@ -57,21 +60,25 @@ namespace Kyoo.Models
string path) string path)
{ {
EpisodeID = episodeID; EpisodeID = episodeID;
ShowTitle = showTitle; ShowTitle = show.Title;
ShowSlug = showSlug; ShowSlug = show.Slug;
SeasonNumber = seasonNumber; SeasonNumber = seasonNumber;
EpisodeNumber = episodeNumber; EpisodeNumber = episodeNumber;
Title = title; Title = title;
ReleaseDate = releaseDate; ReleaseDate = releaseDate;
Path = path; Path = path;
IsMovie = show.IsMovie;
Poster = show.Poster;
Logo = show.Logo;
Backdrop = show.Backdrop;
Container = Path.Substring(Path.LastIndexOf('.') + 1); Container = Path.Substring(Path.LastIndexOf('.') + 1);
Slug = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber); Slug = Episode.GetSlug(ShowSlug, seasonNumber, episodeNumber);
} }
private WatchItem(int episodeID, private WatchItem(int episodeID,
string showTitle, Show show,
string showSlug,
int seasonNumber, int seasonNumber,
int episodeNumber, int episodeNumber,
string title, string title,
@ -80,7 +87,7 @@ namespace Kyoo.Models
Track video, Track video,
ICollection<Track> audios, ICollection<Track> audios,
ICollection<Track> subtitles) ICollection<Track> subtitles)
: this(episodeID, showTitle, showSlug, seasonNumber, episodeNumber, title, releaseDate, path) : this(episodeID, show, seasonNumber, episodeNumber, title, releaseDate, path)
{ {
Video = video; Video = video;
Audios = audios; Audios = audios;
@ -89,11 +96,13 @@ namespace Kyoo.Models
public static async Task<WatchItem> FromEpisode(Episode ep, ILibraryManager library) public static async Task<WatchItem> FromEpisode(Episode ep, ILibraryManager library)
{ {
Show show = await library.GetShow(ep.ShowID);
Episode previous = null; Episode previous = null;
Episode next = 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) if (ep.EpisodeNumber > 1)
previous = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber - 1); previous = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber - 1);
@ -109,11 +118,9 @@ namespace Kyoo.Models
else else
next = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber + 1); next = await library.GetEpisode(ep.ShowID, ep.SeasonNumber, ep.EpisodeNumber + 1);
} }
await library.Load(ep, x => x.Tracks);
return new WatchItem(ep.ID, return new WatchItem(ep.ID,
show.Title, ep.Show,
show.Slug,
ep.SeasonNumber, ep.SeasonNumber,
ep.EpisodeNumber, ep.EpisodeNumber,
ep.Title, 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.Audio).ToArray(),
ep.Tracks.Where(x => x.Type == StreamType.Subtitle).ToArray()) ep.Tracks.Where(x => x.Type == StreamType.Subtitle).ToArray())
{ {
IsMovie = show.IsMovie,
PreviousEpisode = previous, PreviousEpisode = previous,
NextEpisode = next, NextEpisode = next,
Chapters = await GetChapters(ep.Path) Chapters = await GetChapters(ep.Path)

View File

@ -119,7 +119,8 @@ namespace Kyoo.Controllers
if (value == "HOST") if (value == "HOST")
return _host; return _host;
PropertyInfo properties = target.GetType().GetProperties() PropertyInfo properties = target.GetType()
.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.FirstOrDefault(y => y.Name == value); .FirstOrDefault(y => y.Name == value);
if (properties == null) if (properties == null)
return null; return null;

View File

@ -51,7 +51,7 @@ namespace Kyoo.Controllers
Sort<MetadataID> sort = default, Sort<MetadataID> sort = default,
Pagination limit = 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 => _database.MetadataIds.FirstOrDefaultAsync(y => y.ID == x),
x => x.ID, x => x.ID,
where, where,

View File

@ -23,7 +23,7 @@ namespace Kyoo.Api
: base(libraryManager.PeopleRepository, configuration) : base(libraryManager.PeopleRepository, configuration)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_peoplePath = configuration.GetValue<string>("peoplePath"); _peoplePath = Path.GetFullPath(configuration.GetValue<string>("peoplePath"));
} }
[HttpGet("{id:int}/role")] [HttpGet("{id:int}/role")]

@ -1 +1 @@
Subproject commit 35e6a601edc494d1bea142fd419c7750c18d21d9 Subproject commit f36ac1bb9bf60329a7f04ba76730f43ded7b0d9d