Cleaning up

This commit is contained in:
Zoe Roux 2020-04-27 00:18:41 +02:00
parent 3a0061d379
commit aa0c672d42
15 changed files with 61 additions and 1301 deletions

View File

@ -63,6 +63,7 @@ namespace Kyoo.Controllers
long RegisterEpisode(Episode episode);
long RegisterTrack(Track track);
void RegisterShowLinks(Library library, Collection collection, Show show);
IEnumerable<MetadataID> ValidateExternalIDs(IEnumerable<MetadataID> ids);
void RemoveShow(long showID);
void RemoveSeason(long seasonID);

View File

@ -11,7 +11,7 @@
<Company>SDG</Company>
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageVersion>1.0.19</PackageVersion>
<PackageVersion>1.0.20</PackageVersion>
</PropertyGroup>
<ItemGroup>

View File

@ -1,4 +1,4 @@
namespace Kyoo.Models
{
public enum ImageType { Poster, Background, Thumbnail, Logo }
public enum ImageType { Poster, Background, Logo }
}

View File

@ -7,8 +7,6 @@ namespace Kyoo.Models
[JsonIgnore] public long ID { get; set; }
[JsonIgnore] public long ProviderID { get; set; }
[JsonIgnore] public virtual ProviderID Provider { get; set; }
[JsonIgnore] public long? ShowID { get; set; }
[JsonIgnore] public virtual Show Show { get; set; }
[JsonIgnore] public long? LibraryID { get; set; }
[JsonIgnore] public virtual Library Library { get; set; }

View File

@ -19,10 +19,9 @@ namespace Kyoo.Models
public long? StartYear { get; set; }
public long? EndYear { get; set; }
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 Poster { get; set; }
public string Logo { get; set; }
public string Backdrop { get; set; }
public virtual IEnumerable<MetadataID> ExternalIDs { get; set; }
@ -77,10 +76,9 @@ namespace Kyoo.Models
Status? status,
long? startYear,
long? endYear,
string imgPrimary,
string imgThumb,
string imgLogo,
string imgBackdrop,
string poster,
string logo,
string backdrop,
IEnumerable<MetadataID> externalIDs)
{
Slug = slug;
@ -92,10 +90,9 @@ namespace Kyoo.Models
Status = status;
StartYear = startYear;
EndYear = endYear;
ImgPrimary = imgPrimary;
ImgThumb = imgThumb;
ImgLogo = imgLogo;
ImgBackdrop = imgBackdrop;
Poster = poster;
Logo = logo;
Backdrop = backdrop;
ExternalIDs = externalIDs;
IsCollection = false;
}
@ -122,10 +119,9 @@ namespace Kyoo.Models
Status ??= other.Status;
StartYear ??= other.StartYear;
EndYear ??= other.EndYear;
ImgPrimary ??= other.ImgPrimary;
ImgThumb ??= other.ImgThumb;
ImgLogo ??= other.ImgLogo;
ImgBackdrop ??= other.ImgBackdrop;
Poster ??= other.Poster;
Logo ??= other.Logo;
Backdrop ??= other.Backdrop;
Studio ??= other.Studio;
ExternalIDs = Utility.MergeLists(ExternalIDs, other.ExternalIDs,
(x, y) => x.Provider.Name == y.Provider.Name);

View File

@ -47,17 +47,16 @@ namespace Kyoo
switch(type)
{
case ImageType.Poster:
show.ImgPrimary = imgUrl;
break;
case ImageType.Thumbnail:
show.ImgThumb = imgUrl;
show.Poster = imgUrl;
break;
case ImageType.Logo:
show.ImgLogo = imgUrl;
show.Logo = imgUrl;
break;
case ImageType.Background:
show.ImgBackdrop = imgUrl;
show.Backdrop = imgUrl;
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}

View File

