mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 12:14:46 -04:00
Reworking the common to support identifiy
This commit is contained in:
parent
e7eea1e5f8
commit
f6a418ca26
@ -8,18 +8,14 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
//For the collection
|
|
||||||
Task<Collection> GetCollectionFromName(string name);
|
Task<Collection> GetCollectionFromName(string name);
|
||||||
|
|
||||||
//For the show
|
|
||||||
Task<Show> GetShowByID(Show show);
|
Task<Show> GetShowByID(Show show);
|
||||||
Task<Show> GetShowFromName(string showName, bool isMovie);
|
Task<IEnumerable<Show>> GetShowsFromName(string showName, bool isMovie);
|
||||||
Task<IEnumerable<PeopleLink>> GetPeople(Show show);
|
Task<IEnumerable<PeopleLink>> GetPeople(Show show);
|
||||||
|
|
||||||
//For the seasons
|
|
||||||
Task<Season> GetSeason(Show show, long seasonNumber);
|
Task<Season> GetSeason(Show show, long seasonNumber);
|
||||||
|
|
||||||
//For the episodes
|
|
||||||
Task<Episode> GetEpisode(Show show, long seasonNumber, long episodeNumber, long absoluteNumber);
|
Task<Episode> GetEpisode(Show show, long seasonNumber, long episodeNumber, long absoluteNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ namespace Kyoo.Controllers
|
|||||||
public interface IProviderManager
|
public interface IProviderManager
|
||||||
{
|
{
|
||||||
Task<Collection> GetCollectionFromName(string name, Library library);
|
Task<Collection> GetCollectionFromName(string name, Library library);
|
||||||
Task<Show> GetShowFromName(string showName, string showPath, bool isMovie, Library library);
|
Task<Show> SearchShow(string showName, bool isMovie, Library library);
|
||||||
|
Task<IEnumerable<Show>> SearchShows(string showName, bool isMovie, Library library);
|
||||||
Task<Season> GetSeason(Show show, long seasonNumber, Library library);
|
Task<Season> GetSeason(Show show, long seasonNumber, Library library);
|
||||||
Task<Episode> GetEpisode(Show show, string episodePath, long seasonNumber, long episodeNumber, long absoluteNumber, Library library);
|
Task<Episode> GetEpisode(Show show, string episodePath, long seasonNumber, long episodeNumber, long absoluteNumber, Library library);
|
||||||
Task<IEnumerable<PeopleLink>> GetPeople(Show show, Library library);
|
Task<IEnumerable<PeopleLink>> GetPeople(Show show, Library library);
|
||||||
|
@ -7,7 +7,7 @@ namespace Kyoo.Controllers
|
|||||||
public interface IThumbnailsManager
|
public interface IThumbnailsManager
|
||||||
{
|
{
|
||||||
Task<Show> Validate(Show show);
|
Task<Show> Validate(Show show);
|
||||||
Task<IEnumerable<PeopleLink>> Validate(List<PeopleLink> actors);
|
Task<IEnumerable<PeopleLink>> Validate(IEnumerable<PeopleLink> actors);
|
||||||
Task<Episode> Validate(Episode episode);
|
Task<Episode> Validate(Episode episode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
<Company>SDG</Company>
|
<Company>SDG</Company>
|
||||||
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
|
<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression>
|
||||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||||
<PackageVersion>1.0.13</PackageVersion>
|
<PackageVersion>1.0.14</PackageVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -9,15 +9,14 @@ namespace Kyoo.Controllers
|
|||||||
public class ProviderManager : IProviderManager
|
public class ProviderManager : IProviderManager
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<IMetadataProvider> _providers;
|
private readonly IEnumerable<IMetadataProvider> _providers;
|
||||||
private readonly IThumbnailsManager _thumbnailsManager;
|
|
||||||
|
|
||||||
public ProviderManager(IThumbnailsManager thumbnailsManager, IPluginManager pluginManager)
|
public ProviderManager(IPluginManager pluginManager)
|
||||||
{
|
{
|
||||||
_thumbnailsManager = thumbnailsManager;
|
|
||||||
_providers = pluginManager.GetPlugins<IMetadataProvider>();
|
_providers = pluginManager.GetPlugins<IMetadataProvider>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<T> GetMetadata<T>(Func<IMetadataProvider, Task<T>> providerCall, Library library, string what) where T : IMergable<T>, new()
|
private async Task<T> GetMetadata<T>(Func<IMetadataProvider, Task<T>> providerCall, Library library, string what)
|
||||||
|
where T : IMergable<T>, new()
|
||||||
{
|
{
|
||||||
T ret = new T();
|
T ret = new T();
|
||||||
|
|
||||||
@ -36,8 +35,8 @@ namespace Kyoo.Controllers
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<T>> GetMetadata<T>(Func<IMetadataProvider, Task<IEnumerable<T>>> providerCall, Library library, string what)
|
private async Task<IEnumerable<T>> GetMetadata<T>(Func<IMetadataProvider, Task<IEnumerable<T>>> providerCall, Library library, string what)
|
||||||
{
|
{
|
||||||
List<T> ret = new List<T>();
|
List<T> ret = new List<T>();
|
||||||
|
|
||||||
@ -65,16 +64,26 @@ namespace Kyoo.Controllers
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Show> GetShowFromName(string showName, string showPath, bool isMovie, Library library)
|
public async Task<Show> SearchShow(string showName, bool isMovie, Library library)
|
||||||
{
|
{
|
||||||
Show show = await GetMetadata(provider => provider.GetShowFromName(showName, isMovie), library, $"the show {showName}");
|
Show show = await GetMetadata(async provider => (await provider.GetShowsFromName(showName, isMovie))?.FirstOrDefault(), library, $"the show {showName}");
|
||||||
show.Path = showPath;
|
|
||||||
show.Slug = Utility.ToSlug(showName);
|
show.Slug = Utility.ToSlug(showName);
|
||||||
show.Title ??= showName;
|
show.Title ??= showName;
|
||||||
show.IsMovie = isMovie;
|
show.IsMovie = isMovie;
|
||||||
await _thumbnailsManager.Validate(show);
|
|
||||||
return show;
|
return show;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Show>> SearchShows(string showName, bool isMovie, Library library)
|
||||||
|
{
|
||||||
|
IEnumerable<Show> shows = await GetMetadata(provider => provider.GetShowsFromName(showName, isMovie), library, $"the show {showName}");
|
||||||
|
return shows.Select(show =>
|
||||||
|
{
|
||||||
|
show.Slug = Utility.ToSlug(showName);
|
||||||
|
show.Title ??= showName;
|
||||||
|
show.IsMovie = isMovie;
|
||||||
|
return show;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Season> GetSeason(Show show, long seasonNumber, Library library)
|
public async Task<Season> GetSeason(Show show, long seasonNumber, Library library)
|
||||||
{
|
{
|
||||||
@ -93,14 +102,12 @@ namespace Kyoo.Controllers
|
|||||||
episode.SeasonNumber = episode.SeasonNumber != -1 ? episode.SeasonNumber : seasonNumber;
|
episode.SeasonNumber = episode.SeasonNumber != -1 ? episode.SeasonNumber : seasonNumber;
|
||||||
episode.EpisodeNumber = episode.EpisodeNumber != -1 ? episode.EpisodeNumber : episodeNumber;
|
episode.EpisodeNumber = episode.EpisodeNumber != -1 ? episode.EpisodeNumber : episodeNumber;
|
||||||
episode.AbsoluteNumber = episode.AbsoluteNumber != -1 ? episode.AbsoluteNumber : absoluteNumber;
|
episode.AbsoluteNumber = episode.AbsoluteNumber != -1 ? episode.AbsoluteNumber : absoluteNumber;
|
||||||
await _thumbnailsManager.Validate(episode);
|
|
||||||
return episode;
|
return episode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<PeopleLink>> GetPeople(Show show, Library library)
|
public async Task<IEnumerable<PeopleLink>> GetPeople(Show show, Library library)
|
||||||
{
|
{
|
||||||
IEnumerable<PeopleLink> people = await GetMetadata(provider => provider.GetPeople(show), library, $"a cast member of {show.Title}");
|
IEnumerable<PeopleLink> people = await GetMetadata(provider => provider.GetPeople(show), library, $"a cast member of {show.Title}");
|
||||||
people = await _thumbnailsManager.Validate(people.ToList());
|
|
||||||
return people;
|
return people;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ namespace Kyoo.Controllers
|
|||||||
return show;
|
return show;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<PeopleLink>> Validate(List<PeopleLink> people)
|
public async Task<IEnumerable<PeopleLink>> Validate(IEnumerable<PeopleLink> people)
|
||||||
{
|
{
|
||||||
if (people == null)
|
if (people == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,6 +22,7 @@ namespace Kyoo.Controllers
|
|||||||
public int Priority => 0;
|
public int Priority => 0;
|
||||||
|
|
||||||
private ILibraryManager _libraryManager;
|
private ILibraryManager _libraryManager;
|
||||||
|
private IThumbnailsManager _thumbnailsManager;
|
||||||
private IProviderManager _metadataProvider;
|
private IProviderManager _metadataProvider;
|
||||||
private ITranscoder _transcoder;
|
private ITranscoder _transcoder;
|
||||||
private IConfiguration _config;
|
private IConfiguration _config;
|
||||||
@ -41,6 +42,7 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
using IServiceScope serviceScope = serviceProvider.CreateScope();
|
using IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||||
_libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
_libraryManager = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
||||||
|
_thumbnailsManager = serviceScope.ServiceProvider.GetService<IThumbnailsManager>();
|
||||||
_metadataProvider = serviceScope.ServiceProvider.GetService<IProviderManager>();
|
_metadataProvider = serviceScope.ServiceProvider.GetService<IProviderManager>();
|
||||||
_transcoder = serviceScope.ServiceProvider.GetService<ITranscoder>();
|
_transcoder = serviceScope.ServiceProvider.GetService<ITranscoder>();
|
||||||
_config = serviceScope.ServiceProvider.GetService<IConfiguration>();
|
_config = serviceScope.ServiceProvider.GetService<IConfiguration>();
|
||||||
@ -129,18 +131,21 @@ namespace Kyoo.Controllers
|
|||||||
Show show = _libraryManager.GetShow(showPath);
|
Show show = _libraryManager.GetShow(showPath);
|
||||||
if (show != null)
|
if (show != null)
|
||||||
return show;
|
return show;
|
||||||
show = await _metadataProvider.GetShowFromName(showTitle, showPath, isMovie, library);
|
show = await _metadataProvider.SearchShow(showTitle, isMovie, library);
|
||||||
|
show.Path = showPath;
|
||||||
show.People = (await _metadataProvider.GetPeople(show, library)).GroupBy(x => x.Slug).Select(x => x.First())
|
show.People = (await _metadataProvider.GetPeople(show, library)).GroupBy(x => x.Slug).Select(x => x.First())
|
||||||
.Select(x =>
|
.Select(x =>
|
||||||
{
|
{
|
||||||
People existing = _libraryManager.GetPeopleBySlug(x.Slug);
|
People existing = _libraryManager.GetPeopleBySlug(x.Slug);
|
||||||
return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x;
|
return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
show.People = await _thumbnailsManager.Validate(show.People);
|
||||||
show.Genres = show.Genres.Select(x =>
|
show.Genres = show.Genres.Select(x =>
|
||||||
{
|
{
|
||||||
Genre existing = _libraryManager.GetGenreBySlug(x.Slug);
|
Genre existing = _libraryManager.GetGenreBySlug(x.Slug);
|
||||||
return existing ?? x;
|
return existing ?? x;
|
||||||
});
|
});
|
||||||
|
await _thumbnailsManager.Validate(show);
|
||||||
return show;
|
return show;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +171,8 @@ namespace Kyoo.Controllers
|
|||||||
Console.Error.WriteLine("\tError: You don't have any provider that support absolute epiode numbering. Install one and try again.");
|
Console.Error.WriteLine("\tError: You don't have any provider that support absolute epiode numbering. Install one and try again.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _thumbnailsManager.Validate(episode);
|
||||||
await GetTracks(episode);
|
await GetTracks(episode);
|
||||||
return episode;
|
return episode;
|
||||||
}
|
}
|
||||||
@ -193,16 +199,19 @@ namespace Kyoo.Controllers
|
|||||||
|
|
||||||
private static IEnumerable<Track> GetExtractedSubtitles(Episode episode)
|
private static IEnumerable<Track> GetExtractedSubtitles(Episode episode)
|
||||||
{
|
{
|
||||||
string path = Path.Combine(Path.GetDirectoryName(episode.Path), "Subtitles");
|
|
||||||
List<Track> tracks = new List<Track>();
|
List<Track> tracks = new List<Track>();
|
||||||
|
|
||||||
|
if (episode.Path == null)
|
||||||
|
return tracks;
|
||||||
|
string path = Path.Combine(Path.GetDirectoryName(episode.Path)!, "Subtitles");
|
||||||
|
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
return tracks;
|
return tracks;
|
||||||
foreach (string sub in Directory.EnumerateFiles(path, "", SearchOption.AllDirectories))
|
foreach (string sub in Directory.EnumerateFiles(path, "", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
string episodeLink = Path.GetFileNameWithoutExtension(episode.Path);
|
string episodeLink = Path.GetFileNameWithoutExtension(episode.Path);
|
||||||
|
|
||||||
if (!sub.Contains(episodeLink))
|
if (!sub.Contains(episodeLink!))
|
||||||
continue;
|
continue;
|
||||||
string language = sub.Substring(Path.GetDirectoryName(sub).Length + episodeLink.Length + 2, 3);
|
string language = sub.Substring(Path.GetDirectoryName(sub).Length + episodeLink.Length + 2, 3);
|
||||||
bool isDefault = sub.Contains("default");
|
bool isDefault = sub.Contains("default");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models.Exceptions;
|
using Kyoo.Models.Exceptions;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
@ -10,13 +11,15 @@ namespace Kyoo.Api
|
|||||||
[Route("api/shows")]
|
[Route("api/shows")]
|
||||||
[Route("api/show")]
|
[Route("api/show")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class ShowsController : ControllerBase
|
public class ShowsAPI : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
private readonly IProviderManager _providerManager;
|
||||||
|
|
||||||
public ShowsController(ILibraryManager libraryManager)
|
public ShowsAPI(ILibraryManager libraryManager, IProviderManager providerManager)
|
||||||
{
|
{
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
|
_providerManager = providerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -57,5 +60,12 @@ namespace Kyoo.Api
|
|||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("identify/{name}")]
|
||||||
|
[Authorize(Policy = "Read")]
|
||||||
|
public async Task<IEnumerable<Show>> IdentityShow(string name, [FromQuery] bool isMovie)
|
||||||
|
{
|
||||||
|
return await _providerManager.SearchShows(name, isMovie, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 16ebfac8ba9ea07715de8a3d1b99e0242db9518f
|
Subproject commit b77c04fa6e129bc8cf4f22489064509e02846071
|
Loading…
x
Reference in New Issue
Block a user