mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Add image creation code in Validate() of resources
This commit is contained in:
parent
b904f25d33
commit
e9b29dd814
@ -20,6 +20,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
using Kyoo.Abstractions.Models.Utils;
|
using Kyoo.Abstractions.Models.Utils;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
@ -30,7 +31,8 @@ namespace Kyoo.Core.Controllers;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A local repository to handle collections
|
/// A local repository to handle collections
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CollectionRepository(DatabaseContext database) : GenericRepository<Collection>(database)
|
public class CollectionRepository(DatabaseContext database, IThumbnailsManager thumbnails)
|
||||||
|
: GenericRepository<Collection>(database)
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ICollection<Collection>> Search(
|
public override async Task<ICollection<Collection>> Search(
|
||||||
@ -51,6 +53,7 @@ public class CollectionRepository(DatabaseContext database) : GenericRepository<
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(resource.Name))
|
if (string.IsNullOrEmpty(resource.Name))
|
||||||
throw new ArgumentException("The collection's name must be set and not empty");
|
throw new ArgumentException("The collection's name must be set and not empty");
|
||||||
|
await thumbnails.DownloadImages(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddMovie(Guid id, Guid movieId)
|
public async Task AddMovie(Guid id, Guid movieId)
|
||||||
|
@ -32,7 +32,7 @@ namespace Kyoo.Core.Controllers;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A local repository to handle episodes.
|
/// A local repository to handle episodes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows)
|
public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows, IThumbnailsManager thumbnails)
|
||||||
: GenericRepository<Episode>(database)
|
: GenericRepository<Episode>(database)
|
||||||
{
|
{
|
||||||
static EpisodeRepository()
|
static EpisodeRepository()
|
||||||
@ -96,6 +96,7 @@ public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows
|
|||||||
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
|
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
await thumbnails.DownloadImages(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -27,8 +27,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Kyoo.Core.Controllers;
|
namespace Kyoo.Core.Controllers;
|
||||||
|
|
||||||
public class MovieRepository(DatabaseContext database, IRepository<Studio> studios)
|
public class MovieRepository(
|
||||||
: GenericRepository<Movie>(database)
|
DatabaseContext database,
|
||||||
|
IRepository<Studio> studios,
|
||||||
|
IThumbnailsManager thumbnails
|
||||||
|
) : GenericRepository<Movie>(database)
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ICollection<Movie>> Search(
|
public override async Task<ICollection<Movie>> Search(
|
||||||
@ -51,5 +54,6 @@ public class MovieRepository(DatabaseContext database, IRepository<Studio> studi
|
|||||||
resource.Studio = await studios.CreateIfNotExists(resource.Studio);
|
resource.Studio = await studios.CreateIfNotExists(resource.Studio);
|
||||||
resource.StudioId = resource.Studio.Id;
|
resource.StudioId = resource.Studio.Id;
|
||||||
}
|
}
|
||||||
|
await thumbnails.DownloadImages(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
|
|
||||||
namespace Kyoo.Core.Controllers;
|
namespace Kyoo.Core.Controllers;
|
||||||
|
|
||||||
public class SeasonRepository(DatabaseContext database) : GenericRepository<Season>(database)
|
public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumbnails)
|
||||||
|
: GenericRepository<Season>(database)
|
||||||
{
|
{
|
||||||
static SeasonRepository()
|
static SeasonRepository()
|
||||||
{
|
{
|
||||||
@ -90,5 +91,6 @@ public class SeasonRepository(DatabaseContext database) : GenericRepository<Seas
|
|||||||
}
|
}
|
||||||
resource.ShowId = resource.Show.Id;
|
resource.ShowId = resource.Show.Id;
|
||||||
}
|
}
|
||||||
|
await thumbnails.DownloadImages(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Kyoo.Core.Controllers;
|
namespace Kyoo.Core.Controllers;
|
||||||
|
|
||||||
public class ShowRepository(DatabaseContext database, IRepository<Studio> studios)
|
public class ShowRepository(
|
||||||
: GenericRepository<Show>(database)
|
DatabaseContext database,
|
||||||
|
IRepository<Studio> studios,
|
||||||
|
IThumbnailsManager thumbnails
|
||||||
|
) : GenericRepository<Show>(database)
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task<ICollection<Show>> Search(
|
public override async Task<ICollection<Show>> Search(
|
||||||
@ -51,5 +54,6 @@ public class ShowRepository(DatabaseContext database, IRepository<Studio> studio
|
|||||||
resource.Studio = await studios.CreateIfNotExists(resource.Studio);
|
resource.Studio = await studios.CreateIfNotExists(resource.Studio);
|
||||||
resource.StudioId = resource.Studio.Id;
|
resource.StudioId = resource.Studio.Id;
|
||||||
}
|
}
|
||||||
|
await thumbnails.DownloadImages(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,17 @@ public class ThumbnailsManager(
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (image.Id == Guid.Empty)
|
if (image.Id == Guid.Empty)
|
||||||
image.Id = new Guid();
|
{
|
||||||
string localPath = $"/metadata/{image.Id}";
|
using MD5 md5 = MD5.Create();
|
||||||
|
image.Id = new Guid(md5.ComputeHash(Encoding.UTF8.GetBytes(image.Source)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
File.Exists(GetImagePath(image.Id, ImageQuality.High))
|
||||||
|
&& File.Exists(GetImagePath(image.Id, ImageQuality.Medium))
|
||||||
|
&& File.Exists(GetImagePath(image.Id, ImageQuality.Low))
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
|
||||||
logger.LogInformation("Downloading image {What}", what);
|
logger.LogInformation("Downloading image {What}", what);
|
||||||
|
|
||||||
@ -81,31 +90,19 @@ public class ThumbnailsManager(
|
|||||||
new SKSizeI(original.Width, original.Height),
|
new SKSizeI(original.Width, original.Height),
|
||||||
SKFilterQuality.High
|
SKFilterQuality.High
|
||||||
);
|
);
|
||||||
await _WriteTo(
|
await _WriteTo(original, GetImagePath(image.Id, ImageQuality.High), 90);
|
||||||
original,
|
|
||||||
$"{localPath}.{ImageQuality.High.ToString().ToLowerInvariant()}.webp",
|
|
||||||
90
|
|
||||||
);
|
|
||||||
|
|
||||||
using SKBitmap medium = high.Resize(
|
using SKBitmap medium = high.Resize(
|
||||||
new SKSizeI((int)(high.Width / 1.5), (int)(high.Height / 1.5)),
|
new SKSizeI((int)(high.Width / 1.5), (int)(high.Height / 1.5)),
|
||||||
SKFilterQuality.Medium
|
SKFilterQuality.Medium
|
||||||
);
|
);
|
||||||
await _WriteTo(
|
await _WriteTo(medium, GetImagePath(image.Id, ImageQuality.Medium), 75);
|
||||||
medium,
|
|
||||||
$"{localPath}.{ImageQuality.Medium.ToString().ToLowerInvariant()}.webp",
|
|
||||||
75
|
|
||||||
);
|
|
||||||
|
|
||||||
using SKBitmap low = medium.Resize(
|
using SKBitmap low = medium.Resize(
|
||||||
new SKSizeI(original.Width / 2, original.Height / 2),
|
new SKSizeI(original.Width / 2, original.Height / 2),
|
||||||
SKFilterQuality.Low
|
SKFilterQuality.Low
|
||||||
);
|
);
|
||||||
await _WriteTo(
|
await _WriteTo(low, GetImagePath(image.Id, ImageQuality.Low), 50);
|
||||||
low,
|
|
||||||
$"{localPath}.{ImageQuality.Low.ToString().ToLowerInvariant()}.webp",
|
|
||||||
50
|
|
||||||
);
|
|
||||||
|
|
||||||
image.Blurhash = Blurhasher.Encode(low, 4, 3);
|
image.Blurhash = Blurhasher.Encode(low, 4, 3);
|
||||||
}
|
}
|
||||||
@ -136,7 +133,7 @@ public class ThumbnailsManager(
|
|||||||
public Task DeleteImages<T>(T item)
|
public Task DeleteImages<T>(T item)
|
||||||
where T : IThumbnails
|
where T : IThumbnails
|
||||||
{
|
{
|
||||||
IEnumerable<string> images = new[] {item.Poster?.Id, item.Thumbnail?.Id, item.Logo?.Id}
|
IEnumerable<string> images = new[] { item.Poster?.Id, item.Thumbnail?.Id, item.Logo?.Id }
|
||||||
.Where(x => x is not null)
|
.Where(x => x is not null)
|
||||||
.SelectMany(x => $"/metadata/{x}")
|
.SelectMany(x => $"/metadata/{x}")
|
||||||
.SelectMany(x =>
|
.SelectMany(x =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user