mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Abstractions.Models.Utils;
|
||||
using Kyoo.Postgresql;
|
||||
@ -30,7 +31,8 @@ namespace Kyoo.Core.Controllers;
|
||||
/// <summary>
|
||||
/// A local repository to handle collections
|
||||
/// </summary>
|
||||
public class CollectionRepository(DatabaseContext database) : GenericRepository<Collection>(database)
|
||||
public class CollectionRepository(DatabaseContext database, IThumbnailsManager thumbnails)
|
||||
: GenericRepository<Collection>(database)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override async Task<ICollection<Collection>> Search(
|
||||
@ -51,6 +53,7 @@ public class CollectionRepository(DatabaseContext database) : GenericRepository<
|
||||
|
||||
if (string.IsNullOrEmpty(resource.Name))
|
||||
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)
|
||||
|
@ -32,7 +32,7 @@ namespace Kyoo.Core.Controllers;
|
||||
/// <summary>
|
||||
/// A local repository to handle episodes.
|
||||
/// </summary>
|
||||
public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows)
|
||||
public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows, IThumbnailsManager thumbnails)
|
||||
: GenericRepository<Episode>(database)
|
||||
{
|
||||
static EpisodeRepository()
|
||||
@ -96,6 +96,7 @@ public class EpisodeRepository(DatabaseContext database, IRepository<Show> shows
|
||||
x.ShowId == resource.ShowId && x.SeasonNumber == resource.SeasonNumber
|
||||
);
|
||||
}
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -27,8 +27,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kyoo.Core.Controllers;
|
||||
|
||||
public class MovieRepository(DatabaseContext database, IRepository<Studio> studios)
|
||||
: GenericRepository<Movie>(database)
|
||||
public class MovieRepository(
|
||||
DatabaseContext database,
|
||||
IRepository<Studio> studios,
|
||||
IThumbnailsManager thumbnails
|
||||
) : GenericRepository<Movie>(database)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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.StudioId = resource.Studio.Id;
|
||||
}
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kyoo.Core.Controllers;
|
||||
|
||||
public class SeasonRepository(DatabaseContext database) : GenericRepository<Season>(database)
|
||||
public class SeasonRepository(DatabaseContext database, IThumbnailsManager thumbnails)
|
||||
: GenericRepository<Season>(database)
|
||||
{
|
||||
static SeasonRepository()
|
||||
{
|
||||
@ -90,5 +91,6 @@ public class SeasonRepository(DatabaseContext database) : GenericRepository<Seas
|
||||
}
|
||||
resource.ShowId = resource.Show.Id;
|
||||
}
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kyoo.Core.Controllers;
|
||||
|
||||
public class ShowRepository(DatabaseContext database, IRepository<Studio> studios)
|
||||
: GenericRepository<Show>(database)
|
||||
public class ShowRepository(
|
||||
DatabaseContext database,
|
||||
IRepository<Studio> studios,
|
||||
IThumbnailsManager thumbnails
|
||||
) : GenericRepository<Show>(database)
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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.StudioId = resource.Studio.Id;
|
||||
}
|
||||
await thumbnails.DownloadImages(resource);
|
||||
}
|
||||
}
|
||||
|
@ -57,8 +57,17 @@ public class ThumbnailsManager(
|
||||
try
|
||||
{
|
||||
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);
|
||||
|
||||
@ -81,31 +90,19 @@ public class ThumbnailsManager(
|
||||
new SKSizeI(original.Width, original.Height),
|
||||
SKFilterQuality.High
|
||||
);
|
||||
await _WriteTo(
|
||||
original,
|
||||
$"{localPath}.{ImageQuality.High.ToString().ToLowerInvariant()}.webp",
|
||||
90
|
||||
);
|
||||
await _WriteTo(original, GetImagePath(image.Id, ImageQuality.High), 90);
|
||||
|
||||
using SKBitmap medium = high.Resize(
|
||||
new SKSizeI((int)(high.Width / 1.5), (int)(high.Height / 1.5)),
|
||||
SKFilterQuality.Medium
|
||||
);
|
||||
await _WriteTo(
|
||||
medium,
|
||||
$"{localPath}.{ImageQuality.Medium.ToString().ToLowerInvariant()}.webp",
|
||||
75
|
||||
);
|
||||
await _WriteTo(medium, GetImagePath(image.Id, ImageQuality.Medium), 75);
|
||||
|
||||
using SKBitmap low = medium.Resize(
|
||||
new SKSizeI(original.Width / 2, original.Height / 2),
|
||||
SKFilterQuality.Low
|
||||
);
|
||||
await _WriteTo(
|
||||
low,
|
||||
$"{localPath}.{ImageQuality.Low.ToString().ToLowerInvariant()}.webp",
|
||||
50
|
||||
);
|
||||
await _WriteTo(low, GetImagePath(image.Id, ImageQuality.Low), 50);
|
||||
|
||||
image.Blurhash = Blurhasher.Encode(low, 4, 3);
|
||||
}
|
||||
@ -136,7 +133,7 @@ public class ThumbnailsManager(
|
||||
public Task DeleteImages<T>(T item)
|
||||
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)
|
||||
.SelectMany(x => $"/metadata/{x}")
|
||||
.SelectMany(x =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user