diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs index a226c8a8..eda05306 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Episode.cs @@ -150,6 +150,25 @@ namespace Kyoo.Abstractions.Models /// public Dictionary ExternalId { get; set; } = new(); + /// + /// The previous episode that should be seen before viewing this one. + /// + [LoadableRelation] public Episode? PreviousEpisode { get; set; } + + /// + /// The next episode to watch after this one. + /// + [LoadableRelation] public Episode? NextEpisode { get; set; } + + /// + /// Links to watch this episode. + /// + public object Links => new + { + Direct = $"/video/episode/{Slug}/direct", + Hls = $"/video/episode/{Slug}/master.m3u8", + }; + /// /// Get the slug of an episode. /// diff --git a/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs b/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs index 99a9f854..de9b6243 100644 --- a/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs +++ b/back/src/Kyoo.Abstractions/Models/Resources/Movie.cs @@ -121,6 +121,15 @@ namespace Kyoo.Abstractions.Models /// [LoadableRelation] public ICollection? Collections { get; set; } + /// + /// Links to watch this movie. + /// + public object Links => new + { + Direct = $"/video/movie/{Slug}/direct", + Hls = $"/video/movie/{Slug}/master.m3u8", + }; + /// public void OnMerge(object merged) { diff --git a/back/src/Kyoo.Core/Controllers/LibraryManager.cs b/back/src/Kyoo.Core/Controllers/LibraryManager.cs index d2c4d172..b134e76b 100644 --- a/back/src/Kyoo.Core/Controllers/LibraryManager.cs +++ b/back/src/Kyoo.Core/Controllers/LibraryManager.cs @@ -255,6 +255,28 @@ namespace Kyoo.Core.Controllers .GetAll(x => x.Collections.Any(y => y.Id == obj.Id)) .Then(x => c.Shows = x), + (Collection c, nameof(Collection.Movies)) => MovieRepository + .GetAll(x => x.Collections.Any(y => y.Id == obj.Id)) + .Then(x => c.Movies = x), + + + (Movie m, nameof(Movie.People)) => PeopleRepository + .GetFromShow(obj.Id) + .Then(x => m.People = x), + + (Movie m, nameof(Movie.Collections)) => CollectionRepository + .GetAll(x => x.Movies.Any(y => y.Id == obj.Id)) + .Then(x => m.Collections = x), + + (Movie m, nameof(Movie.Studio)) => StudioRepository + .GetOrDefault(x => x.Movies.Any(y => y.Id == obj.Id)) + .Then(x => + { + m.Studio = x; + m.StudioID = x?.Id ?? 0; + }), + + (Show s, nameof(Show.People)) => PeopleRepository .GetFromShow(obj.Id) .Then(x => s.People = x), @@ -312,11 +334,28 @@ namespace Kyoo.Core.Controllers e.SeasonID = x?.Id ?? 0; }), + (Episode e, nameof(Episode.PreviousEpisode)) => EpisodeRepository + .GetAll( + where: x => x.ShowID == e.ShowID, + limit: new Pagination(1, e.Id, true) + ).Then(x => e.PreviousEpisode = x.FirstOrDefault()), + + (Episode e, nameof(Episode.NextEpisode)) => EpisodeRepository + .GetAll( + where: x => x.ShowID == e.ShowID, + limit: new Pagination(1, e.Id) + ).Then(x => e.NextEpisode = x.FirstOrDefault()), + (Studio s, nameof(Studio.Shows)) => ShowRepository .GetAll(x => x.Studio.Id == obj.Id) .Then(x => s.Shows = x), + (Studio s, nameof(Studio.Movies)) => MovieRepository + .GetAll(x => x.Studio.Id == obj.Id) + .Then(x => s.Movies = x), + + (People p, nameof(People.Roles)) => PeopleRepository .GetFromPeople(obj.Id) .Then(x => p.Roles = x), diff --git a/back/src/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs b/back/src/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs index 3414b63c..33dd9b8b 100644 --- a/back/src/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs +++ b/back/src/Kyoo.Core/Controllers/Repositories/LibraryItemRepository.cs @@ -69,8 +69,6 @@ namespace Kyoo.Core.Controllers Pagination limit = default) { return await ApplyFilters(_database.LibraryItems, where, sort, limit); - // .Select(x => x.ToItem()) - // .ToList(); } /// diff --git a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs index e8cacb82..a5daeec4 100644 --- a/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs +++ b/back/src/Kyoo.Core/Views/Helper/Serializers/JsonSerializerContract.cs @@ -16,7 +16,6 @@ // You should have received a copy of the GNU General Public License // along with Kyoo. If not, see . -using System; using System.Collections.Generic; using System.Reflection; using Kyoo.Abstractions.Models; @@ -73,76 +72,5 @@ namespace Kyoo.Core.Api property.ShouldDeserialize = _ => false; return property; } - - /// - protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) - { - IList properties = base.CreateProperties(type, memberSerialization); - // if (!type.IsAssignableTo(typeof(Image))) - // return properties; - // foreach ((int id, string image) in Images.ImageName) - // { - // properties.Add(new JsonProperty - // { - // DeclaringType = type, - // PropertyName = image.ToLower(), - // UnderlyingName = image, - // PropertyType = typeof(string), - // Readable = true, - // Writable = false, - // ItemIsReference = false, - // TypeNameHandling = TypeNameHandling.None, - // ShouldSerialize = x => - // { - // IThumbnails thumb = (IThumbnails)x; - // return thumb?.Images?.ContainsKey(id) == true; - // }, - // ValueProvider = new ThumbnailProvider(id) - // }); - // } - return properties; - } - - /// - /// A custom that uses the - /// . as a value. - /// - private class ThumbnailProvider : IValueProvider - { - /// - /// The index/ID of the image to retrieve/set. - /// - private readonly int _imageIndex; - - /// - /// Create a new . - /// - /// The index/ID of the image to retrieve/set. - public ThumbnailProvider(int imageIndex) - { - _imageIndex = imageIndex; - } - - /// - public void SetValue(object target, object value) - { - throw new NotSupportedException(); - } - - /// - public object GetValue(object target) - { - return null; - // string slug = (target as IResource)?.Slug ?? (target as ICustomTypeDescriptor)?.GetComponentName(); - // if (target is not IThumbnails thumb - // || slug == null - // || string.IsNullOrEmpty(thumb.Images?.GetValueOrDefault(_imageIndex))) - // return null; - // string type = target is ICustomTypeDescriptor descriptor - // ? descriptor.GetClassName() - // : target.GetType().Name; - // return $"/{type}/{slug}/{Images.ImageName[_imageIndex]}".ToLowerInvariant(); - } - } } } diff --git a/back/src/Kyoo.Postgresql/DatabaseContext.cs b/back/src/Kyoo.Postgresql/DatabaseContext.cs index 7982c6e6..3d794f2c 100644 --- a/back/src/Kyoo.Postgresql/DatabaseContext.cs +++ b/back/src/Kyoo.Postgresql/DatabaseContext.cs @@ -231,6 +231,10 @@ namespace Kyoo.Postgresql { base.OnModelCreating(modelBuilder); + modelBuilder.Entity() + .Ignore(x => x.PreviousEpisode) + .Ignore(x => x.NextEpisode); + modelBuilder.Entity() .Ignore(x => x.ForPeople);