Removing links & DE items. DotnetEf now support Many to Many out of the box

This commit is contained in:
Zoe Roux 2021-03-01 00:20:38 +01:00
parent 072dd7d9b8
commit b2b53f2691
8 changed files with 606 additions and 574 deletions

View File

@ -71,7 +71,7 @@ namespace Kyoo.Controllers
private IQueryable<LibraryItem> ItemsQuery
=> _database.Shows
.Where(x => !_database.CollectionLinks.Any(y => y.ChildID == x.ID))
// .Where(x => !_database.CollectionLinks.Any(y => y.ChildID == x.ID))
.Select(LibraryItem.FromShow)
.Concat(_database.Collections
.Select(LibraryItem.FromCollection));
@ -114,17 +114,18 @@ namespace Kyoo.Controllers
public override Task Delete(LibraryItem obj) => throw new InvalidOperationException();
private IQueryable<LibraryItem> LibraryRelatedQuery(Expression<Func<LibraryLink, bool>> selector)
=> _database.LibraryLinks
.Where(selector)
.Select(x => x.Show)
.Where(x => x != null)
.Where(x => !_database.CollectionLinks.Any(y => y.ChildID == x.ID))
.Select(LibraryItem.FromShow)
.Concat(_database.LibraryLinks
.Where(selector)
.Select(x => x.Collection)
.Where(x => x != null)
.Select(LibraryItem.FromCollection));
=> throw new NotImplementedException();
// => _database.LibraryLinks
// .Where(selector)
// .Select(x => x.Show)
// .Where(x => x != null)
// .Where(x => !_database.CollectionLinks.Any(y => y.ChildID == x.ID))
// .Select(LibraryItem.FromShow)
// .Concat(_database.LibraryLinks
// .Where(selector)
// .Select(x => x.Collection)
// .Where(x => x != null)
// .Select(LibraryItem.FromCollection));
public async Task<ICollection<LibraryItem>> GetFromLibrary(int id,
Expression<Func<LibraryItem, bool>> where = null,

View File

@ -134,18 +134,18 @@ namespace Kyoo.Controllers
{
if (collectionID != null)
{
await _database.CollectionLinks.AddAsync(new CollectionLink {ParentID = collectionID.Value, ChildID = showID});
// await _database.CollectionLinks.AddAsync(new CollectionLink {ParentID = collectionID.Value, ChildID = showID});
await _database.SaveIfNoDuplicates();
}
if (libraryID != null)
{
await _database.LibraryLinks.AddAsync(new LibraryLink {LibraryID = libraryID.Value, ShowID = showID});
// await _database.LibraryLinks.AddAsync(new LibraryLink {LibraryID = libraryID.Value, ShowID = showID});
await _database.SaveIfNoDuplicates();
}
if (libraryID != null && collectionID != null)
{
await _database.LibraryLinks.AddAsync(new LibraryLink {LibraryID = libraryID.Value, CollectionID = collectionID.Value});
// await _database.LibraryLinks.AddAsync(new LibraryLink {LibraryID = libraryID.Value, CollectionID = collectionID.Value});
await _database.SaveIfNoDuplicates();
}
}

View File

@ -16,13 +16,13 @@ namespace Kyoo
{
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
public DbSet<LibraryDE> Libraries { get; set; }
public DbSet<CollectionDE> Collections { get; set; }
public DbSet<ShowDE> Shows { get; set; }
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<GenreDE> Genres { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<People> People { get; set; }
public DbSet<Studio> Studios { get; set; }
public DbSet<ProviderID> Providers { get; set; }
@ -30,11 +30,6 @@ namespace Kyoo
public DbSet<PeopleRole> PeopleRoles { get; set; }
public DbSet<LibraryLink> LibraryLinks { get; set; }
public DbSet<CollectionLink> CollectionLinks { get; set; }
public DbSet<GenreLink> GenreLinks { get; set; }
public DbSet<ProviderLink> ProviderLinks { get; set; }
public DatabaseContext()
{
@ -56,11 +51,11 @@ namespace Kyoo
modelBuilder.Ignore<Show>();
modelBuilder.Ignore<Genre>();
modelBuilder.Entity<LibraryDE>()
modelBuilder.Entity<Library>()
.Property(x => x.Paths)
.HasColumnType("text[]");
modelBuilder.Entity<ShowDE>()
modelBuilder.Entity<Show>()
.Property(x => x.Aliases)
.HasColumnType("text[]");
@ -72,88 +67,8 @@ namespace Kyoo
.Property(t => t.IsForced)
.ValueGeneratedNever();
modelBuilder.Entity<GenreLink>()
.HasKey(x => new {ShowID = x.ParentID, GenreID = x.ChildID});
modelBuilder.Entity<CollectionLink>()
.HasKey(x => new {CollectionID = x.ParentID, ShowID = x.ChildID});
modelBuilder.Entity<ProviderLink>()
.HasKey(x => new {LibraryID = x.ParentID, ProviderID = x.ChildID});
modelBuilder.Entity<LibraryDE>()
.Ignore(x => x.Shows)
.Ignore(x => x.Collections)
.Ignore(x => x.Providers);
modelBuilder.Entity<CollectionDE>()
.Ignore(x => x.Shows)
.Ignore(x => x.Libraries);
modelBuilder.Entity<ShowDE>()
.Ignore(x => x.Genres)
.Ignore(x => x.Libraries)
.Ignore(x => x.Collections);
modelBuilder.Entity<PeopleRole>()
.Ignore(x => x.Slug);
modelBuilder.Entity<GenreDE>()
.Ignore(x => x.Shows);
modelBuilder.Entity<LibraryLink>()
.HasOne(x => x.Library as LibraryDE)
.WithMany(x => x.Links)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<LibraryLink>()
.HasOne(x => x.Show as ShowDE)
.WithMany(x => x.LibraryLinks)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<LibraryLink>()
.HasOne(x => x.Collection as CollectionDE)
.WithMany(x => x.LibraryLinks)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<CollectionLink>()
.HasOne(x => x.Parent as CollectionDE)
.WithMany(x => x.Links)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<CollectionLink>()
.HasOne(x => x.Child as ShowDE)
.WithMany(x => x.CollectionLinks)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GenreLink>()
.HasOne(x => x.Child as GenreDE)
.WithMany(x => x.Links)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<GenreLink>()
.HasOne(x => x.Parent as ShowDE)
.WithMany(x => x.GenreLinks)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<ProviderLink>()
.HasOne(x => x.Parent as LibraryDE)
.WithMany(x => x.ProviderLinks)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Season>()
.HasOne(x => x.Show as ShowDE)
.WithMany(x => x.Seasons);
modelBuilder.Entity<Episode>()
.HasOne(x => x.Show as ShowDE)
.WithMany(x => x.Episodes);
modelBuilder.Entity<PeopleRole>()
.HasOne(x => x.Show as ShowDE)
.WithMany(x => x.People);
modelBuilder.Entity<MetadataID>()
.HasOne(x => x.Show as ShowDE)
.HasOne(x => x.Show)
.WithMany(x => x.ExternalIDs)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<MetadataID>()
@ -169,27 +84,27 @@ namespace Kyoo
.WithMany(x => x.ExternalIDs)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<CollectionDE>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<GenreDE>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<LibraryDE>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Collection>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Genre>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Library>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<People>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<ProviderID>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<ShowDE>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Show>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<Studio>().Property(x => x.Slug).IsRequired();
modelBuilder.Entity<CollectionDE>()
modelBuilder.Entity<Collection>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<GenreDE>()
modelBuilder.Entity<Genre>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<LibraryDE>()
modelBuilder.Entity<Library>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<People>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<ShowDE>()
modelBuilder.Entity<Show>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Studio>()

View File

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Models.DatabaseMigrations.Internal
{
[DbContext(typeof(DatabaseContext))]
[Migration("20210228224046_Initial")]
[Migration("20210228232014_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -24,7 +24,52 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Kyoo.Models.CollectionDE", b =>
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer");
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.HasKey("CollectionsID", "LibrariesID");
b.HasIndex("LibrariesID");
b.ToTable("CollectionLibrary");
});
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("CollectionsID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("CollectionShow");
});
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("GenresID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("GenreShow");
});
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -52,21 +97,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Collections");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("CollectionLinks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Property<int>("ID")
@ -117,7 +147,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Episodes");
});
modelBuilder.Entity("Kyoo.Models.GenreDE", b =>
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -139,22 +169,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Genres");
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("GenreLinks");
});
modelBuilder.Entity("Kyoo.Models.LibraryDE", b =>
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -207,7 +222,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.HasIndex("LibraryID", "ShowID")
.IsUnique();
b.ToTable("LibraryLinks");
b.ToTable("LibraryLink");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
@ -331,21 +346,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Providers");
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("ProviderLinks");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Property<int>("ID")
@ -379,7 +379,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Seasons");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -502,23 +502,79 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Tracks");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
modelBuilder.Entity("LibraryProviderID", b =>
{
b.HasOne("Kyoo.Models.ShowDE", "Child")
.WithMany("CollectionLinks")
.HasForeignKey("ChildID")
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.Property<int>("ProvidersID")
.HasColumnType("integer");
b.HasKey("LibrariesID", "ProvidersID");
b.HasIndex("ProvidersID");
b.ToTable("LibraryProviderID");
});
modelBuilder.Entity("LibraryShow", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("LibrariesID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LibraryShow");
});
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.CollectionDE", "Parent")
.WithMany("Links")
.HasForeignKey("ParentID")
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
b.Navigation("Parent");
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
@ -527,7 +583,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.WithMany("Episodes")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Episodes")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -538,42 +594,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.HasOne("Kyoo.Models.GenreDE", "Child")
.WithMany("Links")
.HasForeignKey("ChildID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Parent")
.WithMany("GenreLinks")
.HasForeignKey("ParentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.Navigation("Parent");
});
modelBuilder.Entity("Kyoo.Models.LibraryLink", b =>
{
b.HasOne("Kyoo.Models.CollectionDE", "Collection")
.WithMany("LibraryLinks")
.HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Collection", "Collection")
.WithMany()
.HasForeignKey("CollectionID");
b.HasOne("Kyoo.Models.LibraryDE", "Library")
.WithMany("Links")
b.HasOne("Kyoo.Models.Library", "Library")
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Show")
.WithMany("LibraryLinks")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID");
b.Navigation("Collection");
@ -605,7 +640,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasForeignKey("SeasonID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
@ -629,7 +664,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -640,28 +675,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.HasOne("Kyoo.Models.ProviderID", "Child")
.WithMany()
.HasForeignKey("ChildID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.LibraryDE", "Parent")
.WithMany("ProviderLinks")
.HasForeignKey("ParentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.Navigation("Parent");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Seasons")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -670,10 +686,10 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.HasOne("Kyoo.Models.Studio", "Studio")
.WithMany()
.WithMany("Shows")
.HasForeignKey("StudioID");
b.Navigation("Studio");
@ -690,11 +706,34 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Episode");
});
modelBuilder.Entity("Kyoo.Models.CollectionDE", b =>
modelBuilder.Entity("LibraryProviderID", b =>
{
b.Navigation("LibraryLinks");
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Links");
b.HasOne("Kyoo.Models.ProviderID", null)
.WithMany()
.HasForeignKey("ProvidersID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
@ -704,18 +743,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Tracks");
});
modelBuilder.Entity("Kyoo.Models.GenreDE", b =>
{
b.Navigation("Links");
});
modelBuilder.Entity("Kyoo.Models.LibraryDE", b =>
{
b.Navigation("Links");
b.Navigation("ProviderLinks");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Navigation("ExternalIDs");
@ -730,22 +757,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("ExternalIDs");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
b.Navigation("GenreLinks");
b.Navigation("LibraryLinks");
b.Navigation("People");
b.Navigation("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Navigation("Shows");
});
#pragma warning restore 612, 618
}
}

View File

@ -103,24 +103,48 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
});
migrationBuilder.CreateTable(
name: "ProviderLinks",
name: "CollectionLibrary",
columns: table => new
{
ParentID = table.Column<int>(type: "integer", nullable: false),
ChildID = table.Column<int>(type: "integer", nullable: false)
CollectionsID = table.Column<int>(type: "integer", nullable: false),
LibrariesID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProviderLinks", x => new { x.ParentID, x.ChildID });
table.PrimaryKey("PK_CollectionLibrary", x => new { x.CollectionsID, x.LibrariesID });
table.ForeignKey(
name: "FK_ProviderLinks_Libraries_ParentID",
column: x => x.ParentID,
name: "FK_CollectionLibrary_Collections_CollectionsID",
column: x => x.CollectionsID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CollectionLibrary_Libraries_LibrariesID",
column: x => x.LibrariesID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LibraryProviderID",
columns: table => new
{
LibrariesID = table.Column<int>(type: "integer", nullable: false),
ProvidersID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LibraryProviderID", x => new { x.LibrariesID, x.ProvidersID });
table.ForeignKey(
name: "FK_LibraryProviderID_Libraries_LibrariesID",
column: x => x.LibrariesID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProviderLinks_Providers_ChildID",
column: x => x.ChildID,
name: "FK_LibraryProviderID_Providers_ProvidersID",
column: x => x.ProvidersID,
principalTable: "Providers",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
@ -159,55 +183,55 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
});
migrationBuilder.CreateTable(
name: "CollectionLinks",
name: "CollectionShow",
columns: table => new
{
ParentID = table.Column<int>(type: "integer", nullable: false),
ChildID = table.Column<int>(type: "integer", nullable: false)
CollectionsID = table.Column<int>(type: "integer", nullable: false),
ShowsID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CollectionLinks", x => new { x.ParentID, x.ChildID });
table.PrimaryKey("PK_CollectionShow", x => new { x.CollectionsID, x.ShowsID });
table.ForeignKey(
name: "FK_CollectionLinks_Collections_ParentID",
column: x => x.ParentID,
name: "FK_CollectionShow_Collections_CollectionsID",
column: x => x.CollectionsID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_CollectionLinks_Shows_ChildID",
column: x => x.ChildID,
name: "FK_CollectionShow_Shows_ShowsID",
column: x => x.ShowsID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "GenreLinks",
name: "GenreShow",
columns: table => new
{
ParentID = table.Column<int>(type: "integer", nullable: false),
ChildID = table.Column<int>(type: "integer", nullable: false)
GenresID = table.Column<int>(type: "integer", nullable: false),
ShowsID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GenreLinks", x => new { x.ParentID, x.ChildID });
table.PrimaryKey("PK_GenreShow", x => new { x.GenresID, x.ShowsID });
table.ForeignKey(
name: "FK_GenreLinks_Genres_ChildID",
column: x => x.ChildID,
name: "FK_GenreShow_Genres_GenresID",
column: x => x.GenresID,
principalTable: "Genres",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_GenreLinks_Shows_ParentID",
column: x => x.ParentID,
name: "FK_GenreShow_Shows_ShowsID",
column: x => x.ShowsID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LibraryLinks",
name: "LibraryLink",
columns: table => new
{
ID = table.Column<int>(type: "integer", nullable: false)
@ -218,24 +242,48 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
},
constraints: table =>
{
table.PrimaryKey("PK_LibraryLinks", x => x.ID);
table.PrimaryKey("PK_LibraryLink", x => x.ID);
table.ForeignKey(
name: "FK_LibraryLinks_Collections_CollectionID",
name: "FK_LibraryLink_Collections_CollectionID",
column: x => x.CollectionID,
principalTable: "Collections",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_LibraryLinks_Libraries_LibraryID",
name: "FK_LibraryLink_Libraries_LibraryID",
column: x => x.LibraryID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LibraryLinks_Shows_ShowID",
name: "FK_LibraryLink_Shows_ShowID",
column: x => x.ShowID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "LibraryShow",
columns: table => new
{
LibrariesID = table.Column<int>(type: "integer", nullable: false),
ShowsID = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LibraryShow", x => new { x.LibrariesID, x.ShowsID });
table.ForeignKey(
name: "FK_LibraryShow_Libraries_LibrariesID",
column: x => x.LibrariesID,
principalTable: "Libraries",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_LibraryShow_Shows_ShowsID",
column: x => x.ShowsID,
principalTable: "Shows",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
@ -403,9 +451,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
});
migrationBuilder.CreateIndex(
name: "IX_CollectionLinks_ChildID",
table: "CollectionLinks",
column: "ChildID");
name: "IX_CollectionLibrary_LibrariesID",
table: "CollectionLibrary",
column: "LibrariesID");
migrationBuilder.CreateIndex(
name: "IX_Collections_Slug",
@ -413,6 +461,11 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CollectionShow_ShowsID",
table: "CollectionShow",
column: "ShowsID");
migrationBuilder.CreateIndex(
name: "IX_Episodes_SeasonID",
table: "Episodes",
@ -424,17 +477,17 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_GenreLinks_ChildID",
table: "GenreLinks",
column: "ChildID");
migrationBuilder.CreateIndex(
name: "IX_Genres_Slug",
table: "Genres",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_GenreShow_ShowsID",
table: "GenreShow",
column: "ShowsID");
migrationBuilder.CreateIndex(
name: "IX_Libraries_Slug",
table: "Libraries",
@ -442,27 +495,37 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
unique: true);
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_CollectionID",
table: "LibraryLinks",
name: "IX_LibraryLink_CollectionID",
table: "LibraryLink",
column: "CollectionID");
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_LibraryID_CollectionID",
table: "LibraryLinks",
name: "IX_LibraryLink_LibraryID_CollectionID",
table: "LibraryLink",
columns: new[] { "LibraryID", "CollectionID" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_LibraryID_ShowID",
table: "LibraryLinks",
name: "IX_LibraryLink_LibraryID_ShowID",
table: "LibraryLink",
columns: new[] { "LibraryID", "ShowID" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_LibraryLinks_ShowID",
table: "LibraryLinks",
name: "IX_LibraryLink_ShowID",
table: "LibraryLink",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_LibraryProviderID_ProvidersID",
table: "LibraryProviderID",
column: "ProvidersID");
migrationBuilder.CreateIndex(
name: "IX_LibraryShow_ShowsID",
table: "LibraryShow",
column: "ShowsID");
migrationBuilder.CreateIndex(
name: "IX_MetadataIds_EpisodeID",
table: "MetadataIds",
@ -504,11 +567,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
table: "PeopleRoles",
column: "ShowID");
migrationBuilder.CreateIndex(
name: "IX_ProviderLinks_ChildID",
table: "ProviderLinks",
column: "ChildID");
migrationBuilder.CreateIndex(
name: "IX_Providers_Slug",
table: "Providers",
@ -547,13 +605,22 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CollectionLinks");
name: "CollectionLibrary");
migrationBuilder.DropTable(
name: "GenreLinks");
name: "CollectionShow");
migrationBuilder.DropTable(
name: "LibraryLinks");
name: "GenreShow");
migrationBuilder.DropTable(
name: "LibraryLink");
migrationBuilder.DropTable(
name: "LibraryProviderID");
migrationBuilder.DropTable(
name: "LibraryShow");
migrationBuilder.DropTable(
name: "MetadataIds");
@ -561,9 +628,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
migrationBuilder.DropTable(
name: "PeopleRoles");
migrationBuilder.DropTable(
name: "ProviderLinks");
migrationBuilder.DropTable(
name: "Tracks");
@ -573,15 +637,15 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
migrationBuilder.DropTable(
name: "Collections");
migrationBuilder.DropTable(
name: "People");
migrationBuilder.DropTable(
name: "Libraries");
migrationBuilder.DropTable(
name: "Providers");
migrationBuilder.DropTable(
name: "People");
migrationBuilder.DropTable(
name: "Episodes");

View File

@ -22,7 +22,52 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Kyoo.Models.CollectionDE", b =>
modelBuilder.Entity("CollectionLibrary", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer");
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.HasKey("CollectionsID", "LibrariesID");
b.HasIndex("LibrariesID");
b.ToTable("CollectionLibrary");
});
modelBuilder.Entity("CollectionShow", b =>
{
b.Property<int>("CollectionsID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("CollectionsID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("CollectionShow");
});
modelBuilder.Entity("GenreShow", b =>
{
b.Property<int>("GenresID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("GenresID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("GenreShow");
});
modelBuilder.Entity("Kyoo.Models.Collection", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -50,21 +95,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Collections");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("CollectionLinks");
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
{
b.Property<int>("ID")
@ -115,7 +145,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Episodes");
});
modelBuilder.Entity("Kyoo.Models.GenreDE", b =>
modelBuilder.Entity("Kyoo.Models.Genre", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -137,22 +167,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Genres");
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("GenreLinks");
});
modelBuilder.Entity("Kyoo.Models.LibraryDE", b =>
modelBuilder.Entity("Kyoo.Models.Library", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -205,7 +220,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.HasIndex("LibraryID", "ShowID")
.IsUnique();
b.ToTable("LibraryLinks");
b.ToTable("LibraryLink");
});
modelBuilder.Entity("Kyoo.Models.MetadataID", b =>
@ -329,21 +344,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Providers");
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.Property<int>("ParentID")
.HasColumnType("integer");
b.Property<int>("ChildID")
.HasColumnType("integer");
b.HasKey("ParentID", "ChildID");
b.HasIndex("ChildID");
b.ToTable("ProviderLinks");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.Property<int>("ID")
@ -377,7 +377,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Seasons");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
@ -500,23 +500,79 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.ToTable("Tracks");
});
modelBuilder.Entity("Kyoo.Models.CollectionLink", b =>
modelBuilder.Entity("LibraryProviderID", b =>
{
b.HasOne("Kyoo.Models.ShowDE", "Child")
.WithMany("CollectionLinks")
.HasForeignKey("ChildID")
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.Property<int>("ProvidersID")
.HasColumnType("integer");
b.HasKey("LibrariesID", "ProvidersID");
b.HasIndex("ProvidersID");
b.ToTable("LibraryProviderID");
});
modelBuilder.Entity("LibraryShow", b =>
{
b.Property<int>("LibrariesID")
.HasColumnType("integer");
b.Property<int>("ShowsID")
.HasColumnType("integer");
b.HasKey("LibrariesID", "ShowsID");
b.HasIndex("ShowsID");
b.ToTable("LibraryShow");
});
modelBuilder.Entity("CollectionLibrary", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.CollectionDE", "Parent")
.WithMany("Links")
.HasForeignKey("ParentID")
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("CollectionShow", b =>
{
b.HasOne("Kyoo.Models.Collection", null)
.WithMany()
.HasForeignKey("CollectionsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
b.Navigation("Parent");
modelBuilder.Entity("GenreShow", b =>
{
b.HasOne("Kyoo.Models.Genre", null)
.WithMany()
.HasForeignKey("GenresID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
@ -525,7 +581,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.WithMany("Episodes")
.HasForeignKey("SeasonID");
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Episodes")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -536,42 +592,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.GenreLink", b =>
{
b.HasOne("Kyoo.Models.GenreDE", "Child")
.WithMany("Links")
.HasForeignKey("ChildID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Parent")
.WithMany("GenreLinks")
.HasForeignKey("ParentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.Navigation("Parent");
});
modelBuilder.Entity("Kyoo.Models.LibraryLink", b =>
{
b.HasOne("Kyoo.Models.CollectionDE", "Collection")
.WithMany("LibraryLinks")
.HasForeignKey("CollectionID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Collection", "Collection")
.WithMany()
.HasForeignKey("CollectionID");
b.HasOne("Kyoo.Models.LibraryDE", "Library")
.WithMany("Links")
b.HasOne("Kyoo.Models.Library", "Library")
.WithMany()
.HasForeignKey("LibraryID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Show")
.WithMany("LibraryLinks")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany()
.HasForeignKey("ShowID");
b.Navigation("Collection");
@ -603,7 +638,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.HasForeignKey("SeasonID")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("ExternalIDs")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade);
@ -627,7 +662,7 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("People")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -638,28 +673,9 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.ProviderLink", b =>
{
b.HasOne("Kyoo.Models.ProviderID", "Child")
.WithMany()
.HasForeignKey("ChildID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.LibraryDE", "Parent")
.WithMany("ProviderLinks")
.HasForeignKey("ParentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Child");
b.Navigation("Parent");
});
modelBuilder.Entity("Kyoo.Models.Season", b =>
{
b.HasOne("Kyoo.Models.ShowDE", "Show")
b.HasOne("Kyoo.Models.Show", "Show")
.WithMany("Seasons")
.HasForeignKey("ShowID")
.OnDelete(DeleteBehavior.Cascade)
@ -668,10 +684,10 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Show");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.HasOne("Kyoo.Models.Studio", "Studio")
.WithMany()
.WithMany("Shows")
.HasForeignKey("StudioID");
b.Navigation("Studio");
@ -688,11 +704,34 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Episode");
});
modelBuilder.Entity("Kyoo.Models.CollectionDE", b =>
modelBuilder.Entity("LibraryProviderID", b =>
{
b.Navigation("LibraryLinks");
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Links");
b.HasOne("Kyoo.Models.ProviderID", null)
.WithMany()
.HasForeignKey("ProvidersID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("LibraryShow", b =>
{
b.HasOne("Kyoo.Models.Library", null)
.WithMany()
.HasForeignKey("LibrariesID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Kyoo.Models.Show", null)
.WithMany()
.HasForeignKey("ShowsID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Kyoo.Models.Episode", b =>
@ -702,18 +741,6 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("Tracks");
});
modelBuilder.Entity("Kyoo.Models.GenreDE", b =>
{
b.Navigation("Links");
});
modelBuilder.Entity("Kyoo.Models.LibraryDE", b =>
{
b.Navigation("Links");
b.Navigation("ProviderLinks");
});
modelBuilder.Entity("Kyoo.Models.People", b =>
{
b.Navigation("ExternalIDs");
@ -728,22 +755,21 @@ namespace Kyoo.Models.DatabaseMigrations.Internal
b.Navigation("ExternalIDs");
});
modelBuilder.Entity("Kyoo.Models.ShowDE", b =>
modelBuilder.Entity("Kyoo.Models.Show", b =>
{
b.Navigation("CollectionLinks");
b.Navigation("Episodes");
b.Navigation("ExternalIDs");
b.Navigation("GenreLinks");
b.Navigation("LibraryLinks");
b.Navigation("People");
b.Navigation("Seasons");
});
modelBuilder.Entity("Kyoo.Models.Studio", b =>
{
b.Navigation("Shows");
});
#pragma warning restore 612, 618
}
}

View File

@ -11,7 +11,7 @@ namespace Kyoo.Tasks
new PluginLoader(),
new Crawler(),
new MetadataProviderLoader(),
new ReScan(),
// new ReScan(),
new ExtractMetadata()
};
}

View File

@ -1,127 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Kyoo.Controllers;
using Kyoo.Models;
using Microsoft.Extensions.DependencyInjection;
namespace Kyoo.Tasks
{
public class ReScan: ITask
{
public string Slug => "re-scan";
public string Name => "ReScan";
public string Description => "Re download metadata of an item using it's external ids.";
public string HelpMessage => null;
public bool RunOnStartup => false;
public int Priority => 0;
private IServiceProvider _serviceProvider;
private IThumbnailsManager _thumbnailsManager;
private IProviderManager _providerManager;
private DatabaseContext _database;
public async Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string arguments = null)
{
using IServiceScope serviceScope = serviceProvider.CreateScope();
_serviceProvider = serviceProvider;
_thumbnailsManager = serviceProvider.GetService<IThumbnailsManager>();
_providerManager = serviceProvider.GetService<IProviderManager>();
_database = serviceScope.ServiceProvider.GetService<DatabaseContext>();
if (arguments == null || !arguments.Contains('/'))
return;
string slug = arguments.Substring(arguments.IndexOf('/') + 1);
switch (arguments.Substring(0, arguments.IndexOf('/')))
{
case "show":
await ReScanShow(slug);
break;
case "season":
await ReScanSeason(slug);
break;
}
}
private async Task ReScanShow(string slug)
{
Show old;
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
{
ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
old = _database.Shows.FirstOrDefault(x => x.Slug == slug);
if (old == null)
return;
Library library = _database.LibraryLinks.First(x => x.Show == old && x.Library != null).Library;
Show edited = await _providerManager.CompleteShow(old, library);
edited.ID = old.ID;
edited.Slug = old.Slug;
edited.Path = old.Path;
await libraryManager.EditShow(edited, true);
await _thumbnailsManager.Validate(edited, true);
}
if (old.Seasons != null)
await Task.WhenAll(old.Seasons.Select(x => ReScanSeason(old, x)));
IEnumerable<Episode> orphans = old.Episodes.Where(x => x.Season == null).ToList();
if (orphans.Any())
await Task.WhenAll(orphans.Select(x => ReScanEpisode(old, x)));
}
private async Task ReScanSeason(string seasonSlug)
{
string[] infos = seasonSlug.Split('-');
if (infos.Length != 2 || int.TryParse(infos[1], out int seasonNumber))
return;
string slug = infos[0];
Show show = _database.Shows.FirstOrDefault(x => x.Slug == slug);
if (show == null)
return;
Season old = _database.Seasons.FirstOrDefault(x => x.SeasonNumber == seasonNumber && x.Show.ID == show.ID);
if (old == null)
return;
await ReScanSeason(show, old);
}
private async Task ReScanSeason(Show show, Season old)
{
using (IServiceScope serviceScope = _serviceProvider.CreateScope())
{
ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
Season edited = await _providerManager.GetSeason(show, old.SeasonNumber, library);
edited.ID = old.ID;
await libraryManager.EditSeason(edited, true);
await _thumbnailsManager.Validate(edited, true);
}
if (old.Episodes != null)
await Task.WhenAll(old.Episodes.Select(x => ReScanEpisode(show, x)));
}
private async Task ReScanEpisode(Show show, Episode old)
{
using IServiceScope serviceScope = _serviceProvider.CreateScope();
ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
Episode edited = await _providerManager.GetEpisode(show, old.Path, old.SeasonNumber, old.EpisodeNumber, old.AbsoluteNumber, library);
edited.ID = old.ID;
await libraryManager.EditEpisode(edited, true);
await _thumbnailsManager.Validate(edited, true);
}
public Task<IEnumerable<string>> GetPossibleParameters()
{
return Task.FromResult<IEnumerable<string>>(null);
}
public int? Progress()
{
return null;
}
}
}
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Threading;
// using System.Threading.Tasks;
// using Kyoo.Controllers;
// using Kyoo.Models;
// using Microsoft.Extensions.DependencyInjection;
//
// namespace Kyoo.Tasks
// {
// public class ReScan: ITask
// {
// public string Slug => "re-scan";
// public string Name => "ReScan";
// public string Description => "Re download metadata of an item using it's external ids.";
// public string HelpMessage => null;
// public bool RunOnStartup => false;
// public int Priority => 0;
//
//
// private IServiceProvider _serviceProvider;
// private IThumbnailsManager _thumbnailsManager;
// private IProviderManager _providerManager;
// private DatabaseContext _database;
//
// public async Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string arguments = null)
// {
// using IServiceScope serviceScope = serviceProvider.CreateScope();
// _serviceProvider = serviceProvider;
// _thumbnailsManager = serviceProvider.GetService<IThumbnailsManager>();
// _providerManager = serviceProvider.GetService<IProviderManager>();
// _database = serviceScope.ServiceProvider.GetService<DatabaseContext>();
//
// if (arguments == null || !arguments.Contains('/'))
// return;
//
// string slug = arguments.Substring(arguments.IndexOf('/') + 1);
// switch (arguments.Substring(0, arguments.IndexOf('/')))
// {
// case "show":
// await ReScanShow(slug);
// break;
// case "season":
// await ReScanSeason(slug);
// break;
// }
// }
//
// private async Task ReScanShow(string slug)
// {
// Show old;
//
// using (IServiceScope serviceScope = _serviceProvider.CreateScope())
// {
// ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
// old = _database.Shows.FirstOrDefault(x => x.Slug == slug);
// if (old == null)
// return;
// Library library = _database.LibraryLinks.First(x => x.Show == old && x.Library != null).Library;
// Show edited = await _providerManager.CompleteShow(old, library);
// edited.ID = old.ID;
// edited.Slug = old.Slug;
// edited.Path = old.Path;
// await libraryManager.EditShow(edited, true);
// await _thumbnailsManager.Validate(edited, true);
// }
// if (old.Seasons != null)
// await Task.WhenAll(old.Seasons.Select(x => ReScanSeason(old, x)));
// IEnumerable<Episode> orphans = old.Episodes.Where(x => x.Season == null).ToList();
// if (orphans.Any())
// await Task.WhenAll(orphans.Select(x => ReScanEpisode(old, x)));
// }
//
// private async Task ReScanSeason(string seasonSlug)
// {
// string[] infos = seasonSlug.Split('-');
// if (infos.Length != 2 || int.TryParse(infos[1], out int seasonNumber))
// return;
// string slug = infos[0];
// Show show = _database.Shows.FirstOrDefault(x => x.Slug == slug);
// if (show == null)
// return;
// Season old = _database.Seasons.FirstOrDefault(x => x.SeasonNumber == seasonNumber && x.Show.ID == show.ID);
// if (old == null)
// return;
// await ReScanSeason(show, old);
// }
//
// private async Task ReScanSeason(Show show, Season old)
// {
// using (IServiceScope serviceScope = _serviceProvider.CreateScope())
// {
// ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
// Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
// Season edited = await _providerManager.GetSeason(show, old.SeasonNumber, library);
// edited.ID = old.ID;
// await libraryManager.EditSeason(edited, true);
// await _thumbnailsManager.Validate(edited, true);
// }
// if (old.Episodes != null)
// await Task.WhenAll(old.Episodes.Select(x => ReScanEpisode(show, x)));
// }
//
// private async Task ReScanEpisode(Show show, Episode old)
// {
// using IServiceScope serviceScope = _serviceProvider.CreateScope();
// ILibraryManager libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
//
// Library library = _database.LibraryLinks.First(x => x.Show == show && x.Library != null).Library;
// Episode edited = await _providerManager.GetEpisode(show, old.Path, old.SeasonNumber, old.EpisodeNumber, old.AbsoluteNumber, library);
// edited.ID = old.ID;
// await libraryManager.EditEpisode(edited, true);
// await _thumbnailsManager.Validate(edited, true);
// }
//
// public Task<IEnumerable<string>> GetPossibleParameters()
// {
// return Task.FromResult<IEnumerable<string>>(null);
// }
//
// public int? Progress()
// {
// return null;
// }
// }
// }