mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Reworking the models to use EF
This commit is contained in:
parent
37abbdd5e0
commit
38d6b4fbde
@ -6,21 +6,20 @@ using System.Linq;
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class Collection : IMergable<Collection>
|
||||
|
||||
{
|
||||
[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<Show> 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)
|
||||
|
@ -5,22 +5,24 @@ namespace Kyoo.Models
|
||||
{
|
||||
public class Episode : IMergable<Episode>
|
||||
{
|
||||
[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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,17 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class People : IMergable<People>
|
||||
{
|
||||
[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<PeopleLink> Roles { get; set; }
|
||||
|
||||
public People() {}
|
||||
|
||||
|
13
Kyoo.Common/Models/PeopleLink.cs
Normal file
13
Kyoo.Common/Models/PeopleLink.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
@ -1,19 +1,24 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
public class Season : IMergable<Season>
|
||||
{
|
||||
[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<Episode> Episodes { get; set; }
|
||||
|
||||
public Season() { }
|
||||
|
||||
|
@ -8,34 +8,34 @@ namespace Kyoo.Models
|
||||
{
|
||||
public class Show : IMergable<Show>
|
||||
{
|
||||
[JsonIgnore] public long ID = -1;
|
||||
[JsonIgnore] public long ID { get; set; } = -1;
|
||||
|
||||
public string Slug;
|
||||
public string Title;
|
||||
public IEnumerable<string> Aliases;
|
||||
[JsonIgnore] public string Path;
|
||||
public string Overview;
|
||||
public IEnumerable<Genre> 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<People> Directors;
|
||||
public IEnumerable<People> People;
|
||||
public IEnumerable<Season> Seasons;
|
||||
public string ExternalIDs { get; set; }
|
||||
|
||||
public bool IsCollection;
|
||||
|
||||
public IEnumerable<Genre> Genres;
|
||||
public virtual Studio Studio { get; set; }
|
||||
public virtual IEnumerable<PeopleLink> People { get; set; }
|
||||
public virtual IEnumerable<Season> Seasons { get; set; }
|
||||
public virtual IEnumerable<Episode> 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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -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";
|
||||
|
@ -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<string>("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<Library> GetLibraries()
|
||||
{
|
||||
const string query = "SELECT * FROM libraries;";
|
||||
|
||||
using SQLiteCommand cmd = new SQLiteCommand(query, sqlConnection);
|
||||
SQLiteDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
List<Library> libraries = new List<Library>();
|
||||
|
||||
while (reader.Read())
|
||||
libraries.Add(Library.FromReader(reader));
|
||||
|
||||
return libraries;
|
||||
return _database.Libraries;
|
||||
}
|
||||
|
||||
public IEnumerable<string> 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();
|
||||
}
|
||||
|
||||
|
60
Kyoo/DatabaseContext.cs
Normal file
60
Kyoo/DatabaseContext.cs
Normal file
@ -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<Library> Libraries { get; set; }
|
||||
public DbSet<Collection> Collections { get; set; }
|
||||
public DbSet<Show> Shows { get; set; }
|
||||
public DbSet<Season> Seasons { get; set; }
|
||||
public DbSet<Episode> Episodes { get; set; }
|
||||
public DbSet<Track> Tracks { get; set; }
|
||||
public DbSet<Genre> Genres { get; set; }
|
||||
public DbSet<People> Peoples { get; set; }
|
||||
public DbSet<PeopleLink> PeopleLinks { get; set; }
|
||||
public DbSet<Studio> Studios { get; set; }
|
||||
|
||||
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
|
||||
arr => string.Join("|", arr),
|
||||
str => str.Split("|", StringSplitOptions.None));
|
||||
|
||||
private ValueComparer<string[]> stringArrayComparer = new ValueComparer<string[]>(
|
||||
(l1, l2) => l1.SequenceEqual(l2),
|
||||
arr => arr.Aggregate(0, (i, s) => s.GetHashCode()));
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Library>().Property(e => e.Paths).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
|
||||
modelBuilder.Entity<Library>().Property(e => e.Providers).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
|
||||
modelBuilder.Entity<Show>().Property(e => e.Aliases).HasConversion(stringArrayConverter).Metadata.SetValueComparer(stringArrayComparer);
|
||||
|
||||
modelBuilder.Entity<PeopleLink>()
|
||||
.HasOne(l => l.Show)
|
||||
.WithMany(s => s.People)
|
||||
.HasForeignKey(l => l.ShowID);
|
||||
|
||||
modelBuilder.Entity<PeopleLink>()
|
||||
.HasOne(l => l.People)
|
||||
.WithMany(p => p.Roles)
|
||||
.HasForeignKey(l => l.PeopleID);
|
||||
|
||||
modelBuilder.Entity<Track>()
|
||||
.Property(t => t.IsDefault)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
modelBuilder.Entity<Track>()
|
||||
.Property(t => t.IsForced)
|
||||
.ValueGeneratedNever();
|
||||
}
|
||||
}
|
||||
}
|
16
Kyoo/HtmlAPI/AuthentificationAPI.cs
Normal file
16
Kyoo/HtmlAPI/AuthentificationAPI.cs
Normal file
@ -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<IActionResult> Authorize(CancellationToken token)
|
||||
// {
|
||||
// //HttpContext.GetOpenIdConnectResponse()
|
||||
// }
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ namespace Kyoo.Controllers
|
||||
if (library == null)
|
||||
return NotFound();
|
||||
|
||||
return libraryManager.GetShowsInLibrary(library.ID);
|
||||
return libraryManager.GetShowsInLibrary(library.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -50,12 +50,12 @@ namespace Kyoo.Controllers
|
||||
public async Task<string> 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<Episode> 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);
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,22 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="IdentityServer4" Version="3.0.2" />
|
||||
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="3.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.112" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -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<ILibraryManager, LibraryManager>();
|
||||
services.AddSingleton<ITranscoder, Transcoder>();
|
||||
services.AddSingleton<IThumbnailsManager, ThumbnailsManager>();
|
||||
services.AddSingleton<IProviderManager, ProviderManager>();
|
||||
services.AddSingleton<ICrawler, Crawler>();
|
||||
services.AddSingleton<IPluginManager, PluginManager>();
|
||||
|
||||
services.AddDbContext<DatabaseContext>(options => options.UseSqlite(Configuration.GetConnectionString("Database")));
|
||||
|
||||
// services.AddIdentity<ApplicationUser, IdentityRole>()
|
||||
// .AddEntityFrameworkStores()
|
||||
// services.AddIdentityServer();
|
||||
|
||||
services.AddScoped<ILibraryManager, LibraryManager>();
|
||||
services.AddScoped<ITranscoder, Transcoder>();
|
||||
services.AddScoped<IThumbnailsManager, ThumbnailsManager>();
|
||||
services.AddScoped<IProviderManager, ProviderManager>();
|
||||
services.AddScoped<ICrawler, Crawler>();
|
||||
services.AddScoped<IPluginManager, PluginManager>();
|
||||
}
|
||||
|
||||
// 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();;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user