mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Reworking the thumbnail manager
This commit is contained in:
parent
3acc69d602
commit
5f98484b4a
@ -50,6 +50,20 @@ namespace Kyoo.Controllers
|
||||
/// <returns>A writer to write to the new file.</returns>
|
||||
public Stream NewFile([NotNull] string path);
|
||||
|
||||
/// <summary>
|
||||
/// Create a new directory at the given path
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the directory</param>
|
||||
/// <returns>The path of the newly created directory is returned.</returns>
|
||||
public Task<string> CreateDirectory([NotNull] string path);
|
||||
|
||||
/// <summary>
|
||||
/// Combine multiple paths.
|
||||
/// </summary>
|
||||
/// <param name="paths">The paths to combine</param>
|
||||
/// <returns>The combined path.</returns>
|
||||
public string Combine(params string[] paths);
|
||||
|
||||
/// <summary>
|
||||
/// List files in a directory.
|
||||
/// </summary>
|
||||
|
@ -1,23 +1,59 @@
|
||||
using Kyoo.Models;
|
||||
using System;
|
||||
using Kyoo.Models;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Kyoo.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Download images and retrieve the path of those images for a resource.
|
||||
/// </summary>
|
||||
public interface IThumbnailsManager
|
||||
{
|
||||
Task Validate(Show show, bool alwaysDownload = false);
|
||||
Task Validate(Season season, bool alwaysDownload = false);
|
||||
Task Validate(Episode episode, bool alwaysDownload = false);
|
||||
Task Validate(People actors, bool alwaysDownload = false);
|
||||
Task Validate(Provider actors, bool alwaysDownload = false);
|
||||
/// <summary>
|
||||
/// Download images of a specified item.
|
||||
/// If no images is available to download, do nothing and silently return.
|
||||
/// </summary>
|
||||
/// <param name="item">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <typeparam name="T">The type of the item</typeparam>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
Task<bool> DownloadImages<T>([NotNull] T item, bool alwaysDownload = false)
|
||||
where T : IResource;
|
||||
|
||||
|
||||
Task<string> GetShowPoster([NotNull] Show show);
|
||||
Task<string> GetShowLogo([NotNull] Show show);
|
||||
Task<string> GetShowBackdrop([NotNull] Show show);
|
||||
Task<string> GetSeasonPoster([NotNull] Season season);
|
||||
Task<string> GetEpisodeThumb([NotNull] Episode episode);
|
||||
Task<string> GetPeoplePoster([NotNull] People people);
|
||||
Task<string> GetProviderLogo([NotNull] Provider provider);
|
||||
/// <summary>
|
||||
/// Retrieve the local path of the poster of the given item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to retrieve the poster from.</param>
|
||||
/// <typeparam name="T">The type of the item</typeparam>
|
||||
/// <exception cref="NotSupportedException">If the type does not have a poster</exception>
|
||||
/// <returns>The path of the poster for the given resource (it might or might not exists).</returns>
|
||||
Task<string> GetPoster<T>([NotNull] T item)
|
||||
where T : IResource;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the local path of the logo of the given item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to retrieve the logo from.</param>
|
||||
/// <typeparam name="T">The type of the item</typeparam>
|
||||
/// <exception cref="NotSupportedException">If the type does not have a logo</exception>
|
||||
/// <returns>The path of the logo for the given resource (it might or might not exists).</returns>
|
||||
Task<string> GetLogo<T>([NotNull] T item)
|
||||
where T : IResource;
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the local path of the thumbnail of the given item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to retrieve the thumbnail from.</param>
|
||||
/// <typeparam name="T">The type of the item</typeparam>
|
||||
/// <exception cref="NotSupportedException">If the type does not have a thumbnail</exception>
|
||||
/// <returns>The path of the thumbnail for the given resource (it might or might not exists).</returns>
|
||||
Task<string> GetThumbnail<T>([NotNull] T item)
|
||||
where T : IResource;
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,21 @@ namespace Kyoo.Controllers
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
return File.Create(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<string> CreateDirectory(string path)
|
||||
{
|
||||
if (path == null)
|
||||
throw new ArgumentNullException(nameof(path));
|
||||
Directory.CreateDirectory(path);
|
||||
return Task.FromResult(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Combine(params string[] paths)
|
||||
{
|
||||
return Path.Combine(paths);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ICollection<string>> ListFiles(string path, SearchOption options = SearchOption.TopDirectoryOnly)
|
||||
|
@ -1,157 +1,266 @@
|
||||
using Kyoo.Models;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.Models.Options;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Kyoo.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Download images and retrieve the path of those images for a resource.
|
||||
/// </summary>
|
||||
public class ThumbnailsManager : IThumbnailsManager
|
||||
{
|
||||
/// <summary>
|
||||
/// The file manager used to download the image if the file is distant
|
||||
/// </summary>
|
||||
private readonly IFileManager _files;
|
||||
/// <summary>
|
||||
/// A logger to report errors.
|
||||
/// </summary>
|
||||
private readonly ILogger<ThumbnailsManager> _logger;
|
||||
/// <summary>
|
||||
/// The options containing the base path of people images and provider logos.
|
||||
/// </summary>
|
||||
private readonly IOptionsMonitor<BasicOptions> _options;
|
||||
|
||||
public ThumbnailsManager(IFileManager files, IOptionsMonitor<BasicOptions> options)
|
||||
/// <summary>
|
||||
/// Create a new <see cref="ThumbnailsManager"/>.
|
||||
/// </summary>
|
||||
/// <param name="files">The file manager to use.</param>
|
||||
/// <param name="logger">A logger to report errors</param>
|
||||
/// <param name="options">The options to use.</param>
|
||||
public ThumbnailsManager(IFileManager files,
|
||||
ILogger<ThumbnailsManager> logger,
|
||||
IOptionsMonitor<BasicOptions> options)
|
||||
{
|
||||
_files = files;
|
||||
_logger = logger;
|
||||
_options = options;
|
||||
Directory.CreateDirectory(_options.CurrentValue.PeoplePath);
|
||||
Directory.CreateDirectory(_options.CurrentValue.ProviderPath);
|
||||
|
||||
options.OnChange(x =>
|
||||
{
|
||||
_files.CreateDirectory(x.PeoplePath);
|
||||
_files.CreateDirectory(x.ProviderPath);
|
||||
});
|
||||
}
|
||||
|
||||
private static async Task DownloadImage(string url, string localPath, string what)
|
||||
/// <inheritdoc />
|
||||
public Task<bool> DownloadImages<T>(T item, bool alwaysDownload = false)
|
||||
where T : IResource
|
||||
{
|
||||
if (item == null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
return item switch
|
||||
{
|
||||
Show show => _Validate(show, alwaysDownload),
|
||||
Season season => _Validate(season, alwaysDownload),
|
||||
Episode episode => _Validate(episode, alwaysDownload),
|
||||
People people => _Validate(people, alwaysDownload),
|
||||
Provider provider => _Validate(provider, alwaysDownload),
|
||||
_ => Task.FromResult(false)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An helper function to download an image using a <see cref="FileManager"/>.
|
||||
/// </summary>
|
||||
/// <param name="url">The distant url of the image</param>
|
||||
/// <param name="localPath">The local path of the image</param>
|
||||
/// <param name="what">What is currently downloaded (used for errors)</param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _DownloadImage(string url, string localPath, string what)
|
||||
{
|
||||
if (url == localPath)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
using WebClient client = new();
|
||||
await client.DownloadFileTaskAsync(new Uri(url), localPath);
|
||||
await using Stream reader = _files.GetReader(url);
|
||||
await using Stream local = _files.NewFile(localPath);
|
||||
await reader.CopyToAsync(local);
|
||||
return true;
|
||||
}
|
||||
catch (WebException exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync($"{what} could not be downloaded. Error: {exception.Message}.");
|
||||
_logger.LogError(ex, "{What} could not be downloaded", what);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Validate(Show show, bool alwaysDownload)
|
||||
/// <summary>
|
||||
/// Download images of a specified show.
|
||||
/// </summary>
|
||||
/// <param name="show">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _Validate([NotNull] Show show, bool alwaysDownload)
|
||||
{
|
||||
bool ret = false;
|
||||
|
||||
if (show.Poster != null)
|
||||
{
|
||||
string posterPath = await GetShowPoster(show);
|
||||
if (alwaysDownload || !File.Exists(posterPath))
|
||||
await DownloadImage(show.Poster, posterPath, $"The poster of {show.Title}");
|
||||
string posterPath = await GetPoster(show);
|
||||
if (alwaysDownload || !await _files.Exists(posterPath))
|
||||
ret |= await _DownloadImage(show.Poster, posterPath, $"The poster of {show.Title}");
|
||||
}
|
||||
if (show.Logo != null)
|
||||
{
|
||||
string logoPath = await GetShowLogo(show);
|
||||
if (alwaysDownload || !File.Exists(logoPath))
|
||||
await DownloadImage(show.Logo, logoPath, $"The logo of {show.Title}");
|
||||
string logoPath = await GetLogo(show);
|
||||
if (alwaysDownload || !await _files.Exists(logoPath))
|
||||
ret |= await _DownloadImage(show.Logo, logoPath, $"The logo of {show.Title}");
|
||||
}
|
||||
if (show.Backdrop != null)
|
||||
{
|
||||
string backdropPath = await GetShowBackdrop(show);
|
||||
if (alwaysDownload || !File.Exists(backdropPath))
|
||||
await DownloadImage(show.Backdrop, backdropPath, $"The backdrop of {show.Title}");
|
||||
string backdropPath = await GetThumbnail(show);
|
||||
if (alwaysDownload || !await _files.Exists(backdropPath))
|
||||
ret |= await _DownloadImage(show.Backdrop, backdropPath, $"The backdrop of {show.Title}");
|
||||
}
|
||||
|
||||
foreach (PeopleRole role in show.People)
|
||||
await Validate(role.People, alwaysDownload);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public async Task Validate([NotNull] People people, bool alwaysDownload)
|
||||
/// <summary>
|
||||
/// Download images of a specified person.
|
||||
/// </summary>
|
||||
/// <param name="people">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _Validate([NotNull] People people, bool alwaysDownload)
|
||||
{
|
||||
if (people == null)
|
||||
throw new ArgumentNullException(nameof(people));
|
||||
if (people.Poster == null)
|
||||
return;
|
||||
string localPath = await GetPeoplePoster(people);
|
||||
if (alwaysDownload || !File.Exists(localPath))
|
||||
await DownloadImage(people.Poster, localPath, $"The profile picture of {people.Name}");
|
||||
return false;
|
||||
string localPath = await GetPoster(people);
|
||||
if (alwaysDownload || !await _files.Exists(localPath))
|
||||
return await _DownloadImage(people.Poster, localPath, $"The profile picture of {people.Name}");
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task Validate(Season season, bool alwaysDownload)
|
||||
/// <summary>
|
||||
/// Download images of a specified season.
|
||||
/// </summary>
|
||||
/// <param name="season">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _Validate([NotNull] Season season, bool alwaysDownload)
|
||||
{
|
||||
if (season?.Show?.Path == null || season.Poster == null)
|
||||
return;
|
||||
if (season.Poster == null)
|
||||
return false;
|
||||
|
||||
string localPath = await GetSeasonPoster(season);
|
||||
if (alwaysDownload || !File.Exists(localPath))
|
||||
await DownloadImage(season.Poster, localPath, $"The poster of {season.Show.Title}'s season {season.SeasonNumber}");
|
||||
string localPath = await GetPoster(season);
|
||||
if (alwaysDownload || !await _files.Exists(localPath))
|
||||
return await _DownloadImage(season.Poster, localPath, $"The poster of {season.Slug}");
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task Validate(Episode episode, bool alwaysDownload)
|
||||
/// <summary>
|
||||
/// Download images of a specified episode.
|
||||
/// </summary>
|
||||
/// <param name="episode">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _Validate([NotNull] Episode episode, bool alwaysDownload)
|
||||
{
|
||||
if (episode?.Path == null || episode.Thumb == null)
|
||||
return;
|
||||
if (episode.Thumb == null)
|
||||
return false;
|
||||
|
||||
string localPath = await GetEpisodeThumb(episode);
|
||||
if (alwaysDownload || !File.Exists(localPath))
|
||||
await DownloadImage(episode.Thumb, localPath, $"The thumbnail of {episode.Slug}");
|
||||
if (alwaysDownload || !await _files.Exists(localPath))
|
||||
return await _DownloadImage(episode.Thumb, localPath, $"The thumbnail of {episode.Slug}");
|
||||
return false;
|
||||
}
|
||||
|
||||
public async Task Validate(Provider provider, bool alwaysDownload)
|
||||
/// <summary>
|
||||
/// Download images of a specified provider.
|
||||
/// </summary>
|
||||
/// <param name="provider">
|
||||
/// The item to cache images.
|
||||
/// </param>
|
||||
/// <param name="alwaysDownload">
|
||||
/// <c>true</c> if images should be downloaded even if they already exists locally, <c>false</c> otherwise.
|
||||
/// </param>
|
||||
/// <returns><c>true</c> if an image has been downloaded, <c>false</c> otherwise.</returns>
|
||||
private async Task<bool> _Validate([NotNull] Provider provider, bool alwaysDownload)
|
||||
{
|
||||
if (provider.Logo == null)
|
||||
return;
|
||||
return false;
|
||||
|
||||
string localPath = await GetProviderLogo(provider);
|
||||
if (alwaysDownload || !File.Exists(localPath))
|
||||
await DownloadImage(provider.Logo, localPath, $"The logo of {provider.Slug}");
|
||||
string localPath = await GetLogo(provider);
|
||||
if (alwaysDownload || !await _files.Exists(localPath))
|
||||
return await _DownloadImage(provider.Logo, localPath, $"The logo of {provider.Slug}");
|
||||
return false;
|
||||
}
|
||||
|
||||
public Task<string> GetShowBackdrop(Show show)
|
||||
/// <inheritdoc />
|
||||
public Task<string> GetPoster<T>(T item)
|
||||
where T : IResource
|
||||
{
|
||||
if (show?.Path == null)
|
||||
throw new ArgumentNullException(nameof(show));
|
||||
return Task.FromResult(Path.Combine(_files.GetExtraDirectory(show), "backdrop.jpg"));
|
||||
if (item == null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
return Task.FromResult(item switch
|
||||
{
|
||||
Show show => _files.Combine(_files.GetExtraDirectory(show), "poster.jpg"),
|
||||
Season season => _files.Combine(_files.GetExtraDirectory(season), $"season-{season.SeasonNumber}.jpg"),
|
||||
People people => _files.Combine(_options.CurrentValue.PeoplePath, $"{people.Slug}.jpg"),
|
||||
_ => throw new NotSupportedException($"The type {typeof(T).Name} does not have a poster.")
|
||||
});
|
||||
}
|
||||
|
||||
public Task<string> GetShowLogo(Show show)
|
||||
/// <inheritdoc />
|
||||
public Task<string> GetThumbnail<T>(T item)
|
||||
where T : IResource
|
||||
{
|
||||
if (show?.Path == null)
|
||||
throw new ArgumentNullException(nameof(show));
|
||||
return Task.FromResult(Path.Combine(_files.GetExtraDirectory(show), "logo.png"));
|
||||
if (item == null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
return item switch
|
||||
{
|
||||
Show show => Task.FromResult(_files.Combine(_files.GetExtraDirectory(show), "backdrop.jpg")),
|
||||
Episode episode => GetEpisodeThumb(episode),
|
||||
_ => throw new NotSupportedException($"The type {typeof(T).Name} does not have a thumbnail.")
|
||||
};
|
||||
}
|
||||
|
||||
public Task<string> GetShowPoster(Show show)
|
||||
private async Task<string> GetEpisodeThumb(Episode episode)
|
||||
{
|
||||
if (show?.Path == null)
|
||||
throw new ArgumentNullException(nameof(show));
|
||||
return Task.FromResult(Path.Combine(_files.GetExtraDirectory(show), "poster.jpg"));
|
||||
string dir = _files.Combine(_files.GetExtraDirectory(episode), "Thumbnails");
|
||||
await _files.CreateDirectory(dir);
|
||||
return _files.Combine(dir, $"{Path.GetFileNameWithoutExtension(episode.Path)}.jpg");
|
||||
}
|
||||
|
||||
public Task<string> GetSeasonPoster(Season season)
|
||||
/// <inheritdoc />
|
||||
public Task<string> GetLogo<T>(T item)
|
||||
where T : IResource
|
||||
{
|
||||
if (season == null)
|
||||
throw new ArgumentNullException(nameof(season));
|
||||
return Task.FromResult(Path.Combine(_files.GetExtraDirectory(season), $"season-{season.SeasonNumber}.jpg"));
|
||||
}
|
||||
|
||||
public Task<string> GetEpisodeThumb(Episode episode)
|
||||
{
|
||||
string dir = Path.Combine(_files.GetExtraDirectory(episode), "Thumbnails");
|
||||
Directory.CreateDirectory(dir);
|
||||
return Task.FromResult(Path.Combine(dir, $"{Path.GetFileNameWithoutExtension(episode.Path)}.jpg"));
|
||||
}
|
||||
|
||||
public Task<string> GetPeoplePoster(People people)
|
||||
{
|
||||
if (people == null)
|
||||
throw new ArgumentNullException(nameof(people));
|
||||
string peoplePath = _options.CurrentValue.PeoplePath;
|
||||
string thumbPath = Path.GetFullPath(Path.Combine(peoplePath, $"{people.Slug}.jpg"));
|
||||
return Task.FromResult(thumbPath.StartsWith(peoplePath) ? thumbPath : null);
|
||||
}
|
||||
|
||||
public Task<string> GetProviderLogo(Provider provider)
|
||||
{
|
||||
if (provider == null)
|
||||
throw new ArgumentNullException(nameof(provider));
|
||||
string providerPath = _options.CurrentValue.ProviderPath;
|
||||
string thumbPath = Path.GetFullPath(Path.Combine(providerPath, $"{provider.Slug}.{provider.LogoExtension}"));
|
||||
return Task.FromResult(thumbPath.StartsWith(providerPath) ? thumbPath : null);
|
||||
if (item == null)
|
||||
throw new ArgumentNullException(nameof(item));
|
||||
return Task.FromResult(item switch
|
||||
{
|
||||
Show show => _files.Combine(_files.GetExtraDirectory(show), "logo.png"),
|
||||
Provider provider => _files.Combine(_options.CurrentValue.ProviderPath,
|
||||
$"{provider.Slug}.{provider.LogoExtension}"),
|
||||
_ => throw new NotSupportedException($"The type {typeof(T).Name} does not have a thumbnail.")
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,10 @@ namespace Kyoo.Tasks
|
||||
/// </summary>
|
||||
[Injected] public AProviderComposite MetadataProvider { private get; set; }
|
||||
/// <summary>
|
||||
/// The thumbnail manager used to download images.
|
||||
/// </summary>
|
||||
[Injected] public IThumbnailsManager ThumbnailsManager { private get; set; }
|
||||
/// <summary>
|
||||
/// The logger used to inform the current status to the console.
|
||||
/// </summary>
|
||||
[Injected] public ILogger<RegisterEpisode> Logger { private get; set; }
|
||||
@ -74,8 +78,10 @@ namespace Kyoo.Tasks
|
||||
if (library != null)
|
||||
MetadataProvider.UseProviders(library.Providers);
|
||||
|
||||
collection = await _RegisterAndFillCollection(collection);
|
||||
// show = await _RegisterAndFillShow(show);
|
||||
if (collection != null)
|
||||
collection.Slug ??= Utility.ToSlug(collection.Name);
|
||||
collection = await _RegisterAndFill(collection);
|
||||
show = await _RegisterAndFill(show);
|
||||
// if (isMovie)
|
||||
// await libraryManager!.Create(await GetMovie(show, path));
|
||||
// else
|
||||
@ -106,22 +112,62 @@ namespace Kyoo.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Collection> _RegisterAndFillCollection(Collection collection)
|
||||
private async Task<T> _RegisterAndFill<T>(T item)
|
||||
where T : class, IResource
|
||||
{
|
||||
if (collection == null)
|
||||
if (item == null || string.IsNullOrEmpty(item.Slug))
|
||||
return null;
|
||||
|
||||
collection.Slug ??= Utility.ToSlug(collection.Name);
|
||||
if (string.IsNullOrEmpty(collection.Slug))
|
||||
return null;
|
||||
|
||||
Collection existing = await LibraryManager.GetOrDefault<Collection>(collection.Slug);
|
||||
|
||||
T existing = await LibraryManager.GetOrDefault<T>(item.Slug);
|
||||
if (existing != null)
|
||||
return existing;
|
||||
collection = await MetadataProvider.Get(collection);
|
||||
return await LibraryManager.CreateIfNotExists(collection);
|
||||
item = await MetadataProvider.Get(item);
|
||||
await ThumbnailsManager.DownloadImages(item);
|
||||
return await LibraryManager.CreateIfNotExists(item);
|
||||
}
|
||||
|
||||
// private async Task<Show> GetShow(ILibraryManager libraryManager,
|
||||
// string showTitle,
|
||||
// string showPath,
|
||||
// bool isMovie,
|
||||
// Library library)
|
||||
// {
|
||||
// Show old = await libraryManager.GetOrDefault<Show>(x => x.Path == showPath);
|
||||
// if (old != null)
|
||||
// {
|
||||
// await libraryManager.Load(old, x => x.ExternalIDs);
|
||||
// return old;
|
||||
// }
|
||||
//
|
||||
// Show show = await MetadataProvider.SearchShow(showTitle, isMovie, library);
|
||||
// show.Path = showPath;
|
||||
// show.People = await MetadataProvider.GetPeople(show, library);
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// show = await libraryManager.Create(show);
|
||||
// }
|
||||
// catch (DuplicatedItemException)
|
||||
// {
|
||||
// old = await libraryManager.GetOrDefault<Show>(show.Slug);
|
||||
// if (old != null && old.Path == showPath)
|
||||
// {
|
||||
// await libraryManager.Load(old, x => x.ExternalIDs);
|
||||
// return old;
|
||||
// }
|
||||
//
|
||||
// if (show.StartAir != null)
|
||||
// {
|
||||
// show.Slug += $"-{show.StartAir.Value.Year}";
|
||||
// await libraryManager.Create(show);
|
||||
// }
|
||||
// else
|
||||
// throw;
|
||||
// }
|
||||
// await ThumbnailsManager.Validate(show);
|
||||
// return show;
|
||||
// }
|
||||
//
|
||||
/*
|
||||
*
|
||||
private async Task RegisterExternalSubtitle(string path, CancellationToken token)
|
||||
@ -170,56 +216,6 @@ namespace Kyoo.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RegisterFile(string path, string relativePath, Library library, CancellationToken token)
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async Task<Show> GetShow(ILibraryManager libraryManager,
|
||||
string showTitle,
|
||||
string showPath,
|
||||
bool isMovie,
|
||||
Library library)
|
||||
{
|
||||
Show old = await libraryManager.GetOrDefault<Show>(x => x.Path == showPath);
|
||||
if (old != null)
|
||||
{
|
||||
await libraryManager.Load(old, x => x.ExternalIDs);
|
||||
return old;
|
||||
}
|
||||
|
||||
Show show = new();//await MetadataProvider.SearchShow(showTitle, isMovie, library);
|
||||
show.Path = showPath;
|
||||
// show.People = await MetadataProvider.GetPeople(show, library);
|
||||
|
||||
try
|
||||
{
|
||||
show = await libraryManager.Create(show);
|
||||
}
|
||||
catch (DuplicatedItemException)
|
||||
{
|
||||
old = await libraryManager.GetOrDefault<Show>(show.Slug);
|
||||
if (old != null && old.Path == showPath)
|
||||
{
|
||||
await libraryManager.Load(old, x => x.ExternalIDs);
|
||||
return old;
|
||||
}
|
||||
|
||||
if (show.StartAir != null)
|
||||
{
|
||||
show.Slug += $"-{show.StartAir.Value.Year}";
|
||||
await libraryManager.Create(show);
|
||||
}
|
||||
else
|
||||
throw;
|
||||
}
|
||||
await ThumbnailsManager.Validate(show);
|
||||
return show;
|
||||
}
|
||||
|
||||
private async Task<Season> GetSeason(ILibraryManager libraryManager,
|
||||
Show show,
|
||||
int seasonNumber,
|
||||
|
@ -188,13 +188,14 @@ namespace Kyoo.Api
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}/thumb")]
|
||||
[HttpGet("{id:int}/thumbnail")]
|
||||
[HttpGet("{id:int}/backdrop")]
|
||||
public async Task<IActionResult> GetThumb(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
Episode episode = await _libraryManager.Get<Episode>(id);
|
||||
return _files.FileResult(await _thumbnails.GetEpisodeThumb(episode));
|
||||
return _files.FileResult(await _thumbnails.GetThumbnail(episode));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
@ -202,13 +203,14 @@ namespace Kyoo.Api
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/thumb")]
|
||||
[HttpGet("{slug}/thumbnail")]
|
||||
[HttpGet("{slug}/backdrop")]
|
||||
public async Task<IActionResult> GetThumb(string slug)
|
||||
{
|
||||
try
|
||||
{
|
||||
Episode episode = await _libraryManager.Get<Episode>(slug);
|
||||
return _files.FileResult(await _thumbnails.GetEpisodeThumb(episode));
|
||||
return _files.FileResult(await _thumbnails.GetThumbnail(episode));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ namespace Kyoo.Api
|
||||
People people = await _libraryManager.GetOrDefault<People>(id);
|
||||
if (people == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbs.GetPeoplePoster(people));
|
||||
return _files.FileResult(await _thumbs.GetPoster(people));
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/poster")]
|
||||
@ -103,7 +103,7 @@ namespace Kyoo.Api
|
||||
People people = await _libraryManager.GetOrDefault<People>(slug);
|
||||
if (people == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbs.GetPeoplePoster(people));
|
||||
return _files.FileResult(await _thumbs.GetPoster(people));
|
||||
}
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ namespace Kyoo.Api
|
||||
Provider provider = await _libraryManager.GetOrDefault<Provider>(id);
|
||||
if (provider == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbnails.GetProviderLogo(provider));
|
||||
return _files.FileResult(await _thumbnails.GetLogo(provider));
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/logo")]
|
||||
@ -45,7 +45,7 @@ namespace Kyoo.Api
|
||||
Provider provider = await _libraryManager.GetOrDefault<Provider>(slug);
|
||||
if (provider == null)
|
||||
return NotFound();
|
||||
return _files.FileResult(await _thumbnails.GetProviderLogo(provider));
|
||||
return _files.FileResult(await _thumbnails.GetLogo(provider));
|
||||
}
|
||||
}
|
||||
}
|
@ -144,24 +144,24 @@ namespace Kyoo.Api
|
||||
return ret;
|
||||
}
|
||||
|
||||
[HttpGet("{id:int}/thumb")]
|
||||
public async Task<IActionResult> GetThumb(int id)
|
||||
[HttpGet("{id:int}/poster")]
|
||||
public async Task<IActionResult> GetPoster(int id)
|
||||
{
|
||||
Season season = await _libraryManager.GetOrDefault<Season>(id);
|
||||
if (season == null)
|
||||
return NotFound();
|
||||
await _libraryManager.Load(season, x => x.Show);
|
||||
return _files.FileResult(await _thumbs.GetSeasonPoster(season));
|
||||
return _files.FileResult(await _thumbs.GetPoster(season));
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/thumb")]
|
||||
public async Task<IActionResult> GetThumb(string slug)
|
||||
[HttpGet("{slug}/poster")]
|
||||
public async Task<IActionResult> GetPoster(string slug)
|
||||
{
|
||||
Season season = await _libraryManager.GetOrDefault<Season>(slug);
|
||||
if (season == null)
|
||||
return NotFound();
|
||||
await _libraryManager.Load(season, x => x.Show);
|
||||
return _files.FileResult(await _thumbs.GetSeasonPoster(season));
|
||||
return _files.FileResult(await _thumbs.GetPoster(season));
|
||||
}
|
||||
}
|
||||
}
|
@ -417,7 +417,7 @@ namespace Kyoo.Api
|
||||
try
|
||||
{
|
||||
Show show = await _libraryManager.Get<Show>(slug);
|
||||
return _files.FileResult(await _thumbs.GetShowPoster(show));
|
||||
return _files.FileResult(await _thumbs.GetPoster(show));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
@ -431,7 +431,7 @@ namespace Kyoo.Api
|
||||
try
|
||||
{
|
||||
Show show = await _libraryManager.Get<Show>(slug);
|
||||
return _files.FileResult(await _thumbs.GetShowLogo(show));
|
||||
return _files.FileResult(await _thumbs.GetLogo(show));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
@ -440,12 +440,13 @@ namespace Kyoo.Api
|
||||
}
|
||||
|
||||
[HttpGet("{slug}/backdrop")]
|
||||
[HttpGet("{slug}/thumbnail")]
|
||||
public async Task<IActionResult> GetBackdrop(string slug)
|
||||
{
|
||||
try
|
||||
{
|
||||
Show show = await _libraryManager.Get<Show>(slug);
|
||||
return _files.FileResult(await _thumbs.GetShowBackdrop(show));
|
||||
return _files.FileResult(await _thumbs.GetThumbnail(show));
|
||||
}
|
||||
catch (ItemNotFoundException)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user