Finishing the rework of providers in the db

This commit is contained in:
Zoe Roux 2020-04-23 22:35:50 +02:00
parent 9580056df1
commit e54b86b16a
9 changed files with 348 additions and 31 deletions

View File

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

View File

@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Kyoo.Models
{
@ -8,11 +9,11 @@ namespace Kyoo.Models
public string Slug { get; set; }
public string Name { get; set; }
public string[] Paths { get; set; }
public ProviderID[] Providers { get; set; }
public virtual IEnumerable<ProviderLink> Providers { get; set; }
public Library() { }
public Library(string slug, string name, string[] paths, ProviderID[] providers)
public Library(string slug, string name, string[] paths, IEnumerable<ProviderLink> providers)
{
Slug = slug;
Name = name;

View File

@ -0,0 +1,17 @@
namespace Kyoo.Models
{
public class ProviderLink
{
public long ID { get; set; }
public long ProviderID { get; set; }
public virtual ProviderID Provider { get; set; }
public long? ShowID { get; set; }
public virtual Show Show { get; set; }
public long? LibraryID { get; set; }
public virtual Library Library { get; set; }
public string Name => Provider.Name;
public ProviderLink() { }
}
}

View File

@ -24,7 +24,7 @@ namespace Kyoo.Models
[JsonIgnore] public string ImgLogo { get; set; }
[JsonIgnore] public string ImgBackdrop { get; set; }
public IEnumerable<MetadataID> ExternalIDs { get; set; }
public virtual IEnumerable<MetadataID> ExternalIDs { get; set; }
public bool IsMovie { get; set; }

View File

@ -20,10 +20,10 @@ namespace Kyoo.Controllers
{
T ret = new T();
IEnumerable<IMetadataProvider> providers = library?.Providers != null
? _providers.Where(x => library.Providers.Contains(x.Provider))
.OrderBy(provider => Array.IndexOf(library.Providers, provider.Provider))
: _providers;
IEnumerable<IMetadataProvider> providers = library?.Providers
.Select(x => _providers.FirstOrDefault(y => y.Provider.Name == x.Name))
.Where(x => x != null)
?? _providers;
foreach (IMetadataProvider provider in providers)
{
@ -41,10 +41,10 @@ namespace Kyoo.Controllers
{
List<T> ret = new List<T>();
IEnumerable<IMetadataProvider> providers = library?.Providers != null
? _providers.Where(x => library.Providers.Contains(x.Provider))
.OrderBy(provider => Array.IndexOf(library.Providers, provider.Provider))
: _providers;
IEnumerable<IMetadataProvider> providers = library?.Providers
.Select(x => _providers.FirstOrDefault(y => y.Provider.Name == x.Name))
.Where(x => x != null)
?? _providers;
foreach (IMetadataProvider provider in providers)
{

View File

@ -85,6 +85,7 @@ namespace Kyoo
// This is used because EF doesn't support Many-To-Many relationships so for now we need to override the getter/setters to store this.
public DbSet<GenreLink> GenreLinks { get; set; }
public DbSet<ProviderLink> ProviderLinks { get; set; }
private ValueConverter<string[], string> stringArrayConverter = new ValueConverter<string[], string>(
@ -101,7 +102,6 @@ namespace Kyoo
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<Track>()

View File

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
[DbContext(typeof(DatabaseContext))]
[Migration("20200414223325_Initial")]
[Migration("20200423203356_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -166,9 +166,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<string>("Paths")
.HasColumnType("TEXT");
b.Property<string>("Providers")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
@ -206,6 +203,33 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("LibraryLinks");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DataID")
.HasColumnType("TEXT");
b.Property<string>("Link")
.HasColumnType("TEXT");
b.Property<long>("ProviderID")
.HasColumnType("INTEGER");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("ProviderID");
b.HasIndex("ShowID");
b.ToTable("MetadataIds");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Property<string>("Slug")
@ -255,6 +279,49 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
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")
@ -301,9 +368,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<long?>("EndYear")
.HasColumnType("INTEGER");
b.Property<string>("ExternalIDs")
.HasColumnType("TEXT");
b.Property<string>("ImgBackdrop")
.HasColumnType("TEXT");
@ -471,6 +535,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.HasOne("Kyoo.Models.ProviderID", "Provider")
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.PeopleLink", b =>
{
b.HasOne("Kyoo.Models.People", "People")
@ -484,6 +563,23 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.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")

View File

@ -46,8 +46,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.Annotation("Sqlite:Autoincrement", true),
Slug = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
Paths = table.Column<string>(nullable: true),
Providers = table.Column<string>(nullable: true)
Paths = table.Column<string>(nullable: true)
},
constraints: table =>
{
@ -68,6 +67,20 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
table.PrimaryKey("PK_Peoples", x => x.Slug);
});
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
@ -101,7 +114,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
ImgThumb = table.Column<string>(nullable: true),
ImgLogo = table.Column<string>(nullable: true),
ImgBackdrop = table.Column<string>(nullable: true),
ExternalIDs = table.Column<string>(nullable: true),
IsMovie = table.Column<bool>(nullable: false),
StudioID = table.Column<long>(nullable: true)
},
@ -199,6 +211,34 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "MetadataIds",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
ShowID = table.Column<long>(nullable: false),
ProviderID = table.Column<long>(nullable: false),
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_ProviderIds_ProviderID",
column: x => x.ProviderID,
principalTable: "ProviderIds",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MetadataIds_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PeopleLinks",
columns: table => new
@ -227,6 +267,39 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
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
@ -373,6 +446,16 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
table: "LibraryLinks",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ProviderID",
table: "MetadataIds",
column: "ProviderID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_ShowID",
table: "MetadataIds",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_PeopleLinks_PeopleID",
table: "PeopleLinks",
@ -389,6 +472,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
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",
@ -428,9 +526,15 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
migrationBuilder.DropTable(
name: "LibraryLinks");
migrationBuilder.DropTable(
name: "MetadataIds");
migrationBuilder.DropTable(
name: "PeopleLinks");
migrationBuilder.DropTable(
name: "ProviderLinks");
migrationBuilder.DropTable(
name: "Tracks");
@ -440,11 +544,14 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
migrationBuilder.DropTable(
name: "Collections");
migrationBuilder.DropTable(
name: "Peoples");
migrationBuilder.DropTable(
name: "Libraries");
migrationBuilder.DropTable(
name: "Peoples");
name: "ProviderIds");
migrationBuilder.DropTable(
name: "Episodes");

View File

@ -164,9 +164,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<string>("Paths")
.HasColumnType("TEXT");
b.Property<string>("Providers")
.HasColumnType("TEXT");
b.Property<string>("Slug")
.HasColumnType("TEXT");
@ -204,6 +201,33 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("LibraryLinks");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.Property<long>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("DataID")
.HasColumnType("TEXT");
b.Property<string>("Link")
.HasColumnType("TEXT");
b.Property<long>("ProviderID")
.HasColumnType("INTEGER");
b.Property<long>("ShowID")
.HasColumnType("INTEGER");
b.HasKey("ID");
b.HasIndex("ProviderID");
b.HasIndex("ShowID");
b.ToTable("MetadataIds");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Property<string>("Slug")
@ -253,6 +277,49 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
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")
@ -299,9 +366,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Property<long?>("EndYear")
.HasColumnType("INTEGER");
b.Property<string>("ExternalIDs")
.HasColumnType("TEXT");
b.Property<string>("ImgBackdrop")
.HasColumnType("TEXT");
@ -469,6 +533,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasForeignKey("ShowID");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
{
b.HasOne("Kyoo.Models.ProviderID", "Provider")
.WithMany()
.HasForeignKey("ProviderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.PeopleLink", b =>
{
b.HasOne("Kyoo.Models.People", "People")
@ -482,6 +561,23 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.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")