@ -429,6 +429,16 @@ namespace Kyoo.Controllers
return edited.ID;
}
public IEnumerable<MetadataID> ValidateExternalIDs(IEnumerable<MetadataID> ids)
{
return ids.Select(x =>
{
x.Provider = _database.Providers.FirstOrDefault(y => y.Name == x.Provider.Name) ?? x.Provider;
x.ProviderID = x.Provider.ID;
return x;
}).ToList();
}
public long RegisterMovie(Episode movie)
{
if (movie == null)
@ -453,6 +463,9 @@ namespace Kyoo.Controllers
{
if (episode == null)
return 0;
episode.ExternalIDs = new List<MetadataID>();
episode.Show.ExternalIDs = new List<MetadataID>();
episode.Season.ExternalIDs = new List<MetadataID>();
if (_database.Entry(episode).State == EntityState.Detached)
_database.Episodes.Add(episode);
_database.SaveChanges();

View File

@ -26,12 +26,12 @@ namespace Kyoo.Controllers
string localBackdrop = Path.Combine(show.Path, "backdrop.jpg");
if (show.ImgPrimary != null && !File.Exists(localThumb))
if (show.Poster != null && !File.Exists(localThumb))
{
try
{
using WebClient client = new WebClient();
await client.DownloadFileTaskAsync(new Uri(show.ImgPrimary), localThumb);
await client.DownloadFileTaskAsync(new Uri(show.Poster), localThumb);
}
catch (WebException exception)
{
@ -39,12 +39,12 @@ namespace Kyoo.Controllers
}
}
if (show.ImgLogo != null && !File.Exists(localLogo))
if (show.Logo != null && !File.Exists(localLogo))
{
try
{
using WebClient client = new WebClient();
await client.DownloadFileTaskAsync(new Uri(show.ImgLogo), localLogo);
await client.DownloadFileTaskAsync(new Uri(show.Logo), localLogo);
}
catch (WebException exception)
{
@ -52,12 +52,12 @@ namespace Kyoo.Controllers
}
}
if (show.ImgBackdrop != null && !File.Exists(localBackdrop))
if (show.Backdrop != null && !File.Exists(localBackdrop))
{
try
{
using WebClient client = new WebClient();
await client.DownloadFileTaskAsync(new Uri(show.ImgBackdrop), localBackdrop);
await client.DownloadFileTaskAsync(new Uri(show.Backdrop), localBackdrop);
}
catch (WebException exception)
{

View File

@ -76,7 +76,7 @@ namespace Kyoo
public DbSet<Genre> Genres { get; set; }
public DbSet<People> Peoples { get; set; }
public DbSet<Studio> Studios { get; set; }
public DbSet<ProviderID> ProviderIds { get; set; }
public DbSet<ProviderID> Providers { get; set; }
public DbSet<MetadataID> MetadataIds { get; set; }
public DbSet<LibraryLink> LibraryLinks { get; set; }

View File

@ -1,633 +0,0 @@
// <auto-generated />
using System;
using Kyoo;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
[DbContext(typeof(DatabaseContext))]
[Migration("20200423211516_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.1.3");
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Overview")
.HasColumnType("TEXT");
b.Property<string>("Poster")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Collections");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long?>("CollectionID")
.HasColumnType("INTEGER");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("CollectionID");
b.HasIndex("ShowID");
b.ToTable("CollectionLinks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long>("AbsoluteNumber")
.HasColumnType("INTEGER");
b.Property<long>("EpisodeNumber")
.HasColumnType("INTEGER");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("Overview")
.HasColumnType("TEXT");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<DateTime?>("ReleaseDate")
.HasColumnType("TEXT");
b.Property<long>("Runtime")
.HasColumnType("INTEGER");
b.Property<long?>("SeasonID")
.HasColumnType("INTEGER");
b.Property<long>("SeasonNumber")
.HasColumnType("INTEGER");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID");
b.ToTable("Episodes");
});
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Genres");
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.Property<long>("GenreID")
.HasColumnType("INTEGER");
b.HasKey("ShowID", "GenreID");
b.HasIndex("GenreID");
b.ToTable("GenreLinks");
});
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Paths")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Libraries");
});
modelBuilder.Entity("Kyoo.Models.LibraryLink", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long?>("CollectionID")
.HasColumnType("INTEGER");
b.Property<long>("LibraryID")
.HasColumnType("INTEGER");
b.Property<long?>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("CollectionID");
b.HasIndex("LibraryID");
b.HasIndex("ShowID");
b.ToTable("LibraryLinks");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DataID")
.HasColumnType("TEXT");
b.Property<long?>("EpisodeID")
.HasColumnType("INTEGER");
b.Property<string>("Link")
.HasColumnType("TEXT");
b.Property<long?>("PeopleID")
.HasColumnType("INTEGER");
b.Property<long>("ProviderID")
.HasColumnType("INTEGER");
b.Property<long?>("SeasonID")
.HasColumnType("INTEGER");
b.Property<long?>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("EpisodeID");
b.HasIndex("PeopleID");
b.HasIndex("ProviderID");
b.HasIndex("SeasonID");
b.HasIndex("ShowID");
b.ToTable("MetadataIds");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Peoples");
});
modelBuilder.Entity("Kyoo.Models.PeopleLink", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("PeopleID")
.HasColumnType("TEXT");
b.Property<long?>("PeopleID1")
.HasColumnType("INTEGER");
b.Property<string>("Role")
.HasColumnType("TEXT");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.Property<string>("Type")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("PeopleID1");
b.HasIndex("ShowID");
b.ToTable("PeopleLinks");
});
modelBuilder.Entity("Kyoo.Models.ProviderID", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Logo")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.HasKey("ID");
b.ToTable("ProviderIds");
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<long?>("LibraryID")
.HasColumnType("INTEGER");
b.Property<long>("ProviderID")
.HasColumnType("INTEGER");
b.Property<long?>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("LibraryID");
b.HasIndex("ProviderID");
b.HasIndex("ShowID");
b.ToTable("ProviderLinks");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("Overview")
.HasColumnType("TEXT");
b.Property<long>("SeasonNumber")
.HasColumnType("INTEGER");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<long?>("Year")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("ShowID");
b.ToTable("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Aliases")
.HasColumnType("TEXT");
b.Property<long?>("EndYear")
.HasColumnType("INTEGER");
b.Property<string>("ImgBackdrop")
.HasColumnType("TEXT");
b.Property<string>("ImgLogo")
.HasColumnType("TEXT");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("ImgThumb")
.HasColumnType("TEXT");
b.Property<bool>("IsMovie")
.HasColumnType("INTEGER");
b.Property<string>("Overview")
.HasColumnType("TEXT");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.Property<long?>("StartYear")
.HasColumnType("INTEGER");
b.Property<int?>("Status")
.HasColumnType("INTEGER");
b.Property<long?>("StudioID")
.HasColumnType("INTEGER");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<string>("TrailerUrl")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("StudioID");
b.ToTable("Shows");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.ToTable("Studios");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Codec")
.HasColumnType("TEXT");
b.Property<long>("EpisodeID")
.HasColumnType("INTEGER");
b.Property<bool>("IsDefault")
.HasColumnType("INTEGER");
b.Property<bool>("IsExternal")
.HasColumnType("INTEGER");
b.Property<bool>("IsForced")
.HasColumnType("INTEGER");
b.Property<string>("Language")
.HasColumnType("TEXT");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("Title")
.HasColumnType("TEXT");
b.Property<int>("Type")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("EpisodeID");
b.ToTable("Tracks");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
{
b.HasOne("Kyoo.Models.Collection", "Collection")
.WithMany()
.HasForeignKey("CollectionID");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("Episodes")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Episodes")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.HasOne("Kyoo.Models.Genre", "Genre")
.WithMany()
.HasForeignKey("GenreID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("GenreLinks")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.LibraryLink", b =>
{
b.HasOne("Kyoo.Models.Collection", "Collection")
.WithMany()
.HasForeignKey("CollectionID");
b.HasOne("Kyoo.Models.Library", "Library")
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("ExternalIDs")
.HasForeignKey("EpisodeID");
b.HasOne("Kyoo.Models.People", "People")
.WithMany("ExternalIDs")
.HasForeignKey("PeopleID");
b.HasOne("Kyoo.Models.ProviderID", "Provider")
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Season", "Season")
.WithMany("ExternalIDs")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.PeopleLink", b =>
{
b.HasOne("Kyoo.Models.People", "People")
.WithMany("Roles")
.HasForeignKey("PeopleID1");
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.HasOne("Kyoo.Models.Library", "Library")
.WithMany("Providers")
.HasForeignKey("LibraryID");
b.HasOne("Kyoo.Models.ProviderID", "Provider")
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Seasons")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.HasOne("Kyoo.Models.Studio", "Studio")
.WithMany()
.HasForeignKey("StudioID");
});
modelBuilder.Entity("Kyoo.Models.Track", b =>
{
b.HasOne("Kyoo.Models.Episode", "Episode")
.WithMany("Tracks")
.HasForeignKey("EpisodeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,605 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Collections",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
Poster = table.Column<string>(nullable: true),
Overview = table.Column<string>(nullable: true),
ImgPrimary = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Collections", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Genres",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Genres", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Libraries",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
Paths = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Libraries", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Peoples",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
ImgPrimary = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Peoples", x => x.ID);
});
migrationBuilder.CreateTable(
name: "ProviderIds",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(nullable: true),
Logo = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderIds", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Studios",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Studios", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Shows",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true),
Aliases = table.Column<string>(nullable: true),
Path = table.Column<string>(nullable: true),
Overview = table.Column<string>(nullable: true),
Status = table.Column<int>(nullable: true),
TrailerUrl = table.Column<string>(nullable: true),
StartYear = table.Column<long>(nullable: true),
EndYear = table.Column<long>(nullable: true),
ImgPrimary = table.Column<string>(nullable: true),
ImgThumb = table.Column<string>(nullable: true),
ImgLogo = table.Column<string>(nullable: true),
ImgBackdrop = table.Column<string>(nullable: true),
IsMovie = table.Column<bool>(nullable: false),
StudioID = table.Column<long>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Shows", x => x.ID);
table.ForeignKey(
name: "FK_Shows_Studios_StudioID",
column: x => x.StudioID,
principalTable: "Studios",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "CollectionLinks",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
CollectionID = table.Column<long>(nullable: true),
ShowID = table.Column<long>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CollectionLinks", x => x.ID);
table.ForeignKey(
name: "FK_CollectionLinks_Collections_CollectionID",
column: x => x.CollectionID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_CollectionLinks_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GenreLinks",
columns: table => new
{
ShowID = table.Column<long>(nullable: false),
GenreID = table.Column<long>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GenreLinks", x => new { x.ShowID, x.GenreID });
table.ForeignKey(
name: "FK_GenreLinks_Genres_GenreID",
column: x => x.GenreID,
principalTable: "Genres",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GenreLinks_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LibraryLinks",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
LibraryID = table.Column<long>(nullable: false),
ShowID = table.Column<long>(nullable: true),
CollectionID = table.Column<long>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_LibraryLinks", x => x.ID);
table.ForeignKey(
name: "FK_LibraryLinks_Collections_CollectionID",
column: x => x.CollectionID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_LibraryLinks_Libraries_LibraryID",
column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LibraryLinks_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PeopleLinks",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
PeopleID = table.Column<string>(nullable: true),
PeopleID1 = table.Column<long>(nullable: true),
ShowID = table.Column<long>(nullable: false),
Role = table.Column<string>(nullable: true),
Type = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PeopleLinks", x => x.ID);
table.ForeignKey(
name: "FK_PeopleLinks_Peoples_PeopleID1",
column: x => x.PeopleID1,
principalTable: "Peoples",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_PeopleLinks_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProviderLinks",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ProviderID = table.Column<long>(nullable: false),
ShowID = table.Column<long>(nullable: true),
LibraryID = table.Column<long>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderLinks", x => x.ID);
table.ForeignKey(
name: "FK_ProviderLinks_Libraries_LibraryID",
column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_ProviderLinks_ProviderIds_ProviderID",
column: x => x.ProviderID,
principalTable: "ProviderIds",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProviderLinks_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Seasons",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ShowID = table.Column<long>(nullable: false),
SeasonNumber = table.Column<long>(nullable: false),
Title = table.Column<string>(nullable: true),
Overview = table.Column<string>(nullable: true),
Year = table.Column<long>(nullable: true),
ImgPrimary = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Seasons", x => x.ID);
table.ForeignKey(
name: "FK_Seasons_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Episodes",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ShowID = table.Column<long>(nullable: false),
SeasonID = table.Column<long>(nullable: true),
SeasonNumber = table.Column<long>(nullable: false),
EpisodeNumber = table.Column<long>(nullable: false),
AbsoluteNumber = table.Column<long>(nullable: false),
Path = table.Column<string>(nullable: true),
Title = table.Column<string>(nullable: true),
Overview = table.Column<string>(nullable: true),
ReleaseDate = table.Column<DateTime>(nullable: true),
Runtime = table.Column<long>(nullable: false),
ImgPrimary = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Episodes", x => x.ID);
table.ForeignKey(
name: "FK_Episodes_Seasons_SeasonID",
column: x => x.SeasonID,
principalTable: "Seasons",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Episodes_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "MetadataIds",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ProviderID = table.Column<long>(nullable: false),
ShowID = table.Column<long>(nullable: true),
EpisodeID = table.Column<long>(nullable: true),
SeasonID = table.Column<long>(nullable: true),
PeopleID = table.Column<long>(nullable: true),
DataID = table.Column<string>(nullable: true),
Link = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MetadataIds", x => x.ID);
table.ForeignKey(
name: "FK_MetadataIds_Episodes_EpisodeID",
column: x => x.EpisodeID,
principalTable: "Episodes",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_MetadataIds_Peoples_PeopleID",
column: x => x.PeopleID,
principalTable: "Peoples",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_MetadataIds_ProviderIds_ProviderID",
column: x => x.ProviderID,
principalTable: "ProviderIds",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_Seasons_SeasonID",
column: x => x.SeasonID,
principalTable: "Seasons",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_MetadataIds_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "Tracks",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column<string>(nullable: true),
Language = table.Column<string>(nullable: true),
Codec = table.Column<string>(nullable: true),
Path = table.Column<string>(nullable: true),
Type = table.Column<int>(nullable: false),
EpisodeID = table.Column<long>(nullable: false),
IsDefault = table.Column<bool>(nullable: false),
IsForced = table.Column<bool>(nullable: false),
IsExternal = table.Column<bool>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tracks", x => x.ID);
table.ForeignKey(
name: "FK_Tracks_Episodes_EpisodeID",
column: x => x.EpisodeID,
principalTable: "Episodes",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_CollectionLinks_CollectionID",
table: "CollectionLinks",
column: "CollectionID");
migrationBuilder.CreateIndex(
name: "IX_CollectionLinks_ShowID",
table: "CollectionLinks",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_Collections_Slug",
table: "Collections",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Episodes_SeasonID",
table: "Episodes",
column: "SeasonID");
migrationBuilder.CreateIndex(
name: "IX_Episodes_ShowID",
table: "Episodes",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_GenreLinks_GenreID",
table: "GenreLinks",
column: "GenreID");
migrationBuilder.CreateIndex(
name: "IX_Genres_Slug",
table: "Genres",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Libraries_Slug",
table: "Libraries",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_CollectionID",
table: "LibraryLinks",
column: "CollectionID");
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_LibraryID",
table: "LibraryLinks",
column: "LibraryID");
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_ShowID",
table: "LibraryLinks",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_EpisodeID",
table: "MetadataIds",
column: "EpisodeID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_PeopleID",
table: "MetadataIds",
column: "PeopleID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ProviderID",
table: "MetadataIds",
column: "ProviderID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_SeasonID",
table: "MetadataIds",
column: "SeasonID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ShowID",
table: "MetadataIds",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_PeopleLinks_PeopleID1",
table: "PeopleLinks",
column: "PeopleID1");
migrationBuilder.CreateIndex(
name: "IX_PeopleLinks_ShowID",
table: "PeopleLinks",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_Peoples_Slug",
table: "Peoples",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_ProviderLinks_LibraryID",
table: "ProviderLinks",
column: "LibraryID");
migrationBuilder.CreateIndex(
name: "IX_ProviderLinks_ProviderID",
table: "ProviderLinks",
column: "ProviderID");
migrationBuilder.CreateIndex(
name: "IX_ProviderLinks_ShowID",
table: "ProviderLinks",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_Seasons_ShowID",
table: "Seasons",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_Shows_Slug",
table: "Shows",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_StudioID",
table: "Shows",
column: "StudioID");
migrationBuilder.CreateIndex(
name: "IX_Studios_Slug",
table: "Studios",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Tracks_EpisodeID",
table: "Tracks",
column: "EpisodeID");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CollectionLinks");
migrationBuilder.DropTable(
name: "GenreLinks");
migrationBuilder.DropTable(
name: "LibraryLinks");
migrationBuilder.DropTable(
name: "MetadataIds");
migrationBuilder.DropTable(
name: "PeopleLinks");
migrationBuilder.DropTable(
name: "ProviderLinks");
migrationBuilder.DropTable(
name: "Tracks");
migrationBuilder.DropTable(
name: "Genres");
migrationBuilder.DropTable(
name: "Collections");
migrationBuilder.DropTable(
name: "Peoples");
migrationBuilder.DropTable(
name: "Libraries");
migrationBuilder.DropTable(
name: "ProviderIds");
migrationBuilder.DropTable(
name: "Episodes");
migrationBuilder.DropTable(
name: "Seasons");
migrationBuilder.DropTable(
name: "Shows");
migrationBuilder.DropTable(
name: "Studios");
}
}
}

View File

@ -307,6 +307,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.HasKey("ID");
b.HasIndex("Name")
.IsUnique();
b.ToTable("ProviderIds");
});
@ -322,17 +325,12 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<long>("ProviderID")
.HasColumnType("INTEGER");
b.Property<long?>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("LibraryID");
b.HasIndex("ProviderID");
b.HasIndex("ShowID");
b.ToTable("ProviderLinks");
});
@ -376,30 +374,27 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<string>("Aliases")
.HasColumnType("TEXT");
b.Property<string>("Backdrop")
.HasColumnType("TEXT");
b.Property<long?>("EndYear")
.HasColumnType("INTEGER");
b.Property<string>("ImgBackdrop")
.HasColumnType("TEXT");
b.Property<string>("ImgLogo")
.HasColumnType("TEXT");
b.Property<string>("ImgPrimary")
.HasColumnType("TEXT");
b.Property<string>("ImgThumb")
.HasColumnType("TEXT");
b.Property<bool>("IsMovie")
.HasColumnType("INTEGER");
b.Property<string>("Logo")
.HasColumnType("TEXT");
b.Property<string>("Overview")
.HasColumnType("TEXT");
b.Property<string>("Path")
.HasColumnType("TEXT");
b.Property<string>("Poster")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
@ -595,10 +590,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>

View File

@ -145,6 +145,7 @@ namespace Kyoo.Controllers
Genre existing = _libraryManager.GetGenreBySlug(x.Slug);
return existing ?? x;
});
show.ExternalIDs = _libraryManager.ValidateExternalIDs(show.ExternalIDs);
await _thumbnailsManager.Validate(show);
return show;
}
@ -152,12 +153,13 @@ namespace Kyoo.Controllers
private async Task<Season> GetSeason(Show show, long seasonNumber, Library library)
{
if (seasonNumber == -1)
return null;
return default;
Season season = _libraryManager.GetSeason(show.Slug, seasonNumber);
if (season == null)
return await _metadataProvider.GetSeason(show, seasonNumber, library);
season = await _metadataProvider.GetSeason(show, seasonNumber, library);
season.Show = show;
return await Task.FromResult(season);
season.ExternalIDs = _libraryManager.ValidateExternalIDs(season.ExternalIDs);
return season;
}
private async Task<Episode> GetEpisode(Show show, Season season, long episodeNumber, long absoluteNumber, string episodePath, Library library)
@ -172,6 +174,7 @@ namespace Kyoo.Controllers
return null;
}
episode.ExternalIDs = _libraryManager.ValidateExternalIDs(episode.ExternalIDs);
await _thumbnailsManager.Validate(episode);
await GetTracks(episode);
return episode;
@ -179,10 +182,7 @@ namespace Kyoo.Controllers
private async Task<Episode> GetMovie(Show show, string episodePath)
{
Episode episode = new Episode();
episode.Title = show.Title;
episode.Path = episodePath;
episode.Show = show;
Episode episode = new Episode {Title = show.Title, Path = episodePath, Show = show};
episode.Tracks = await GetTracks(episode);
return episode;
}

View File

@ -23,7 +23,7 @@ namespace Kyoo.Tasks
DatabaseContext database = serviceScope.ServiceProvider.GetService<DatabaseContext>();
IPluginManager pluginManager = serviceScope.ServiceProvider.GetService<IPluginManager>();
foreach (IMetadataProvider provider in pluginManager.GetPlugins<IMetadataProvider>())
database.ProviderIds.AddIfNotExist(provider.Provider, x => x.Name == provider.Provider.Name);
database.Providers.AddIfNotExist(provider.Provider, x => x.Name == provider.Provider.Name);
database.SaveChanges();
return Task.CompletedTask;
}

@ -1 +1 @@
Subproject commit 6748d004b783a9fb4afdc51fec4787de0ddc1021
Subproject commit 4ec71d48a9d48a054ea68594d3b8b4e2a09b33de