From bc7a314409592f218f04fe561b5a52b4403a1a27 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 16 Feb 2021 00:08:36 +0100 Subject: [PATCH] Replacing IEnumearble with ICollections inside resources --- Kyoo.Common/Controllers/ILibraryManager.cs | 7 +++-- Kyoo.Common/Controllers/IMetadataProvider.cs | 4 +-- Kyoo.Common/Controllers/IProviderManager.cs | 2 +- Kyoo.Common/Kyoo.Common.csproj | 6 ++++- Kyoo.Common/Models/PeopleRole.cs | 9 ++++--- Kyoo.Common/Models/Plugin.cs | 2 +- Kyoo.Common/Models/Resources/Collection.cs | 4 +-- Kyoo.Common/Models/Resources/Episode.cs | 17 ++++-------- Kyoo.Common/Models/Resources/Genre.cs | 2 +- Kyoo.Common/Models/Resources/Library.cs | 13 +++++----- Kyoo.Common/Models/Resources/People.cs | 7 ++--- Kyoo.Common/Models/Resources/Season.cs | 7 ++--- Kyoo.Common/Models/Resources/Show.cs | 26 +++++++++---------- Kyoo.Common/Models/Resources/Studio.cs | 2 +- .../ALibraryManager.cs | 19 ++++++++------ .../LibraryManager.cs | 9 ++++--- Kyoo/Controllers/ProviderManager.cs | 4 +-- Kyoo/Kyoo.csproj | 4 +-- Kyoo/Models/DatabaseContext.cs | 2 +- Kyoo/Models/Resources/CollectionDE.cs | 8 +++--- Kyoo/Models/Resources/GenreDE.cs | 4 +-- Kyoo/Models/Resources/LibraryDE.cs | 12 ++++----- Kyoo/Models/Resources/ShowDE.cs | 12 ++++----- Kyoo/Program.cs | 2 +- Kyoo/Startup.cs | 2 +- Kyoo/Tasks/Crawler.cs | 5 ++-- Kyoo/Tasks/ExtractMetadata.cs | 4 +-- 27 files changed, 99 insertions(+), 96 deletions(-) rename {Kyoo.Common/Controllers/Implementations => Kyoo.CommonAPI}/ALibraryManager.cs (97%) rename {Kyoo/Controllers => Kyoo.CommonAPI}/LibraryManager.cs (88%) diff --git a/Kyoo.Common/Controllers/ILibraryManager.cs b/Kyoo.Common/Controllers/ILibraryManager.cs index 4e75a971..2cdbaf50 100644 --- a/Kyoo.Common/Controllers/ILibraryManager.cs +++ b/Kyoo.Common/Controllers/ILibraryManager.cs @@ -240,10 +240,9 @@ namespace Kyoo.Controllers Task EditGenre(Genre genre, bool resetOld); Task EditStudio(Studio studio, bool resetOld); Task EditPeople(People people, bool resetOld); - // Delete values - Task DelteLibrary(Library library); + Task DeleteLibrary(Library library); Task DeleteCollection(Collection collection); Task DeleteShow(Show show); Task DeleteSeason(Season season); @@ -254,7 +253,7 @@ namespace Kyoo.Controllers Task DeletePeople(People people); //Delete by slug - Task DelteLibrary(string slug); + Task DeleteLibrary(string slug); Task DeleteCollection(string slug); Task DeleteShow(string slug); Task DeleteSeason(string slug); @@ -265,7 +264,7 @@ namespace Kyoo.Controllers Task DeletePeople(string slug); //Delete by id - Task DelteLibrary(int id); + Task DeleteLibrary(int id); Task DeleteCollection(int id); Task DeleteShow(int id); Task DeleteSeason(int id); diff --git a/Kyoo.Common/Controllers/IMetadataProvider.cs b/Kyoo.Common/Controllers/IMetadataProvider.cs index c552d5e3..6cf8a6ac 100644 --- a/Kyoo.Common/Controllers/IMetadataProvider.cs +++ b/Kyoo.Common/Controllers/IMetadataProvider.cs @@ -11,8 +11,8 @@ namespace Kyoo.Controllers Task GetCollectionFromName(string name); Task GetShowByID(Show show); - Task> SearchShows(string showName, bool isMovie); - Task> GetPeople(Show show); + Task> SearchShows(string showName, bool isMovie); + Task> GetPeople(Show show); Task GetSeason(Show show, int seasonNumber); diff --git a/Kyoo.Common/Controllers/IProviderManager.cs b/Kyoo.Common/Controllers/IProviderManager.cs index 07f09cb2..d1136052 100644 --- a/Kyoo.Common/Controllers/IProviderManager.cs +++ b/Kyoo.Common/Controllers/IProviderManager.cs @@ -12,6 +12,6 @@ namespace Kyoo.Controllers Task> SearchShows(string showName, bool isMovie, Library library); Task GetSeason(Show show, int seasonNumber, Library library); Task GetEpisode(Show show, string episodePath, int seasonNumber, int episodeNumber, int absoluteNumber, Library library); - Task> GetPeople(Show show, Library library); + Task> GetPeople(Show show, Library library); } } \ No newline at end of file diff --git a/Kyoo.Common/Kyoo.Common.csproj b/Kyoo.Common/Kyoo.Common.csproj index 8d3adcd9..44f198b9 100644 --- a/Kyoo.Common/Kyoo.Common.csproj +++ b/Kyoo.Common/Kyoo.Common.csproj @@ -12,7 +12,7 @@ SDG GPL-3.0-or-later true - 1.0.22 + 1.0.23 true snupkg default @@ -23,4 +23,8 @@ + + + + diff --git a/Kyoo.Common/Models/PeopleRole.cs b/Kyoo.Common/Models/PeopleRole.cs index 54fe48cb..a9fc0582 100644 --- a/Kyoo.Common/Models/PeopleRole.cs +++ b/Kyoo.Common/Models/PeopleRole.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Linq.Expressions; using Kyoo.Models.Attributes; @@ -33,7 +34,7 @@ namespace Kyoo.Models } [ExpressionRewrite(nameof(People) + "."+ nameof(Models.People.ExternalIDs))] - public IEnumerable ExternalIDs + public ICollection ExternalIDs { get => People.ExternalIDs; set => People.ExternalIDs = value; @@ -75,7 +76,7 @@ namespace Kyoo.Models public string Slug { get; set; } public string Title { get; set; } - public IEnumerable Aliases { get; set; } + public ICollection Aliases { get; set; } [JsonIgnore] public string Path { get; set; } public string Overview { get; set; } public Status? Status { get; set; } @@ -96,7 +97,7 @@ namespace Kyoo.Models Type = x.Type; Slug = x.Show.Slug; Title = x.Show.Title; - Aliases = x.Show.Aliases; + Aliases = x.Show.Aliases?.ToArray(); Path = x.Show.Path; Overview = x.Show.Overview; Status = x.Show.Status; @@ -116,7 +117,7 @@ namespace Kyoo.Models Type = x.Type, Slug = x.Show.Slug, Title = x.Show.Title, - Aliases = x.Show.Aliases, + Aliases = x.Show.Aliases != null ? x.Show.Aliases.ToArray() : null, Path = x.Show.Path, Overview = x.Show.Overview, Status = x.Show.Status, diff --git a/Kyoo.Common/Models/Plugin.cs b/Kyoo.Common/Models/Plugin.cs index 9965d1ba..7947d542 100644 --- a/Kyoo.Common/Models/Plugin.cs +++ b/Kyoo.Common/Models/Plugin.cs @@ -5,6 +5,6 @@ namespace Kyoo.Models public interface IPlugin { public string Name { get; } - public IEnumerable Tasks { get; } + public ICollection Tasks { get; } } } \ No newline at end of file diff --git a/Kyoo.Common/Models/Resources/Collection.cs b/Kyoo.Common/Models/Resources/Collection.cs index 2e8c85bc..283fe017 100644 --- a/Kyoo.Common/Models/Resources/Collection.cs +++ b/Kyoo.Common/Models/Resources/Collection.cs @@ -10,8 +10,8 @@ namespace Kyoo.Models public string Name { get; set; } public string Poster { get; set; } public string Overview { get; set; } - [JsonIgnore] public virtual IEnumerable Shows { get; set; } - [JsonIgnore] public virtual IEnumerable Libraries { get; set; } + [JsonIgnore] public virtual ICollection Shows { get; set; } + [JsonIgnore] public virtual ICollection Libraries { get; set; } public Collection() { } diff --git a/Kyoo.Common/Models/Resources/Episode.cs b/Kyoo.Common/Models/Resources/Episode.cs index cd7c1a24..7a8007ee 100644 --- a/Kyoo.Common/Models/Resources/Episode.cs +++ b/Kyoo.Common/Models/Resources/Episode.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Kyoo.Models.Attributes; namespace Kyoo.Models @@ -24,9 +25,9 @@ namespace Kyoo.Models public int Runtime { get; set; } //This runtime variable should be in minutes [JsonIgnore] public string Poster { get; set; } - [EditableRelation] public virtual IEnumerable ExternalIDs { get; set; } + [EditableRelation] public virtual ICollection ExternalIDs { get; set; } - [JsonIgnore] public virtual IEnumerable Tracks { get; set; } + [JsonIgnore] public virtual ICollection Tracks { get; set; } public string ShowTitle => Show.Title; public string Slug => Show != null ? GetSlug(Show.Slug, SeasonNumber, EpisodeNumber) : ID.ToString(); @@ -61,7 +62,7 @@ namespace Kyoo.Models ReleaseDate = releaseDate; Runtime = runtime; Poster = poster; - ExternalIDs = externalIDs; + ExternalIDs = externalIDs?.ToArray(); } public Episode(int showID, @@ -76,19 +77,11 @@ namespace Kyoo.Models int runtime, string poster, IEnumerable externalIDs) + : this(seasonNumber, episodeNumber, absoluteNumber, title, overview, releaseDate, runtime, poster, externalIDs) { ShowID = showID; SeasonID = seasonID; - SeasonNumber = seasonNumber; - EpisodeNumber = episodeNumber; - AbsoluteNumber = absoluteNumber; Path = path; - Title = title; - Overview = overview; - ReleaseDate = releaseDate; - Runtime = runtime; - Poster = poster; - ExternalIDs = externalIDs; } public static string GetSlug(string showSlug, int seasonNumber, int episodeNumber) diff --git a/Kyoo.Common/Models/Resources/Genre.cs b/Kyoo.Common/Models/Resources/Genre.cs index 947a2866..16e8640d 100644 --- a/Kyoo.Common/Models/Resources/Genre.cs +++ b/Kyoo.Common/Models/Resources/Genre.cs @@ -9,7 +9,7 @@ namespace Kyoo.Models public string Slug { get; set; } public string Name { get; set; } - [JsonIgnore] public virtual IEnumerable Shows { get; set; } + [JsonIgnore] public virtual ICollection Shows { get; set; } public Genre() {} diff --git a/Kyoo.Common/Models/Resources/Library.cs b/Kyoo.Common/Models/Resources/Library.cs index 765d48d3..de3ea5fc 100644 --- a/Kyoo.Common/Models/Resources/Library.cs +++ b/Kyoo.Common/Models/Resources/Library.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Kyoo.Models.Attributes; namespace Kyoo.Models @@ -8,12 +9,12 @@ namespace Kyoo.Models [JsonIgnore] public int ID { get; set; } public string Slug { get; set; } public string Name { get; set; } - public IEnumerable Paths { get; set; } + public ICollection Paths { get; set; } - [EditableRelation] public virtual IEnumerable Providers { get; set; } + [EditableRelation] public virtual ICollection Providers { get; set; } - [JsonIgnore] public virtual IEnumerable Shows { get; set; } - [JsonIgnore] public virtual IEnumerable Collections { get; set; } + [JsonIgnore] public virtual ICollection Shows { get; set; } + [JsonIgnore] public virtual ICollection Collections { get; set; } public Library() { } @@ -21,8 +22,8 @@ namespace Kyoo.Models { Slug = slug; Name = name; - Paths = paths; - Providers = providers; + Paths = paths?.ToArray(); + Providers = providers?.ToArray(); } } } diff --git a/Kyoo.Common/Models/Resources/People.cs b/Kyoo.Common/Models/Resources/People.cs index 5b8828b8..fe9cc4a1 100644 --- a/Kyoo.Common/Models/Resources/People.cs +++ b/Kyoo.Common/Models/Resources/People.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Kyoo.Models.Attributes; namespace Kyoo.Models @@ -9,9 +10,9 @@ namespace Kyoo.Models public string Slug { get; set; } public string Name { get; set; } public string Poster { get; set; } - [EditableRelation] public virtual IEnumerable ExternalIDs { get; set; } + [EditableRelation] public virtual ICollection ExternalIDs { get; set; } - [EditableRelation] [JsonReadOnly] public virtual IEnumerable Roles { get; set; } + [EditableRelation] [JsonReadOnly] public virtual ICollection Roles { get; set; } public People() {} @@ -20,7 +21,7 @@ namespace Kyoo.Models Slug = slug; Name = name; Poster = poster; - ExternalIDs = externalIDs; + ExternalIDs = externalIDs?.ToArray(); } } } diff --git a/Kyoo.Common/Models/Resources/Season.cs b/Kyoo.Common/Models/Resources/Season.cs index d7843e5c..0aee3e9a 100644 --- a/Kyoo.Common/Models/Resources/Season.cs +++ b/Kyoo.Common/Models/Resources/Season.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Kyoo.Models.Attributes; namespace Kyoo.Models @@ -17,10 +18,10 @@ namespace Kyoo.Models public int? Year { get; set; } [JsonIgnore] public string Poster { get; set; } - [EditableRelation] public virtual IEnumerable ExternalIDs { get; set; } + [EditableRelation] public virtual ICollection ExternalIDs { get; set; } [JsonIgnore] public virtual Show Show { get; set; } - [JsonIgnore] public virtual IEnumerable Episodes { get; set; } + [JsonIgnore] public virtual ICollection Episodes { get; set; } public Season() { } @@ -38,7 +39,7 @@ namespace Kyoo.Models Overview = overview; Year = year; Poster = poster; - ExternalIDs = externalIDs; + ExternalIDs = externalIDs?.ToArray(); } } } diff --git a/Kyoo.Common/Models/Resources/Show.cs b/Kyoo.Common/Models/Resources/Show.cs index 69bf72ec..675f45dc 100644 --- a/Kyoo.Common/Models/Resources/Show.cs +++ b/Kyoo.Common/Models/Resources/Show.cs @@ -9,7 +9,7 @@ namespace Kyoo.Models public int ID { get; set; } public string Slug { get; set; } public string Title { get; set; } - [EditableRelation] public IEnumerable Aliases { get; set; } + [EditableRelation] public ICollection Aliases { get; set; } [JsonIgnore] public string Path { get; set; } public string Overview { get; set; } public Status? Status { get; set; } @@ -24,17 +24,17 @@ namespace Kyoo.Models public bool IsMovie { get; set; } - [EditableRelation] public virtual IEnumerable ExternalIDs { get; set; } + [EditableRelation] public virtual ICollection ExternalIDs { get; set; } [JsonIgnore] public int? StudioID { get; set; } [EditableRelation] [JsonReadOnly] public virtual Studio Studio { get; set; } - [EditableRelation] [JsonReadOnly] public virtual IEnumerable Genres { get; set; } - [EditableRelation] [JsonReadOnly] public virtual IEnumerable People { get; set; } - [JsonIgnore] public virtual IEnumerable Seasons { get; set; } - [JsonIgnore] public virtual IEnumerable Episodes { get; set; } - [JsonIgnore] public virtual IEnumerable Libraries { get; set; } - [JsonIgnore] public virtual IEnumerable Collections { get; set; } + [EditableRelation] [JsonReadOnly] public virtual ICollection Genres { get; set; } + [EditableRelation] [JsonReadOnly] public virtual ICollection People { get; set; } + [JsonIgnore] public virtual ICollection Seasons { get; set; } + [JsonIgnore] public virtual ICollection Episodes { get; set; } + [JsonIgnore] public virtual ICollection Libraries { get; set; } + [JsonIgnore] public virtual ICollection Collections { get; set; } public Show() { } @@ -51,15 +51,15 @@ namespace Kyoo.Models { Slug = slug; Title = title; - Aliases = aliases; + Aliases = aliases?.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; - Genres = genres; + Genres = genres?.ToArray(); Status = status; StartYear = startYear; EndYear = endYear; - ExternalIDs = externalIDs; + ExternalIDs = externalIDs?.ToArray(); } public Show(string slug, @@ -78,7 +78,7 @@ namespace Kyoo.Models { Slug = slug; Title = title; - Aliases = aliases; + Aliases = aliases?.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; @@ -88,7 +88,7 @@ namespace Kyoo.Models Poster = poster; Logo = logo; Backdrop = backdrop; - ExternalIDs = externalIDs; + ExternalIDs = externalIDs?.ToArray(); } public string GetID(string provider) diff --git a/Kyoo.Common/Models/Resources/Studio.cs b/Kyoo.Common/Models/Resources/Studio.cs index 1bbb6014..07959b01 100644 --- a/Kyoo.Common/Models/Resources/Studio.cs +++ b/Kyoo.Common/Models/Resources/Studio.cs @@ -9,7 +9,7 @@ namespace Kyoo.Models public string Slug { get; set; } public string Name { get; set; } - [JsonIgnore] public virtual IEnumerable Shows { get; set; } + [JsonIgnore] public virtual ICollection Shows { get; set; } public Studio() { } diff --git a/Kyoo.Common/Controllers/Implementations/ALibraryManager.cs b/Kyoo.CommonAPI/ALibraryManager.cs similarity index 97% rename from Kyoo.Common/Controllers/Implementations/ALibraryManager.cs rename to Kyoo.CommonAPI/ALibraryManager.cs index ab99f4f8..d809d334 100644 --- a/Kyoo.Common/Controllers/Implementations/ALibraryManager.cs +++ b/Kyoo.CommonAPI/ALibraryManager.cs @@ -6,7 +6,7 @@ using Kyoo.Models; namespace Kyoo.Controllers { - public abstract class ALibraryManager : ILibraryManager + public class LibraryManager : ILibraryManager { public ILibraryRepository LibraryRepository { get; } public ILibraryItemRepository LibraryItemRepository { get; } @@ -19,8 +19,8 @@ namespace Kyoo.Controllers public IStudioRepository StudioRepository { get; } public IPeopleRepository PeopleRepository { get; } public IProviderRepository ProviderRepository { get; } - - public ALibraryManager(ILibraryRepository libraryRepository, + + protected LibraryManager(ILibraryRepository libraryRepository, ILibraryItemRepository libraryItemRepository, ICollectionRepository collectionRepository, IShowRepository showRepository, @@ -235,9 +235,12 @@ namespace Kyoo.Controllers return PeopleRepository.Get(where); } - public abstract Task Load(T obj, Expression> member) + public virtual Task Load(T obj, Expression> member) where T : class, IResource - where T2 : class; + where T2 : class + { + return Task.CompletedTask; + } public Task> GetLibraries(Expression> where = null, Sort sort = default, @@ -544,7 +547,7 @@ namespace Kyoo.Controllers return PeopleRepository.Edit(people, resetOld); } - public Task DelteLibrary(Library library) + public Task DeleteLibrary(Library library) { return LibraryRepository.Delete(library); } @@ -589,7 +592,7 @@ namespace Kyoo.Controllers return PeopleRepository.Delete(people); } - public Task DelteLibrary(string library) + public Task DeleteLibrary(string library) { return LibraryRepository.Delete(library); } @@ -634,7 +637,7 @@ namespace Kyoo.Controllers return PeopleRepository.Delete(people); } - public Task DelteLibrary(int library) + public Task DeleteLibrary(int library) { return LibraryRepository.Delete(library); } diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo.CommonAPI/LibraryManager.cs similarity index 88% rename from Kyoo/Controllers/LibraryManager.cs rename to Kyoo.CommonAPI/LibraryManager.cs index 593b0645..5df48c89 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo.CommonAPI/LibraryManager.cs @@ -3,15 +3,16 @@ using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace Kyoo.Controllers { - public class LibraryManager : ALibraryManager + public class TLibraryManager : LibraryManager { - private readonly DatabaseContext _database; + private readonly DbContext _database; - public LibraryManager(ILibraryRepository libraryRepository, + public TLibraryManager(ILibraryRepository libraryRepository, ILibraryItemRepository libraryItemRepository, ICollectionRepository collectionRepository, IShowRepository showRepository, @@ -22,7 +23,7 @@ namespace Kyoo.Controllers IStudioRepository studioRepository, IProviderRepository providerRepository, IPeopleRepository peopleRepository, - DatabaseContext database) + DbContext database) : base(libraryRepository, libraryItemRepository, collectionRepository, diff --git a/Kyoo/Controllers/ProviderManager.cs b/Kyoo/Controllers/ProviderManager.cs index 346f71be..1efea8e5 100644 --- a/Kyoo/Controllers/ProviderManager.cs +++ b/Kyoo/Controllers/ProviderManager.cs @@ -40,7 +40,7 @@ namespace Kyoo.Controllers } private async Task> GetMetadata( - Func>> providerCall, + Func>> providerCall, Library library, string what) { @@ -146,7 +146,7 @@ namespace Kyoo.Controllers return episode; } - public async Task> GetPeople(Show show, Library library) + public async Task> GetPeople(Show show, Library library) { List people = await GetMetadata( provider => provider.GetPeople(show), diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index cb1faf12..7c15982f 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -20,6 +20,8 @@ + + @@ -28,7 +30,6 @@ - @@ -45,7 +46,6 @@ - diff --git a/Kyoo/Models/DatabaseContext.cs b/Kyoo/Models/DatabaseContext.cs index 96744687..236b82c2 100644 --- a/Kyoo/Models/DatabaseContext.cs +++ b/Kyoo/Models/DatabaseContext.cs @@ -44,7 +44,7 @@ namespace Kyoo NpgsqlConnection.GlobalTypeMapper.MapEnum(); } - private readonly ValueComparer> _stringArrayComparer = new( + private readonly ValueComparer> _stringArrayComparer = new( (l1, l2) => l1.SequenceEqual(l2), arr => arr.Aggregate(0, (i, s) => s.GetHashCode()) ); diff --git a/Kyoo/Models/Resources/CollectionDE.cs b/Kyoo/Models/Resources/CollectionDE.cs index ddc02b55..622e602e 100644 --- a/Kyoo/Models/Resources/CollectionDE.cs +++ b/Kyoo/Models/Resources/CollectionDE.cs @@ -8,18 +8,18 @@ namespace Kyoo.Models { [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(CollectionLink.Child))] - public override IEnumerable Shows + public override ICollection Shows { - get => Links?.Select(x => x.Child); + get => Links?.Select(x => x.Child).ToList(); set => Links = value?.Select(x => new CollectionLink(this, x)).ToList(); } [JsonIgnore] [NotMergable] public virtual ICollection LibraryLinks { get; set; } [ExpressionRewrite(nameof(LibraryLinks), nameof(GenreLink.Child))] - public override IEnumerable Libraries + public override ICollection Libraries { - get => LibraryLinks?.Select(x => x.Library); + get => LibraryLinks?.Select(x => x.Library).ToList(); set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)).ToList(); } diff --git a/Kyoo/Models/Resources/GenreDE.cs b/Kyoo/Models/Resources/GenreDE.cs index 1832cd38..892be000 100644 --- a/Kyoo/Models/Resources/GenreDE.cs +++ b/Kyoo/Models/Resources/GenreDE.cs @@ -9,9 +9,9 @@ namespace Kyoo.Models [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(GenreLink.Child))] - [JsonIgnore] [NotMergable] public override IEnumerable Shows + [JsonIgnore] [NotMergable] public override ICollection Shows { - get => Links?.Select(x => x.Parent); + get => Links?.Select(x => x.Parent).ToList(); set => Links = value?.Select(x => new GenreLink(x, this)).ToList(); } diff --git a/Kyoo/Models/Resources/LibraryDE.cs b/Kyoo/Models/Resources/LibraryDE.cs index 1bd097bf..32992c6c 100644 --- a/Kyoo/Models/Resources/LibraryDE.cs +++ b/Kyoo/Models/Resources/LibraryDE.cs @@ -8,25 +8,25 @@ namespace Kyoo.Models { [EditableRelation] [JsonIgnore] [NotMergable] public virtual ICollection ProviderLinks { get; set; } [ExpressionRewrite(nameof(ProviderLinks), nameof(ProviderLink.Child))] - public override IEnumerable Providers + public override ICollection Providers { - get => ProviderLinks?.Select(x => x.Child); + get => ProviderLinks?.Select(x => x.Child).ToList(); set => ProviderLinks = value?.Select(x => new ProviderLink(x, this)).ToList(); } [JsonIgnore] [NotMergable] public virtual ICollection Links { get; set; } [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Show))] - public override IEnumerable Shows + public override ICollection Shows { - get => Links?.Where(x => x.Show != null).Select(x => x.Show); + get => Links?.Where(x => x.Show != null).Select(x => x.Show).ToList(); set => Links = Utility.MergeLists( value?.Select(x => new LibraryLink(this, x)), Links?.Where(x => x.Show == null))?.ToList(); } [ExpressionRewrite(nameof(Links), nameof(LibraryLink.Collection))] - public override IEnumerable Collections + public override ICollection Collections { - get => Links?.Where(x => x.Collection != null).Select(x => x.Collection); + get => Links?.Where(x => x.Collection != null).Select(x => x.Collection).ToList(); set => Links = Utility.MergeLists( value?.Select(x => new LibraryLink(this, x)), Links?.Where(x => x.Collection == null))?.ToList(); diff --git a/Kyoo/Models/Resources/ShowDE.cs b/Kyoo/Models/Resources/ShowDE.cs index 04e26994..e1928214 100644 --- a/Kyoo/Models/Resources/ShowDE.cs +++ b/Kyoo/Models/Resources/ShowDE.cs @@ -8,25 +8,25 @@ namespace Kyoo.Models { [EditableRelation] [JsonReadOnly] [NotMergable] public virtual ICollection GenreLinks { get; set; } [ExpressionRewrite(nameof(GenreLinks), nameof(GenreLink.Child))] - public override IEnumerable Genres + public override ICollection Genres { - get => GenreLinks?.Select(x => x.Child); + get => GenreLinks?.Select(x => x.Child).ToList(); set => GenreLinks = value?.Select(x => new GenreLink(this, x)).ToList(); } [JsonReadOnly] [NotMergable] public virtual ICollection LibraryLinks { get; set; } [ExpressionRewrite(nameof(LibraryLinks), nameof(LibraryLink.Library))] - public override IEnumerable Libraries + public override ICollection Libraries { - get => LibraryLinks?.Select(x => x.Library); + get => LibraryLinks?.Select(x => x.Library).ToList(); set => LibraryLinks = value?.Select(x => new LibraryLink(x, this)).ToList(); } [JsonReadOnly] [NotMergable] public virtual ICollection CollectionLinks { get; set; } [ExpressionRewrite(nameof(CollectionLinks), nameof(CollectionLink.Parent))] - public override IEnumerable Collections + public override ICollection Collections { - get => CollectionLinks?.Select(x => x.Parent); + get => CollectionLinks?.Select(x => x.Parent).ToList(); set => CollectionLinks = value?.Select(x => new CollectionLink(x, this)).ToList(); } diff --git a/Kyoo/Program.cs b/Kyoo/Program.cs index bc6ef89b..eae316f2 100644 --- a/Kyoo/Program.cs +++ b/Kyoo/Program.cs @@ -29,7 +29,7 @@ namespace Kyoo _ => null }; - if (debug == null) + if (debug == null && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ENVIRONEMENT"))) Console.WriteLine($"Invalid ENVIRONEMENT variable. Supported values are \"debug\" and \"prod\". Ignoring..."); Console.WriteLine($"Running as {Environment.UserName}."); diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index 9f32b56d..948bdb7a 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -147,7 +147,7 @@ namespace Kyoo services.AddScoped(); services.AddScoped(); - services.AddScoped(); + // services.AddScoped(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/Kyoo/Tasks/Crawler.cs b/Kyoo/Tasks/Crawler.cs index 35eb2ae1..92ba2342 100644 --- a/Kyoo/Tasks/Crawler.cs +++ b/Kyoo/Tasks/Crawler.cs @@ -75,9 +75,8 @@ namespace Kyoo.Controllers ICollection libraries = argument == null ? await libraryManager.GetLibraries() : new [] { await libraryManager.GetLibrary(argument)}; - // TODO replace this grotesque way to load the providers. foreach (Library library in libraries) - library.Providers = library.Providers; + await libraryManager.Load(library, x => x.Providers); foreach (Library library in libraries) await Scan(library, episodes, tracks, cancellationToken); @@ -353,7 +352,7 @@ namespace Kyoo.Controllers return episode; } - private async Task> GetTracks(Episode episode) + private async Task> GetTracks(Episode episode) { episode.Tracks = (await _transcoder.ExtractInfos(episode.Path)) .Where(x => x.Type != StreamType.Font) diff --git a/Kyoo/Tasks/ExtractMetadata.cs b/Kyoo/Tasks/ExtractMetadata.cs index ac613e0e..85c81612 100644 --- a/Kyoo/Tasks/ExtractMetadata.cs +++ b/Kyoo/Tasks/ExtractMetadata.cs @@ -99,8 +99,8 @@ namespace Kyoo.Tasks if (subs) { // TODO handle external subtites. - episode.Tracks = (await _transcoder!.ExtractInfos(episode.Path)) - .Where(x => x.Type != StreamType.Font); + episode.Tracks = (await _transcoder!.ExtractInfos(episode.Path)) + .Where(x => x.Type != StreamType.Font).ToArray(); await _library.EditEpisode(episode, false); } }