diff --git a/Kyoo.Common/Kyoo.Common.csproj b/Kyoo.Common/Kyoo.Common.csproj index 9a1ba82b..c0e22521 100644 --- a/Kyoo.Common/Kyoo.Common.csproj +++ b/Kyoo.Common/Kyoo.Common.csproj @@ -12,7 +12,7 @@ SDG GPL-3.0-or-later true - 1.0.23 + 1.0.24 true snupkg default diff --git a/Kyoo.Common/Utility.cs b/Kyoo.Common/Utility.cs index 0ee0c881..a25d9b4f 100644 --- a/Kyoo.Common/Utility.cs +++ b/Kyoo.Common/Utility.cs @@ -91,18 +91,18 @@ namespace Kyoo } } - public static IEnumerable MergeLists(IEnumerable first, + public static T[] MergeLists(IEnumerable first, IEnumerable second, Func isEqual = null) { if (first == null) - return second; + return second.ToArray(); if (second == null) - return first; + return first.ToArray(); if (isEqual == null) - return first.Concat(second).ToList(); + return first.Concat(second).ToArray(); List list = first.ToList(); - return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y)))); + return list.Concat(second.Where(x => !list.Any(y => isEqual(x, y)))).ToArray(); } public static T Assign(T first, T second) @@ -183,7 +183,7 @@ namespace Kyoo { property.SetValue(first, RunGenericMethod( typeof(Utility), - "MergeLists", + nameof(MergeLists), GetEnumerableType(property.PropertyType), oldValue, newValue, null)); } @@ -384,18 +384,21 @@ namespace Kyoo .IfEmpty(() => throw new NullReferenceException($"A method named {name} with " + $"{args.Length} arguments and {generics.Length} generic " + $"types could not be found on {type.Name}.")) - .Where(x => - { - int i = 0; - return x.GetGenericArguments().All(y => y.IsAssignableFrom(generics[i++])); - }) - .IfEmpty(() => throw new NullReferenceException($"No method {name} match the generics specified.")) - .Where(x => - { - int i = 0; - return x.GetParameters().All(y => y.ParameterType == args[i++].GetType()); - }) - .IfEmpty(() => throw new NullReferenceException($"No method {name} match the parameters's types.")) + // TODO this won't work but I don't know why. + // .Where(x => + // { + // int i = 0; + // return x.GetGenericArguments().All(y => y.IsAssignableFrom(generics[i++])); + // }) + // .IfEmpty(() => throw new NullReferenceException($"No method {name} match the generics specified.")) + + // TODO this won't work for Type because T is specified in arguments but not in the parameters type. + // .Where(x => + // { + // int i = 0; + // return x.GetParameters().All(y => y.ParameterType.IsInstanceOfType(args[i++])); + // }) + // .IfEmpty(() => throw new NullReferenceException($"No method {name} match the parameters's types.")) .Take(2) .ToArray(); diff --git a/Kyoo/Controllers/ThumbnailsManager.cs b/Kyoo/Controllers/ThumbnailsManager.cs index bc91f1af..a9ca9d8b 100644 --- a/Kyoo/Controllers/ThumbnailsManager.cs +++ b/Kyoo/Controllers/ThumbnailsManager.cs @@ -10,14 +10,12 @@ namespace Kyoo.Controllers { public class ThumbnailsManager : IThumbnailsManager { - private readonly IConfiguration _config; private readonly IFileManager _files; private readonly string _peoplePath; private readonly string _providerPath; public ThumbnailsManager(IConfiguration configuration, IFileManager files) { - _config = configuration; _files = files; _peoplePath = Path.GetFullPath(configuration.GetValue("peoplePath")); _providerPath = Path.GetFullPath(configuration.GetValue("providerPath")); @@ -67,10 +65,9 @@ namespace Kyoo.Controllers { if (people == null) throw new ArgumentNullException(nameof(people)); - string root = _config.GetValue("peoplePath"); - string localPath = Path.Combine(root, people.Slug + ".jpg"); - - Directory.CreateDirectory(root); + 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}"); } @@ -100,10 +97,7 @@ namespace Kyoo.Controllers if (provider.Logo == null) return; - string root = _config.GetValue("providerPath"); - string localPath = Path.Combine(root, provider.Slug + ".jpg"); - - Directory.CreateDirectory(root); + string localPath = await GetProviderLogo(provider); if (alwaysDownload || !File.Exists(localPath)) await DownloadImage(provider.Logo, localPath, $"The logo of {provider.Slug}"); } @@ -157,9 +151,7 @@ namespace Kyoo.Controllers { if (provider == null) throw new ArgumentNullException(nameof(provider)); - string thumbPath = Path.GetFullPath(Path.Combine(_providerPath, $"{provider.Slug}.jpg")); - if (!thumbPath.StartsWith(_providerPath)) - return Task.FromResult(null); + string thumbPath = Path.GetFullPath(Path.Combine(_providerPath, $"{provider.Slug}.png")); return Task.FromResult(thumbPath.StartsWith(_providerPath) ? thumbPath : null); } }