diff --git a/Kyoo.Common/Models/Collection.cs b/Kyoo.Common/Models/Collection.cs index 74d63518..fb3aee7d 100644 --- a/Kyoo.Common/Models/Collection.cs +++ b/Kyoo.Common/Models/Collection.cs @@ -6,21 +6,20 @@ using System.Linq; namespace Kyoo.Models { public class Collection : IMergable - { - [JsonIgnore] public long ID = -1; - public string Slug; - public string Name; - public string Poster; - public string Overview; - [JsonIgnore] public string ImgPrimary; + [JsonIgnore] public long Id { get; set; } = -1; + public string Slug { get; set; } + public string Name { get; set; } + public string Poster { get; set; } + public string Overview { get; set; } + [JsonIgnore] public string ImgPrimary { get; set; } public IEnumerable Shows; public Collection() { } public Collection(long id, string slug, string name, string overview, string imgPrimary) { - ID = id; + Id = id; Slug = slug; Name = name; Overview = overview; @@ -45,7 +44,7 @@ namespace Kyoo.Models public Collection SetShows(ILibraryManager libraryManager) { - Shows = libraryManager.GetShowsInCollection(ID); + Shows = libraryManager.GetShowsInCollection(Id); return this; } @@ -53,8 +52,8 @@ namespace Kyoo.Models { if (collection == null) return this; - if (ID == -1) - ID = collection.ID; + if (Id == -1) + Id = collection.Id; if (Slug == null) Slug = collection.Slug; if (Name == null) diff --git a/Kyoo.Common/Models/Episode.cs b/Kyoo.Common/Models/Episode.cs index 3ad3aada..48ea449c 100644 --- a/Kyoo.Common/Models/Episode.cs +++ b/Kyoo.Common/Models/Episode.cs @@ -5,22 +5,24 @@ namespace Kyoo.Models { public class Episode : IMergable { - [JsonIgnore] public long ID; - [JsonIgnore] public long ShowID; - [JsonIgnore] public long SeasonID; + [JsonIgnore] public long Id { get; set; } + [JsonIgnore] public long ShowID { get; set; } + public virtual Show Show { get; set; } + [JsonIgnore] public long SeasonID { get; set; } + public virtual Season Season { get; set; } - public long SeasonNumber; - public long EpisodeNumber; - public long AbsoluteNumber; - [JsonIgnore] public string Path; - public string Title; - public string Overview; - public DateTime? ReleaseDate; + public long SeasonNumber { get; set; } + public long EpisodeNumber { get; set; } + public long AbsoluteNumber { get; set; } + [JsonIgnore] public string Path { get; set; } + public string Title { get; set; } + public string Overview { get; set; } + public DateTime? ReleaseDate { get; set; } - public long Runtime; //This runtime variable should be in minutes + public long Runtime { get; set; } //This runtime variable should be in minutes - [JsonIgnore] public string ImgPrimary; - public string ExternalIDs; + [JsonIgnore] public string ImgPrimary { get; set; } + public string ExternalIDs { get; set; } public string ShowTitle; //Used in the API response only public string Link; //Used in the API response only @@ -29,7 +31,7 @@ namespace Kyoo.Models public Episode() { - ID = -1; + Id = -1; ShowID = -1; SeasonID = -1; SeasonNumber = -1; @@ -39,7 +41,7 @@ namespace Kyoo.Models public Episode(long seasonNumber, long episodeNumber, long absoluteNumber, string title, string overview, DateTime? releaseDate, long runtime, string imgPrimary, string externalIDs) { - ID = -1; + Id = -1; ShowID = -1; SeasonID = -1; SeasonNumber = seasonNumber; @@ -55,7 +57,7 @@ namespace Kyoo.Models public Episode(long id, long showID, long seasonID, long seasonNumber, long episodeNumber, long absoluteNumber, string path, string title, string overview, DateTime? releaseDate, long runtime, string imgPrimary, string externalIDs) { - ID = id; + Id = id; ShowID = showID; SeasonID = seasonID; SeasonNumber = seasonNumber; @@ -110,8 +112,8 @@ namespace Kyoo.Models { if (other == null) return this; - if (ID == -1) - ID = other.ID; + if (Id == -1) + Id = other.Id; if (ShowID == -1) ShowID = other.ShowID; if (SeasonID == -1) diff --git a/Kyoo.Common/Models/Genre.cs b/Kyoo.Common/Models/Genre.cs index e80fa2c0..7d378950 100644 --- a/Kyoo.Common/Models/Genre.cs +++ b/Kyoo.Common/Models/Genre.cs @@ -4,9 +4,9 @@ namespace Kyoo.Models { public class Genre { - [JsonIgnore] public readonly long ID; - public string Slug; - public string Name; + [JsonIgnore] public long Id { get; set; } + public string Slug { get; set; } + public string Name { get; set; } public Genre(string slug, string name) { @@ -16,7 +16,7 @@ namespace Kyoo.Models public Genre(long id, string slug, string name) { - ID = id; + Id = id; Slug = slug; Name = name; } diff --git a/Kyoo.Common/Models/Library.cs b/Kyoo.Common/Models/Library.cs index 6b4db9af..dfe1a584 100644 --- a/Kyoo.Common/Models/Library.cs +++ b/Kyoo.Common/Models/Library.cs @@ -1,18 +1,21 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Kyoo.Models { public class Library { - [JsonIgnore] public readonly long ID; - public string Slug; - public string Name; - public string[] Paths; - public string[] Providers; + [JsonIgnore] public long Id { get; set; } + public string Slug { get; set; } + public string Name { get; set; } + public string[] Paths { get; set; } + public string[] Providers { get; set; } + public Library() { } + public Library(long id, string slug, string name, string[] paths, string[] providers) { - ID = id; + Id = id; Slug = slug; Name = name; Paths = paths; diff --git a/Kyoo.Common/Models/People.cs b/Kyoo.Common/Models/People.cs index 4c189f99..515fb9f3 100644 --- a/Kyoo.Common/Models/People.cs +++ b/Kyoo.Common/Models/People.cs @@ -1,17 +1,20 @@ -using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Kyoo.Models { public class People : IMergable { - [JsonIgnore] public long ID = -1; - public string Slug; - public string Name; - public string Role; //Dynamic data not stored as it in the database + [JsonIgnore] public long ID { get; set; } = -1; + public string Slug { get; set; } + public string Name { get; set; } + public string Role;//Dynamic data not stored as it in the database public string Type; //Dynamic data not stored as it in the database ---- Null for now - [JsonIgnore] public string ImgPrimary; - - public string ExternalIDs; + [JsonIgnore] public string ImgPrimary { get; set; } + public string ExternalIDs { get; set; } + + public virtual IEnumerable Roles { get; set; } public People() {} diff --git a/Kyoo.Common/Models/PeopleLink.cs b/Kyoo.Common/Models/PeopleLink.cs new file mode 100644 index 00000000..3729115c --- /dev/null +++ b/Kyoo.Common/Models/PeopleLink.cs @@ -0,0 +1,13 @@ +namespace Kyoo.Models +{ + public class PeopleLink + { + public long ID { get; set; } + public long PeopleID { get; set; } + public People People { get; set; } + public long ShowID { get; set; } + public Show Show { get; set; } + public string Role { get; set; } + public string Type { get; set; } + } +} \ No newline at end of file diff --git a/Kyoo.Common/Models/Season.cs b/Kyoo.Common/Models/Season.cs index 5ff2bee5..97d81f7e 100644 --- a/Kyoo.Common/Models/Season.cs +++ b/Kyoo.Common/Models/Season.cs @@ -1,19 +1,24 @@ -using Newtonsoft.Json; +using System.Collections; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Kyoo.Models { public class Season : IMergable { - [JsonIgnore] public readonly long ID = -1; - [JsonIgnore] public long ShowID = -1; + [JsonIgnore] public long ID { get; set; } = -1; + [JsonIgnore] public long ShowID { get; set; } = -1; - public long SeasonNumber = -1; - public string Title; - public string Overview; - public long? Year; + public long SeasonNumber { get; set; } = -1; + public string Title { get; set; } + public string Overview { get; set; } + public long? Year { get; set; } - [JsonIgnore] public string ImgPrimary; - public string ExternalIDs; + [JsonIgnore] public string ImgPrimary { get; set; } + public string ExternalIDs { get; set; } + + public virtual Show Show { get; set; } + public virtual IEnumerable Episodes { get; set; } public Season() { } diff --git a/Kyoo.Common/Models/Show.cs b/Kyoo.Common/Models/Show.cs index 00cbfafa..72a1c410 100644 --- a/Kyoo.Common/Models/Show.cs +++ b/Kyoo.Common/Models/Show.cs @@ -8,34 +8,34 @@ namespace Kyoo.Models { public class Show : IMergable { - [JsonIgnore] public long ID = -1; + [JsonIgnore] public long ID { get; set; } = -1; - public string Slug; - public string Title; - public IEnumerable Aliases; - [JsonIgnore] public string Path; - public string Overview; - public IEnumerable Genres; - public Status? Status; - public string TrailerUrl; + public string Slug { get; set; } + public string Title { get; set; } + public string[] Aliases { get; set; } + [JsonIgnore] public string Path { get; set; } + public string Overview { get; set; } + public Status? Status { get; set; } + public string TrailerUrl { get; set; } - public long? StartYear; - public long? EndYear; + public long? StartYear { get; set; } + public long? EndYear { get; set; } - [JsonIgnore] public string ImgPrimary; - [JsonIgnore] public string ImgThumb; - [JsonIgnore] public string ImgLogo; - [JsonIgnore] public string ImgBackdrop; + [JsonIgnore] public string ImgPrimary { get; set; } + [JsonIgnore] public string ImgThumb { get; set; } + [JsonIgnore] public string ImgLogo { get; set; } + [JsonIgnore] public string ImgBackdrop { get; set; } - public string ExternalIDs; - - //Used in the rest API excusively. - public Studio Studio; - public IEnumerable Directors; - public IEnumerable People; - public IEnumerable Seasons; + public string ExternalIDs { get; set; } + public bool IsCollection; + public IEnumerable Genres; + public virtual Studio Studio { get; set; } + public virtual IEnumerable People { get; set; } + public virtual IEnumerable Seasons { get; set; } + public virtual IEnumerable Episodes { get; set; } + public string GetAliases() { @@ -55,7 +55,7 @@ namespace Kyoo.Models ID = id; Slug = slug; Title = title; - Aliases = aliases; + Aliases = aliases.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; @@ -72,7 +72,7 @@ namespace Kyoo.Models ID = id; Slug = slug; Title = title; - Aliases = aliases; + Aliases = aliases.ToArray(); Path = path; Overview = overview; TrailerUrl = trailerUrl; @@ -152,13 +152,13 @@ namespace Kyoo.Models public Show SetDirectors(ILibraryManager manager) { - Directors = manager.GetDirectors(ID); + //Directors = manager.GetDirectors(ID); return this; } public Show SetPeople(ILibraryManager manager) { - People = manager.GetPeople(ID); + //People = manager.GetPeople(ID); return this; } @@ -181,7 +181,7 @@ namespace Kyoo.Models if (Aliases == null) Aliases = other.Aliases; else - Aliases = Aliases.Concat(other.Aliases); + Aliases = Aliases.Concat(other.Aliases).ToArray(); if (Genres == null) Genres = other.Genres; else diff --git a/Kyoo.Common/Models/Studio.cs b/Kyoo.Common/Models/Studio.cs index 48f6d68c..2fbe2ba4 100644 --- a/Kyoo.Common/Models/Studio.cs +++ b/Kyoo.Common/Models/Studio.cs @@ -4,9 +4,11 @@ namespace Kyoo.Models { public class Studio { - [JsonIgnore] public readonly long ID = -1; - public string Slug; - public string Name; + [JsonIgnore] public long ID { get; set; } = -1; + public string Slug { get; set; } + public string Name { get; set; } + + public Studio() { } public Studio(string slug, string name) { diff --git a/Kyoo.Common/Models/Track.cs b/Kyoo.Common/Models/Track.cs index f610c4e6..8671cdab 100644 --- a/Kyoo.Common/Models/Track.cs +++ b/Kyoo.Common/Models/Track.cs @@ -20,13 +20,13 @@ namespace Kyoo.Models [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public class Stream { - public string Title; - public string Language; - public string Codec; - [MarshalAs(UnmanagedType.I1)] public bool IsDefault; - [MarshalAs(UnmanagedType.I1)] public bool IsForced; - [JsonIgnore] public string Path; - [JsonIgnore] public StreamType Type; + public string Title { get; set; } + public string Language { get; set; } + public string Codec { get; set; } + [MarshalAs(UnmanagedType.I1)] public bool isDefault; + [MarshalAs(UnmanagedType.I1)] public bool isForced; + [JsonIgnore] public string Path { get; set; } + [JsonIgnore] public StreamType Type { get; set; } public Stream() {} @@ -35,8 +35,8 @@ namespace Kyoo.Models Title = title; Language = language; Codec = codec; - IsDefault = isDefault; - IsForced = isForced; + this.isDefault = isDefault; + this.isForced = isForced; Path = path; Type = type; } @@ -45,8 +45,8 @@ namespace Kyoo.Models { Title = stream.Title; Language = stream.Language; - IsDefault = stream.IsDefault; - IsForced = stream.IsForced; + isDefault = stream.isDefault; + isForced = stream.isForced; Codec = stream.Codec; Path = stream.Path; Type = stream.Type; @@ -56,11 +56,25 @@ namespace Kyoo.Models public class Track : Stream { + public int ID { get; set; } + [JsonIgnore] public long EpisodeID { get; set; } + public bool IsDefault + { + get => isDefault; + set => isDefault = value; + } + public bool IsForced + { + get => isForced; + set => isForced = value; + } public string DisplayName; public string Link; - [JsonIgnore] public long EpisodeID; - [JsonIgnore] public bool IsExternal; + [JsonIgnore] public bool IsExternal { get; set; } + public virtual Episode Episode { get; set; } + + public Track() { } public Track(StreamType type, string title, string language, bool isDefault, bool isForced, string codec, bool isExternal, string path) : base(title, language, codec, isDefault, isForced, path, type) diff --git a/Kyoo/Controllers/Crawler.cs b/Kyoo/Controllers/Crawler.cs index b7ac00b4..a072c565 100644 --- a/Kyoo/Controllers/Crawler.cs +++ b/Kyoo/Controllers/Crawler.cs @@ -183,7 +183,7 @@ namespace Kyoo.Controllers if (seasonID == -1) seasonID = await RegisterSeason(show, seasonNumber, library); episode.SeasonID = seasonID; - episode.ID = libraryManager.RegisterEpisode(episode); + episode.Id = libraryManager.RegisterEpisode(episode); Track[] tracks = await transcoder.GetTrackInfo(episode.Path); int subcount = 0; @@ -194,7 +194,7 @@ namespace Kyoo.Controllers subcount++; continue; } - track.EpisodeID = episode.ID; + track.EpisodeID = episode.Id; libraryManager.RegisterTrack(track); } @@ -205,7 +205,7 @@ namespace Kyoo.Controllers { foreach (Track track in subtitles) { - track.EpisodeID = episode.ID; + track.EpisodeID = episode.Id; libraryManager.RegisterTrack(track); } } @@ -228,7 +228,7 @@ namespace Kyoo.Controllers string language = sub.Substring(Path.GetDirectoryName(sub).Length + episodeLink.Length + 2, 3); bool isDefault = sub.Contains("default"); bool isForced = sub.Contains("forced"); - Track track = new Track(StreamType.Subtitle, null, language, isDefault, isForced, null, false, sub) { EpisodeID = episode.ID }; + Track track = new Track(StreamType.Subtitle, null, language, isDefault, isForced, null, false, sub) { EpisodeID = episode.Id }; if (Path.GetExtension(sub) == ".ass") track.Codec = "ass"; diff --git a/Kyoo/Controllers/LibraryManager.cs b/Kyoo/Controllers/LibraryManager.cs index 43b840bc..24ec9cee 100644 --- a/Kyoo/Controllers/LibraryManager.cs +++ b/Kyoo/Controllers/LibraryManager.cs @@ -11,162 +11,13 @@ namespace Kyoo.Controllers { public class LibraryManager : ILibraryManager { + private readonly DatabaseContext _database; private readonly SQLiteConnection sqlConnection; - public LibraryManager(IConfiguration configuration) + public LibraryManager(DatabaseContext database) { - string databasePath = configuration.GetValue("databasePath"); - - if (!File.Exists(databasePath)) - { - Console.WriteLine($"Creating the database at {databasePath}."); - - if (!Directory.Exists(Path.GetDirectoryName(databasePath))) - Directory.CreateDirectory(databasePath); - SQLiteConnection.CreateFile(databasePath); - sqlConnection = new SQLiteConnection($"Data Source={databasePath};Version=3"); - sqlConnection.Open(); - - const string createStatement = @"CREATE TABLE shows( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - title TEXT, - aliases TEXT, - path TEXT UNIQUE, - overview TEXT, - trailerUrl TEXT, - status TEXT, - startYear INTEGER, - endYear INTEGER, - imgPrimary TEXT, - imgThumb TEXT, - imgLogo TEXT, - imgBackdrop TEXT, - externalIDs TEXT - ); - CREATE TABLE seasons( - id INTEGER PRIMARY KEY UNIQUE, - showID INTEGER, - seasonNumber INTEGER, - title TEXT, - overview TEXT, - imgPrimary TEXT, - year INTEGER, - externalIDs TEXT, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - ); - CREATE TABLE episodes( - id INTEGER PRIMARY KEY UNIQUE, - showID INTEGER, - seasonID INTEGER, - seasonNumber INTEGER, - episodeNumber INTEGER, - absoluteNumber INTEGER, - path TEXT UNIQUE, - title TEXT, - overview TEXT, - imgPrimary TEXT, - releaseDate TEXT, - runtime INTEGER, - externalIDs TEXT, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE, - FOREIGN KEY(seasonID) REFERENCES seasons(id) ON DELETE CASCADE - ); - CREATE TABLE tracks( - id INTEGER PRIMARY KEY UNIQUE, - episodeID INTEGER, - streamType INTEGER, - title TEXT, - language TEXT, - codec TEXT, - isDefault BOOLEAN, - isForced BOOLEAN, - isExternal BOOLEAN, - path TEXT, - FOREIGN KEY(episodeID) REFERENCES episodes(id) ON DELETE CASCADE - ); - - CREATE TABLE libraries( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - name TEXT, - path TEXT, - providers TEXT - ); - CREATE TABLE librariesLinks( - libraryID INTEGER, - showID INTEGER, - FOREIGN KEY(libraryID) REFERENCES libraries(id) ON DELETE CASCADE, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - ); - - CREATE TABLE collections( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - name TEXT, - overview TEXT, - startYear INTEGER, - endYear INTEGER, - imgPrimary TEXT - ); - CREATE TABLE collectionsLinks( - collectionID INTEGER, - showID INTEGER, - FOREIGN KEY(collectionID) REFERENCES collections(id) ON DELETE CASCADE, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - ); - - CREATE TABLE studios( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - name TEXT - ); - CREATE TABLE studiosLinks( - studioID INTEGER, - showID INTEGER, - FOREIGN KEY(studioID) REFERENCES studios(id) ON DELETE CASCADE, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - ); - - CREATE TABLE people( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - name TEXT, - imgPrimary TEXT, - externalIDs TEXT - ); - CREATE TABLE peopleLinks( - peopleID INTEGER, - showID INTEGER, - role TEXT, - type TEXT, - FOREIGN KEY(peopleID) REFERENCES people(id) ON DELETE CASCADE, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - ); - - CREATE TABLE genres( - id INTEGER PRIMARY KEY UNIQUE, - slug TEXT UNIQUE, - name TEXT - ); - CREATE TABLE genresLinks( - genreID INTEGER, - showID INTEGER, - FOREIGN KEY(genreID) REFERENCES genres(id) ON DELETE CASCADE, - FOREIGN KEY(showID) REFERENCES shows(id) ON DELETE CASCADE - );"; - - using SQLiteCommand createCmd = new SQLiteCommand(createStatement, sqlConnection); - createCmd.ExecuteNonQuery(); - } - else - { - sqlConnection = new SQLiteConnection($"Data Source={databasePath};Version=3"); - sqlConnection.Open(); - } - - Debug.WriteLine("&Sql Database initated."); + _database = database; } ~LibraryManager() @@ -177,17 +28,7 @@ namespace Kyoo.Controllers #region Read the database public IEnumerable GetLibraries() { - const string query = "SELECT * FROM libraries;"; - - using SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection); - SQLiteDataReader reader = cmd.ExecuteReader(); - - List libraries = new List(); - - while (reader.Read()) - libraries.Add(Library.FromReader(reader)); - - return libraries; + return _database.Libraries; } public IEnumerable GetLibrariesPath() @@ -836,7 +677,7 @@ namespace Kyoo.Controllers Genre existingGenre = GetGenreBySlug(genre.Slug); if (existingGenre != null) - return existingGenre.ID; + return existingGenre.Id; string query = "INSERT INTO genres (slug, name) VALUES($slug, $name);"; using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) @@ -957,7 +798,7 @@ namespace Kyoo.Controllers using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) { - cmd.Parameters.AddWithValue("$libraryID", library.ID); + cmd.Parameters.AddWithValue("$libraryID", library.Id); cmd.Parameters.AddWithValue("$showID", showID); cmd.ExecuteNonQuery(); } @@ -1166,7 +1007,7 @@ namespace Kyoo.Controllers using (SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection)) { - cmd.Parameters.AddWithValue("$episodeID", episode.ID); + cmd.Parameters.AddWithValue("$episodeID", episode.Id); cmd.ExecuteNonQuery(); } diff --git a/Kyoo/DatabaseContext.cs b/Kyoo/DatabaseContext.cs new file mode 100644 index 00000000..beadd8a7 --- /dev/null +++ b/Kyoo/DatabaseContext.cs @@ -0,0 +1,60 @@ +using System; +using System.Linq; +using Kyoo.Models; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Kyoo +{ + public class DatabaseContext : DbContext + { + public DatabaseContext(DbContextOptions options) : base(options) { } + + public DbSet Libraries { get; set; } + public DbSet Collections { get; set; } + public DbSet Shows { get; set; } + public DbSet Seasons { get; set; } + public DbSet Episodes { get; set; } + public DbSet Tracks { get; set; } + public DbSet Genres { get; set; } + public DbSet Peoples { get; set; } + public DbSet PeopleLinks { get; set; } + public DbSet Studios { get; set; } + + private ValueConverter stringArrayConverter = new ValueConverter( + arr => string.Join("|", arr), + str => str.Split("|", StringSplitOptions.None)); + + private ValueComparer stringArrayComparer = new ValueComparer( + (l1, l2) => l1.SequenceEqual(l2), + arr => arr.Aggregate(0, (i, s) => s.GetHashCode())); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + base.OnModelCreating(modelBuilder); + + modelBuilder.Entity().Property(e => e.Paths).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer); + modelBuilder.Entity().Property(e => e.Providers).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer); + modelBuilder.Entity().Property(e => e.Aliases).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer); + + modelBuilder.Entity() + .HasOne(l => l.Show) + .WithMany(s => s.People) + .HasForeignKey(l => l.ShowID); + + modelBuilder.Entity() + .HasOne(l => l.People) + .WithMany(p => p.Roles) + .HasForeignKey(l => l.PeopleID); + + modelBuilder.Entity() + .Property(t => t.IsDefault) + .ValueGeneratedNever(); + + modelBuilder.Entity() + .Property(t => t.IsForced) + .ValueGeneratedNever(); + } + } +} \ No newline at end of file diff --git a/Kyoo/HtmlAPI/AuthentificationAPI.cs b/Kyoo/HtmlAPI/AuthentificationAPI.cs new file mode 100644 index 00000000..264bb3a8 --- /dev/null +++ b/Kyoo/HtmlAPI/AuthentificationAPI.cs @@ -0,0 +1,16 @@ +using System.Threading; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace Kyoo.Controllers +{ + public class AuthentificationAPI : Controller + { + // [Authorize, HttpGet("/connect/authorize")] + // public async Task Authorize(CancellationToken token) + // { + // //HttpContext.GetOpenIdConnectResponse() + // } + } +} \ No newline at end of file diff --git a/Kyoo/HtmlAPI/LibrariesAPI.cs b/Kyoo/HtmlAPI/LibrariesAPI.cs index 4c4faee0..47d7011e 100644 --- a/Kyoo/HtmlAPI/LibrariesAPI.cs +++ b/Kyoo/HtmlAPI/LibrariesAPI.cs @@ -30,7 +30,7 @@ namespace Kyoo.Controllers if (library == null) return NotFound(); - return libraryManager.GetShowsInLibrary(library.ID); + return libraryManager.GetShowsInLibrary(library.Id); } } } \ No newline at end of file diff --git a/Kyoo/HtmlAPI/SubtitleAPI.cs b/Kyoo/HtmlAPI/SubtitleAPI.cs index 178c354c..15e156b9 100644 --- a/Kyoo/HtmlAPI/SubtitleAPI.cs +++ b/Kyoo/HtmlAPI/SubtitleAPI.cs @@ -50,12 +50,12 @@ namespace Kyoo.Controllers public async Task ExtractSubtitle(string showSlug, long seasonNumber, long episodeNumber) { Episode episode = libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber); - libraryManager.ClearSubtitles(episode.ID); + libraryManager.ClearSubtitles(episode.Id); Track[] tracks = await transcoder.ExtractSubtitles(episode.Path); foreach (Track track in tracks) { - track.EpisodeID = episode.ID; + track.EpisodeID = episode.Id; libraryManager.RegisterTrack(track); } @@ -68,12 +68,12 @@ namespace Kyoo.Controllers List episodes = libraryManager.GetEpisodes(showSlug); foreach (Episode episode in episodes) { - libraryManager.ClearSubtitles(episode.ID); + libraryManager.ClearSubtitles(episode.Id); Track[] tracks = await transcoder.ExtractSubtitles(episode.Path); foreach (Track track in tracks) { - track.EpisodeID = episode.ID; + track.EpisodeID = episode.Id; libraryManager.RegisterTrack(track); } } diff --git a/Kyoo/Kyoo.csproj b/Kyoo/Kyoo.csproj index d5ffa11a..09c37be3 100644 --- a/Kyoo/Kyoo.csproj +++ b/Kyoo/Kyoo.csproj @@ -17,12 +17,22 @@ + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + - diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index e6144cb1..089b0b74 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -1,7 +1,9 @@ using Kyoo.Controllers; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.SpaServices.AngularCli; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -30,17 +32,23 @@ namespace Kyoo services.AddControllers().AddNewtonsoftJson(); services.AddHttpClient(); - - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + + services.AddDbContext(options => options.UseSqlite(Configuration.GetConnectionString("Database"))); + + // services.AddIdentity() + // .AddEntityFrameworkStores() + // services.AddIdentityServer(); + + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DatabaseContext database) { if (env.IsDevelopment()) { @@ -86,6 +94,10 @@ namespace Kyoo spa.UseAngularCliServer(npmScript: "start"); } }); + + database.Database.EnsureCreated();; + // Use the next line if the database is not SQLite (SQLite doesn't support complexe migrations). + // database.Database.Migrate();; } } } diff --git a/Kyoo/appsettings.json b/Kyoo/appsettings.json index 7cd9243d..c271f185 100644 --- a/Kyoo/appsettings.json +++ b/Kyoo/appsettings.json @@ -7,8 +7,11 @@ } }, "AllowedHosts": "*", + + "ConnectionStrings": { + "Database": "Data Source=kyoo.db" + }, - "databasePath": "/tmp/database.db", "transmuxTempPath": "/tmp/cached/kyoo/transmux", "transcodeTempPath": "/tmp/cached/kyoo/transcode", "peoplePath": "/tmp/people",