Add show thumbnail as backup for new episodes

This commit is contained in:
Zoe Roux 2023-10-30 13:56:22 +01:00
parent 068e153ae9
commit 40c0403962
6 changed files with 266 additions and 66 deletions

View File

@ -159,7 +159,7 @@ namespace Kyoo.Abstractions.Models
/// A simple summary of informations about the show of this episode /// A simple summary of informations about the show of this episode
/// (this is specially useful since news can't have includes). /// (this is specially useful since news can't have includes).
/// </summary> /// </summary>
public class ShowInfo : IResource public class ShowInfo : IResource, IThumbnails
{ {
/// <inheritdoc/> /// <inheritdoc/>
public int Id { get; set; } public int Id { get; set; }
@ -171,6 +171,15 @@ namespace Kyoo.Abstractions.Models
/// The title of this show. /// The title of this show.
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }
/// <inheritdoc />
public Image? Poster { get; set; }
/// <inheritdoc />
public Image? Thumbnail { get; set; }
/// <inheritdoc />
public Image? Logo { get; set; }
} }
} }
} }

View File

@ -361,8 +361,11 @@ namespace Kyoo.Postgresql
modelBuilder.Entity<News>() modelBuilder.Entity<News>()
.Ignore(x => x.Links); .Ignore(x => x.Links);
modelBuilder.Entity<News>() var builder = modelBuilder.Entity<News>()
.OwnsOne(x => x.Show); .OwnsOne(x => x.Show);
builder.OwnsOne(x => x.Poster);
builder.OwnsOne(x => x.Thumbnail);
builder.OwnsOne(x => x.Logo);
} }
/// <summary> /// <summary>

View File

@ -1197,6 +1197,119 @@ namespace Kyoo.Postgresql.Migrations
modelBuilder.Entity("Kyoo.Abstractions.Models.News", b => modelBuilder.Entity("Kyoo.Abstractions.Models.News", b =>
{ {
b.OwnsOne("Kyoo.Abstractions.Models.News+ShowInfo", "Show", b1 =>
{
b1.Property<int>("NewsId")
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("show_id");
b1.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_name");
b1.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_slug");
b1.HasKey("NewsId");
b1.ToTable("news");
b1.WithOwner()
.HasForeignKey("NewsId")
.HasConstraintName("fk_news_news_id");
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_logo_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_logo_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Poster", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_poster_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_poster_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Thumbnail", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_thumbnail_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_thumbnail_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.Navigation("Logo");
b1.Navigation("Poster");
b1.Navigation("Thumbnail");
});
b.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b1 => b.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b1 =>
{ {
b1.Property<int>("NewsId") b1.Property<int>("NewsId")
@ -1275,35 +1388,6 @@ namespace Kyoo.Postgresql.Migrations
.HasConstraintName("fk_news_news_id"); .HasConstraintName("fk_news_news_id");
}); });
b.OwnsOne("Kyoo.Abstractions.Models.ShowInfo", "Show", b1 =>
{
b1.Property<int>("NewsId")
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("show_info_id");
b1.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_info_name");
b1.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_info_slug");
b1.HasKey("NewsId");
b1.ToTable("news");
b1.WithOwner()
.HasForeignKey("NewsId")
.HasConstraintName("fk_news_news_id");
});
b.Navigation("Logo"); b.Navigation("Logo");
b.Navigation("Poster"); b.Navigation("Poster");

View File

@ -38,7 +38,9 @@ namespace Kyoo.Postgresql.Migrations
e.id, e.slug, e.name, NULL AS tagline, '{}' AS aliases, e.path, e.overview, '{}' AS tags, '{}' AS genres, e.id, e.slug, e.name, NULL AS tagline, '{}' AS aliases, e.path, e.overview, '{}' AS tags, '{}' AS genres,
NULL AS status, e.release_date AS air_date, e.poster_source, e.poster_blurhash, e.thumbnail_source, e.thumbnail_blurhash, NULL AS status, e.release_date AS air_date, e.poster_source, e.poster_blurhash, e.thumbnail_source, e.thumbnail_blurhash,
e.logo_source,e.logo_blurhash, NULL AS trailer, e.external_id, e.season_number, e.episode_number, e.absolute_number, e.logo_source,e.logo_blurhash, NULL AS trailer, e.external_id, e.season_number, e.episode_number, e.absolute_number,
'episode'::news_kind AS kind, e.added_date, s.id AS show_id, s.slug AS show_slug, s.name AS show_name 'episode'::news_kind AS kind, e.added_date, s.id AS show_id, s.slug AS show_slug, s.name AS show_name,
s.poster_source AS show_poster_source, s.poster_blurhash AS show_poster_blurhash, s.thumbnail_source AS show_thumbnail_source,
s.thumbnail_blurhash AS show_thumbnail_blurhash, s.logo_source AS show_logo_source, s.logo_blurhash AS show_logo_blurhash
FROM episodes AS e FROM episodes AS e
LEFT JOIN shows AS s ON e.show_id = s.id LEFT JOIN shows AS s ON e.show_id = s.id
UNION ALL UNION ALL
@ -46,7 +48,9 @@ namespace Kyoo.Postgresql.Migrations
-m.id, m.slug, m.name, m.tagline, m.aliases, m.path, m.overview, m.tags, m.genres, -m.id, m.slug, m.name, m.tagline, m.aliases, m.path, m.overview, m.tags, m.genres,
m.status, m.air_date, m.poster_source, m.poster_blurhash, m.thumbnail_source, m.thumbnail_blurhash, m.status, m.air_date, m.poster_source, m.poster_blurhash, m.thumbnail_source, m.thumbnail_blurhash,
m.logo_source, m.logo_blurhash, m.trailer, m.external_id, NULL AS season_number, NULL AS episode_number, NULL as absolute_number, m.logo_source, m.logo_blurhash, m.trailer, m.external_id, NULL AS season_number, NULL AS episode_number, NULL as absolute_number,
'movie'::news_kind AS kind, m.added_date, NULL AS show_id, NULL AS show_slug, NULL AS show_name 'movie'::news_kind AS kind, m.added_date, NULL AS show_id, NULL AS show_slug, NULL AS show_name,
NULL AS show_poster_source, NULL AS show_poster_blurhash, NULL AS show_thumbnail_source, NULL AS show_thumbnail_blurhash,
NULL AS show_logo_source, NULL AS show_logo_blurhash
FROM movies AS m FROM movies AS m
"); ");
} }

