mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-06 23:24:14 -04:00
Adding a rescan for shows, seasons & episodes
This commit is contained in:
parent
8aae1c9bd6
commit
be2d3e324f
@ -40,7 +40,9 @@ namespace Kyoo.Controllers
|
|||||||
Task<Library> GetLibrary(string slug);
|
Task<Library> GetLibrary(string slug);
|
||||||
Task<Collection> GetCollection(string slug);
|
Task<Collection> GetCollection(string slug);
|
||||||
Task<Show> GetShow(string slug);
|
Task<Show> GetShow(string slug);
|
||||||
|
Task<Season> GetSeason(string slug);
|
||||||
Task<Season> GetSeason(string showSlug, int seasonNumber);
|
Task<Season> GetSeason(string showSlug, int seasonNumber);
|
||||||
|
Task<Episode> GetEpisode(string slug);
|
||||||
Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber);
|
Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber);
|
||||||
Task<Episode> GetMovieEpisode(string movieSlug);
|
Task<Episode> GetMovieEpisode(string movieSlug);
|
||||||
Task<Track> GetTrack(string slug, StreamType type = StreamType.Unknown);
|
Task<Track> GetTrack(string slug, StreamType type = StreamType.Unknown);
|
||||||
|
@ -145,11 +145,21 @@ namespace Kyoo.Controllers
|
|||||||
return ShowRepository.Get(slug);
|
return ShowRepository.Get(slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Season> GetSeason(string slug)
|
||||||
|
{
|
||||||
|
return SeasonRepository.Get(slug);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<Season> GetSeason(string showSlug, int seasonNumber)
|
public Task<Season> GetSeason(string showSlug, int seasonNumber)
|
||||||
{
|
{
|
||||||
return SeasonRepository.Get(showSlug, seasonNumber);
|
return SeasonRepository.Get(showSlug, seasonNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Task<Episode> GetEpisode(string slug)
|
||||||
|
{
|
||||||
|
return EpisodeRepository.Get(slug);
|
||||||
|
}
|
||||||
|
|
||||||
public Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber)
|
public Task<Episode> GetEpisode(string showSlug, int seasonNumber, int episodeNumber)
|
||||||
{
|
{
|
||||||
return EpisodeRepository.Get(showSlug, seasonNumber, episodeNumber);
|
return EpisodeRepository.Get(showSlug, seasonNumber, episodeNumber);
|
||||||
|
@ -21,12 +21,12 @@ namespace Kyoo.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using WebClient client = new WebClient();
|
using WebClient client = new();
|
||||||
await client.DownloadFileTaskAsync(new Uri(url), localPath);
|
await client.DownloadFileTaskAsync(new Uri(url), localPath);
|
||||||
}
|
}
|
||||||
catch (WebException exception)
|
catch (WebException exception)
|
||||||
{
|
{
|
||||||
await Console.Error.WriteLineAsync($"\t{what} could not be downloaded.\n\tError: {exception.Message}.");
|
await Console.Error.WriteLineAsync($"{what} could not be downloaded.\n\tError: {exception.Message}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,9 @@ namespace Kyoo.Tasks
|
|||||||
new CreateDatabase(),
|
new CreateDatabase(),
|
||||||
new PluginLoader(),
|
new PluginLoader(),
|
||||||
new Crawler(),
|
new Crawler(),
|
||||||
new MetadataLoader(),
|
new MetadataProviderLoader(),
|
||||||
new ReScan()
|
new ReScan(),
|
||||||
|
new ExtractMetadata()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
119
Kyoo/Tasks/ExtractMetadata.cs
Normal file
119
Kyoo/Tasks/ExtractMetadata.cs
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Kyoo.Tasks
|
||||||
|
{
|
||||||
|
public class ExtractMetadata : ITask
|
||||||
|
{
|
||||||
|
public string Slug => "extract";
|
||||||
|
public string Name => "Metadata Extractor";
|
||||||
|
public string Description => "Extract subtitles or download thumbnails for a show/episode.";
|
||||||
|
public string HelpMessage => null;
|
||||||
|
public bool RunOnStartup => false;
|
||||||
|
public int Priority => 0;
|
||||||
|
|
||||||
|
|
||||||
|
private ILibraryManager _library;
|
||||||
|
private IThumbnailsManager _thumbnails;
|
||||||
|
private ITranscoder _transcoder;
|
||||||
|
|
||||||
|
public async Task Run(IServiceProvider serviceProvider, CancellationToken token, string arguments = null)
|
||||||
|
{
|
||||||
|
string[] args = arguments?.Split('/');
|
||||||
|
|
||||||
|
if (args == null || args.Length < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
string slug = args[1];
|
||||||
|
bool thumbs = args.Length < 3 || string.Equals(args[2], "thumbnails", StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
bool subs = args.Length < 3 || string.Equals(args[2], "subs", StringComparison.InvariantCultureIgnoreCase);
|
||||||
|
|
||||||
|
using IServiceScope serviceScope = serviceProvider.CreateScope();
|
||||||
|
_library = serviceScope.ServiceProvider.GetService<ILibraryManager>();
|
||||||
|
_thumbnails = serviceScope.ServiceProvider.GetService<IThumbnailsManager>();
|
||||||
|
_transcoder = serviceScope.ServiceProvider.GetService<ITranscoder>();
|
||||||
|
int id;
|
||||||
|
|
||||||
|
switch (args[0].ToLowerInvariant())
|
||||||
|
{
|
||||||
|
case "show":
|
||||||
|
case "shows":
|
||||||
|
Show show = await (int.TryParse(slug, out id)
|
||||||
|
? _library!.GetShow(id)
|
||||||
|
: _library!.GetShow(slug));
|
||||||
|
await ExtractShow(show, thumbs, subs, token);
|
||||||
|
break;
|
||||||
|
case "season":
|
||||||
|
case "seasons":
|
||||||
|
Season season = await (int.TryParse(slug, out id)
|
||||||
|
? _library!.GetSeason(id)
|
||||||
|
: _library!.GetSeason(slug));
|
||||||
|
await ExtractSeason(season, thumbs, subs, token);
|
||||||
|
break;
|
||||||
|
case "episode":
|
||||||
|
case "episodes":
|
||||||
|
Episode episode = await (int.TryParse(slug, out id)
|
||||||
|
? _library!.GetEpisode(id)
|
||||||
|
: _library!.GetEpisode(slug));
|
||||||
|
await ExtractEpisode(episode, thumbs, subs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await _library!.DisposeAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExtractShow(Show show, bool thumbs, bool subs, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (thumbs)
|
||||||
|
await _thumbnails!.Validate(show, true);
|
||||||
|
foreach (Season season in show.Seasons)
|
||||||
|
{
|
||||||
|
if (token.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
await ExtractSeason(season, thumbs, subs, token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExtractSeason(Season season, bool thumbs, bool subs, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (thumbs)
|
||||||
|
await _thumbnails!.Validate(season, true);
|
||||||
|
foreach (Episode episode in season.Episodes)
|
||||||
|
{
|
||||||
|
if (token.IsCancellationRequested)
|
||||||
|
return;
|
||||||
|
await ExtractEpisode(episode, thumbs, subs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task ExtractEpisode(Episode episode, bool thumbs, bool subs)
|
||||||
|
{
|
||||||
|
if (thumbs)
|
||||||
|
await _thumbnails!.Validate(episode, true);
|
||||||
|
if (subs)
|
||||||
|
{
|
||||||
|
// TODO this doesn't work.
|
||||||
|
IEnumerable<Track> tracks = (await _transcoder!.ExtractInfos(episode.Path))
|
||||||
|
.Where(x => x.Type != StreamType.Font);
|
||||||
|
episode.Tracks = tracks;
|
||||||
|
await _library.EditEpisode(episode, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<string>> GetPossibleParameters()
|
||||||
|
{
|
||||||
|
return Task.FromResult<IEnumerable<string>>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int? Progress()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
|
|
||||||
namespace Kyoo.Tasks
|
namespace Kyoo.Tasks
|
||||||
{
|
{
|
||||||
public class MetadataLoader : ITask
|
public class MetadataProviderLoader : ITask
|
||||||
{
|
{
|
||||||
public string Slug => "reload-metdata";
|
public string Slug => "reload-metdata";
|
||||||
public string Name => "Reload Metadata Providers";
|
public string Name => "Reload Metadata Providers";
|
@ -17,6 +17,7 @@ namespace Kyoo.Api
|
|||||||
|
|
||||||
|
|
||||||
[HttpGet("{taskSlug}/{*args}")]
|
[HttpGet("{taskSlug}/{*args}")]
|
||||||
|
[HttpPut("{taskSlug}/{*args}")]
|
||||||
[Authorize(Policy="Admin")]
|
[Authorize(Policy="Admin")]
|
||||||
public IActionResult RunTask(string taskSlug, string args = null)
|
public IActionResult RunTask(string taskSlug, string args = null)
|
||||||
{
|
{
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit ec79821a71ba0db650b850f7c04c5f93abcb68b0
|
Subproject commit 09edd091b9bc75b697da4dc16eeaf9aadb9d4b05
|
Loading…
x
Reference in New Issue
Block a user