mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 10:14:13 -04:00
Fixing tvdb provider and adding fields=all
This commit is contained in:
parent
a4635866a7
commit
4c0179ad4d
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Kyoo.Models.Attributes;
|
||||
|
||||
namespace Kyoo.Models
|
||||
{
|
||||
@ -107,12 +108,12 @@ namespace Kyoo.Models
|
||||
/// <summary>
|
||||
/// A reference of the first resource.
|
||||
/// </summary>
|
||||
public T1 First { get; set; }
|
||||
[SerializeIgnore] public T1 First { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A reference to the second resource.
|
||||
/// </summary>
|
||||
public T2 Second { get; set; }
|
||||
[SerializeIgnore] public T2 Second { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Kyoo.Common.Models.Attributes;
|
||||
using Kyoo.Controllers;
|
||||
using Kyoo.Models.Attributes;
|
||||
@ -157,6 +158,7 @@ namespace Kyoo.Models
|
||||
/// <remarks>This method will never return anything if the <see cref="ExternalIDs"/> are not loaded.</remarks>
|
||||
/// <param name="provider">The slug of the provider</param>
|
||||
/// <returns>The <see cref="MetadataID{T}.DataID"/> field of the asked provider.</returns>
|
||||
[CanBeNull]
|
||||
public string GetID(string provider)
|
||||
{
|
||||
return ExternalIDs?.FirstOrDefault(x => x.Second.Slug == provider)?.DataID;
|
||||
|
@ -43,22 +43,31 @@ namespace Kyoo.CommonApi
|
||||
PropertyInfo[] properties = type.GetProperties()
|
||||
.Where(x => x.GetCustomAttribute<LoadableRelationAttribute>() != null)
|
||||
.ToArray();
|
||||
fields = fields.Select(x =>
|
||||
{
|
||||
string property = properties
|
||||
.FirstOrDefault(y => string.Equals(x, y.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
?.Name;
|
||||
if (property != null)
|
||||
return property;
|
||||
context.Result = new BadRequestObjectResult(new
|
||||
if (fields.Count == 1 && fields.Contains("all"))
|
||||
{
|
||||
fields = properties.Select(x => x.Name).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
fields = fields
|
||||
.Select(x =>
|
||||
{
|
||||
Error = $"{x} does not exist on {type.Name}."
|
||||
});
|
||||
return null;
|
||||
})
|
||||
.ToList();
|
||||
if (context.Result != null)
|
||||
return;
|
||||
string property = properties
|
||||
.FirstOrDefault(y
|
||||
=> string.Equals(x, y.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
?.Name;
|
||||
if (property != null)
|
||||
return property;
|
||||
context.Result = new BadRequestObjectResult(new
|
||||
{
|
||||
Error = $"{x} does not exist on {type.Name}."
|
||||
});
|
||||
return null;
|
||||
})
|
||||
.ToList();
|
||||
if (context.Result != null)
|
||||
return;
|
||||
}
|
||||
}
|
||||
context.HttpContext.Items["fields"] = fields;
|
||||
base.OnActionExecuting(context);
|
||||
|
@ -33,7 +33,8 @@ namespace Kyoo.TheTvdb
|
||||
/// <returns>The parsed <see cref="DateTime"/> or null.</returns>
|
||||
private static DateTime ParseDate(string date)
|
||||
{
|
||||
DateTime.TryParseExact(date, "yyyy-mm-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsed);
|
||||
DateTime.TryParseExact(date, "yyyy-MM-dd", CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out DateTime parsed);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
@ -122,7 +123,8 @@ namespace Kyoo.TheTvdb
|
||||
}
|
||||
}
|
||||
},
|
||||
Role = actor.Role
|
||||
Role = actor.Role,
|
||||
Type = "Actor"
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -71,11 +71,21 @@ namespace Kyoo.TheTvdb
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve metadata about a show.
|
||||
/// </summary>
|
||||
/// <param name="show">The base show to retrieve metadata for.</param>
|
||||
/// <returns>A new show filled with metadata from the tvdb.</returns>
|
||||
[ItemCanBeNull]
|
||||
private async Task<Show> _GetShow([NotNull] Show show)
|
||||
{
|
||||
if (!int.TryParse(show.GetID(Provider.Slug), out int id))
|
||||
return (await _SearchShow(show.Title)).FirstOrDefault();
|
||||
{
|
||||
Show found = (await _SearchShow(show.Title)).FirstOrDefault();
|
||||
if (found == null)
|
||||
return null;
|
||||
return await Get(found);
|
||||
}
|
||||
TvDbResponse<Series> series = await _client.Series.GetAsync(id);
|
||||
Show ret = series.Data.ToShow(Provider);
|
||||
|
||||
@ -84,6 +94,11 @@ namespace Kyoo.TheTvdb
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve metadata about an episode.
|
||||
/// </summary>
|
||||
/// <param name="episode">The base episode to retrieve metadata for.</param>
|
||||
/// <returns>A new episode filled with metadata from the tvdb.</returns>
|
||||
[ItemCanBeNull]
|
||||
private async Task<Episode> _GetEpisode([NotNull] Episode episode)
|
||||
{
|
||||
@ -106,11 +121,23 @@ namespace Kyoo.TheTvdb
|
||||
return ArraySegment<T>.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Search for shows in the tvdb.
|
||||
/// </summary>
|
||||
/// <param name="query">The query to ask the tvdb about.</param>
|
||||
/// <returns>A list of shows that could be found on the tvdb.</returns>
|
||||
[ItemNotNull]
|
||||
private async Task<ICollection<Show>> _SearchShow(string query)
|
||||
{
|
||||
TvDbResponse<SeriesSearchResult[]> shows = await _client.Search.SearchSeriesByNameAsync(query);
|
||||
return shows.Data.Select(x => x.ToShow(Provider)).ToArray();
|
||||
try
|
||||
{
|
||||
TvDbResponse<SeriesSearchResult[]> shows = await _client.Search.SearchSeriesByNameAsync(query);
|
||||
return shows.Data.Select(x => x.ToShow(Provider)).ToArray();
|
||||
}
|
||||
catch (TvDbServerException)
|
||||
{
|
||||
return ArraySegment<Show>.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -150,7 +150,7 @@ namespace Kyoo.Tasks
|
||||
|
||||
string[] subtitles = files
|
||||
.Where(FileExtensions.IsSubtitle)
|
||||
.Where(x => x.Contains("/Extra/"))
|
||||
.Where(x => !x.Contains("/Extra/"))
|
||||
.Where(x => tracks.All(y => y.Path != x))
|
||||
.ToArray();
|
||||
percent = 0;
|
||||
|
@ -112,14 +112,15 @@ namespace Kyoo.Tasks
|
||||
|
||||
if (season != null)
|
||||
season.Show = show;
|
||||
|
||||
season = await _RegisterAndFill(season);
|
||||
if (season != null)
|
||||
season.Title ??= $"Season {season.SeasonNumber}";
|
||||
progress.Report(60);
|
||||
|
||||
episode = await MetadataProvider.Get(episode);
|
||||
progress.Report(70);
|
||||
episode.Show = show;
|
||||
episode.Season = season;
|
||||
episode = await MetadataProvider.Get(episode);
|
||||
progress.Report(70);
|
||||
episode.Tracks = (await Transcoder.ExtractInfos(episode, false))
|
||||
.Where(x => x.Type != StreamType.Attachment)
|
||||
.ToArray();
|
||||
|
@ -60,5 +60,9 @@
|
||||
},
|
||||
"profilePicturePath": "users/",
|
||||
"clients": []
|
||||
},
|
||||
|
||||
"tvdb": {
|
||||
"apiKey": "REDACTED"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user