Devcontainer, fixes
This commit is contained in:
1 parent
b619253510
commit
8ca93bf060
26 files changed
+929
-302
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
+50
-50
@@ -1,50 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Tests
|
||||
{
|
||||
public class DeserializationTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
|
||||
public DeserializationTests() {
|
||||
this._jsonOptions.Converters.Add(new JsonStringEnumMemberConverter());
|
||||
}
|
||||
|
||||
private Stream GetTestDataStream(string name) {
|
||||
var assembly = typeof(DeserializationTests).GetTypeInfo().Assembly;
|
||||
return assembly.GetManifestResourceStream($"Jellyfin.Plugin.Kinopoisk.Test.Data.{name}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FilmDetails_ShouldParseFilm()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616059004666.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<FilmDetails>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(FilmType.Film, res.Data.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FilmDetails_ShouldParseTvShow()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616058514535.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<FilmDetails>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(FilmType.TvShow, res.Data.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StaffItem_ShouldParseProducerUssr()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616062293018.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<IEnumerable<StaffItem>>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(ProfessionEnum.ProducerUssr, res.ToArray()[81].ProfessionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Tests
|
||||
{
|
||||
public class DeserializationTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
|
||||
public DeserializationTests() {
|
||||
this._jsonOptions.Converters.Add(new JsonStringEnumMemberConverter());
|
||||
}
|
||||
|
||||
private Stream GetTestDataStream(string name) {
|
||||
var assembly = typeof(DeserializationTests).GetTypeInfo().Assembly;
|
||||
return assembly.GetManifestResourceStream($"Jellyfin.Plugin.Kinopoisk.Tests.Data.{name}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FilmDetails_ShouldParseFilm()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616059004666.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<FilmDetails>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(FilmType.Film, res.Data.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FilmDetails_ShouldParseTvShow()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616058514535.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<FilmDetails>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(FilmType.TvShow, res.Data.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StaffItem_ShouldParseProducerUssr()
|
||||
{
|
||||
using var testData = GetTestDataStream("response_1616062293018.json");
|
||||
var res = await JsonSerializer.DeserializeAsync<IEnumerable<StaffItem>>(testData, _jsonOptions).ConfigureAwait(false);
|
||||
Assert.Equal(ProfessionEnum.ProducerUssr, res.ToArray()[81].ProfessionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
@@ -2,6 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<DebugType>portable</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -10,10 +11,21 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Jellyfin.Controller" Version="10.7.0" />
|
||||
<PackageReference Include="Jellyfin.Model" Version="10.7.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||
<PackageReference Include="Macross.Json.Extensions" Version="2.0.0" />
|
||||
<PackageReference Include="Jellyfin.Controller" Version="10.*">
|
||||
<IncludeAssets>compile</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Jellyfin.Model" Version="10.*">
|
||||
<IncludeAssets>compile</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0">
|
||||
<IncludeAssets>compile</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Macross.Json.Extensions" Version="2.0.0">
|
||||
<IncludeAssets>all</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="System.Text.Json" Version="5.*">
|
||||
<IncludeAssets>compile</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -61,7 +62,40 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
var film = await _apiProxy.GetSingleFilmImages(kinopoiskId, cancellationToken);
|
||||
|
||||
return film.ToRemoteImageInfos();
|
||||
return await FilterEmptyImages(film.ToRemoteImageInfos());
|
||||
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<RemoteImageInfo>> FilterEmptyImages(IEnumerable<RemoteImageInfo> images)
|
||||
{
|
||||
using (var httpClient = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }, true))
|
||||
{
|
||||
var res = await Task.WhenAll(images.Select(i => NullIfEmptyImage(i, httpClient)));
|
||||
|
||||
return res.Where(i => i != null);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<RemoteImageInfo> NullIfEmptyImage(RemoteImageInfo info, HttpClient httpClient)
|
||||
{
|
||||
var currentUrl = info.Url;
|
||||
while (!currentUrl.Contains("no-poster"))
|
||||
{
|
||||
var response = await httpClient.SendAsync(
|
||||
new HttpRequestMessage(HttpMethod.Get, currentUrl), HttpCompletionOption.ResponseHeadersRead);
|
||||
|
||||
if ((int)response.StatusCode <= 299)
|
||||
return info;
|
||||
else if (response.Headers.Location != null)
|
||||
{
|
||||
currentUrl = response.Headers.Location.ToString();
|
||||
continue;
|
||||
}
|
||||
else
|
||||
throw new InvalidOperationException("Not expected answer");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Model
|
||||
{
|
||||
public class KinopoiskExternalId : IExternalId
|
||||
{
|
||||
@@ -0,0 +1,27 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Model
|
||||
{
|
||||
public class KinopoiskPersonExternalId : IExternalId
|
||||
{
|
||||
public string ProviderName => Utils.ProviderName;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public string Key => Utils.ProviderId;
|
||||
|
||||
public string UrlFormatString => "https://www.kinopoisk.ru/name/{0}";
|
||||
|
||||
public ExternalIdMediaType? Type => null;
|
||||
|
||||
public bool Supports(IHasProviderIds item)
|
||||
{
|
||||
return item is Person;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ VisualStudioVersion = 15.0.26124.0
|
||||
MinimumVisualStudioVersion = 15.0.26124.0
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Kinopoisk", "Jellyfin.Plugin.Kinopoisk\Jellyfin.Plugin.Kinopoisk.csproj", "{C9335ABD-972B-4FF9-B564-72D9FF7122A2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Kinopoisk.Test", "Jellyfin.Plugin.Kinopoisk.Test\Jellyfin.Plugin.Kinopoisk.Test.csproj", "{7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jellyfin.Plugin.Kinopoisk.Tests", "Jellyfin.Plugin.Kinopoisk.Tests\Jellyfin.Plugin.Kinopoisk.Tests.csproj", "{7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
Reference in new issue
Block a user