mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Fixing subtitle re-extraction
This commit is contained in:
parent
d2a38c9b3d
commit
b84baae99a
@ -304,6 +304,14 @@ namespace Kyoo
|
||||
action(i);
|
||||
}
|
||||
|
||||
public static void ForEach([CanBeNull] this IEnumerable self, Action<object> action)
|
||||
{
|
||||
if (self == null)
|
||||
return;
|
||||
foreach (object i in self)
|
||||
action(i);
|
||||
}
|
||||
|
||||
public static async Task ForEachAsync<T>([CanBeNull] this IEnumerable<T> self, Func<T, Task> action)
|
||||
{
|
||||
if (self == null)
|
||||
@ -319,6 +327,14 @@ namespace Kyoo
|
||||
await foreach (T i in self)
|
||||
action(i);
|
||||
}
|
||||
|
||||
public static async Task ForEachAsync([CanBeNull] this IEnumerable self, Func<object, Task> action)
|
||||
{
|
||||
if (self == null)
|
||||
return;
|
||||
foreach (object i in self)
|
||||
await action(i);
|
||||
}
|
||||
|
||||
private static MethodInfo GetMethod(Type type, BindingFlags flag, string name, Type[] generics, object[] args)
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.CommonApi;
|
||||
using Kyoo.Models;
|
||||
using Kyoo.Models.Attributes;
|
||||
@ -119,7 +118,7 @@ namespace Kyoo.Controllers
|
||||
return query.CountAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<T> Create([NotNull] T obj)
|
||||
public virtual async Task<T> Create(T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
@ -169,6 +168,26 @@ namespace Kyoo.Controllers
|
||||
if (old == null)
|
||||
throw new ItemNotFound($"No resource found with the ID {edited.ID}.");
|
||||
|
||||
// foreach (PropertyInfo navigation in typeof(T).GetProperties()
|
||||
// .Where(x => x.GetCustomAttribute<LoadableRelationAttribute>() != null))
|
||||
// {
|
||||
// if (navigation.GetCustomAttribute<EditableRelationAttribute>() == null)
|
||||
// {
|
||||
// navigation.SetValue(edited, default);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (resetOld || navigation.GetValue(edited) != default)
|
||||
// {
|
||||
// // TODO only works for X To One and not X to Many
|
||||
// await _library.Value.Load(old, navigation.Name);
|
||||
// object value = navigation.GetValue(old);
|
||||
// if (value is IEnumerable list) // TODO handle externalIds & PeopleRoles
|
||||
// list.ForEach(x => _library.Value.Delete(x));
|
||||
// else if (value is IResource resource)
|
||||
// _library.Value.Delete(resource);
|
||||
// }
|
||||
// }
|
||||
foreach (NavigationEntry navigation in Database.Entry(old).Navigations)
|
||||
{
|
||||
if (navigation.Metadata.PropertyInfo.GetCustomAttribute<EditableRelationAttribute>() != null)
|
||||
|
@ -166,13 +166,12 @@ namespace Kyoo.Controllers
|
||||
|
||||
await base.Validate(resource);
|
||||
|
||||
if (resource.Tracks != null)
|
||||
{
|
||||
// TODO remove old values
|
||||
resource.Tracks = await resource.Tracks
|
||||
.SelectAsync(x => _tracks.CreateIfNotExists(x, true))
|
||||
.ToListAsync();
|
||||
}
|
||||
// if (resource.Tracks != null)
|
||||
// {
|
||||
// resource.Tracks = await resource.Tracks
|
||||
// .SelectAsync(x => _tracks.CreateIfNotExists(x, true))
|
||||
// .ToListAsync();
|
||||
// }
|
||||
|
||||
if (resource.ExternalIDs != null)
|
||||
{
|
||||
@ -194,7 +193,7 @@ namespace Kyoo.Controllers
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
await obj.Tracks.ForEachAsync(x => _tracks.CreateIfNotExists(x, true));
|
||||
// await obj.Tracks.ForEachAsync(x => _tracks.CreateIfNotExists(x, true));
|
||||
if (obj.ExternalIDs != null)
|
||||
foreach (MetadataID entry in obj.ExternalIDs)
|
||||
_database.Entry(entry).State = EntityState.Deleted;
|
||||
|
@ -100,9 +100,11 @@ namespace Kyoo.Tasks
|
||||
await _thumbnails!.Validate(episode, true);
|
||||
if (subs)
|
||||
{
|
||||
// TODO handle external subtites.
|
||||
await _library.Load(episode, x => x.Tracks);
|
||||
episode.Tracks = (await _transcoder!.ExtractInfos(episode.Path))
|
||||
.Where(x => x.Type != StreamType.Font).ToArray();
|
||||
.Where(x => x.Type != StreamType.Font)
|
||||
.Concat(episode.Tracks.Where(x => x.IsExternal))
|
||||
.ToList();
|
||||
await _library.EditEpisode(episode, false);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user