View File

@ -1,4 +1,4 @@
// <auto-generated /> // <auto-generated />
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Kyoo.Abstractions.Models; using Kyoo.Abstractions.Models;
@ -1194,6 +1194,119 @@ namespace Kyoo.Postgresql.Migrations
modelBuilder.Entity("Kyoo.Abstractions.Models.News", b => modelBuilder.Entity("Kyoo.Abstractions.Models.News", b =>
{ {
b.OwnsOne("Kyoo.Abstractions.Models.News+ShowInfo", "Show", b1 =>
{
b1.Property<int>("NewsId")
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("show_id");
b1.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_name");
b1.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_slug");
b1.HasKey("NewsId");
b1.ToTable("news");
b1.WithOwner()
.HasForeignKey("NewsId")
.HasConstraintName("fk_news_news_id");
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_logo_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_logo_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Poster", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_poster_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_poster_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.OwnsOne("Kyoo.Abstractions.Models.Image", "Thumbnail", b2 =>
{
b2.Property<int>("ShowInfoNewsId")
.HasColumnType("integer")
.HasColumnName("id");
b2.Property<string>("Blurhash")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("show_thumbnail_blurhash");
b2.Property<string>("Source")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_thumbnail_source");
b2.HasKey("ShowInfoNewsId");
b2.ToTable("news");
b2.WithOwner()
.HasForeignKey("ShowInfoNewsId")
.HasConstraintName("fk_news_news_id");
});
b1.Navigation("Logo");
b1.Navigation("Poster");
b1.Navigation("Thumbnail");
});
b.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b1 => b.OwnsOne("Kyoo.Abstractions.Models.Image", "Logo", b1 =>
{ {
b1.Property<int>("NewsId") b1.Property<int>("NewsId")
@ -1272,35 +1385,6 @@ namespace Kyoo.Postgresql.Migrations
.HasConstraintName("fk_news_news_id"); .HasConstraintName("fk_news_news_id");
}); });
b.OwnsOne("Kyoo.Abstractions.Models.ShowInfo", "Show", b1 =>
{
b1.Property<int>("NewsId")
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<int>("Id")
.HasColumnType("integer")
.HasColumnName("show_info_id");
b1.Property<string>("Name")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_info_name");
b1.Property<string>("Slug")
.IsRequired()
.HasColumnType("text")
.HasColumnName("show_info_slug");
b1.HasKey("NewsId");
b1.ToTable("news");
b1.WithOwner()
.HasForeignKey("NewsId")
.HasConstraintName("fk_news_news_id");
});
b.Navigation("Logo"); b.Navigation("Logo");
b.Navigation("Poster"); b.Navigation("Poster");

View File

@ -22,6 +22,7 @@ import { z } from "zod";
import { MovieP } from "./movie"; import { MovieP } from "./movie";
import { BaseEpisodeP } from "./episode"; import { BaseEpisodeP } from "./episode";
import { ResourceP } from "../traits/resource"; import { ResourceP } from "../traits/resource";
import { withImages } from "../traits/images";
/** /**
* The type of item, ether a a movie or an episode. * The type of item, ether a a movie or an episode.
@ -38,11 +39,26 @@ export const NewsP = z.union([
BaseEpisodeP.and( BaseEpisodeP.and(
z.object({ z.object({
kind: z.literal(NewsKind.Episode), kind: z.literal(NewsKind.Episode),
show: ResourceP.extend({ show: withImages(
ResourceP.extend({
name: z.string(), name: z.string(),
}), }),
"shows",
).transform((x) => {
if (!x.thumbnail && x.poster) {
x.thumbnail = { ...x.poster };
if (x.thumbnail) {
x.thumbnail.low = x.thumbnail.high;
x.thumbnail.medium = x.thumbnail.high;
}
}
return x;
}),
}),
).transform((x) => {
if (!x.thumbnail && x.show.thumbnail) x.thumbnail = x.show.thumbnail;
return x;
}), }),
),
/* /*
* Or a Movie * Or a Movie
*/ */