Refactored tests
This commit is contained in:
1 parent
b7a0f2c0ee
commit
35ce5536be
38 files changed
+782
-1480
No files matched your search
@@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api
|
||||
{
|
||||
public interface IKinopoiskApiProxy
|
||||
{
|
||||
Task<FilmDetails> GetSingleFilm(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<FilmDetails> GetSingleFilmImages(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<IEnumerable<StaffItem>> GetStaff(int filmId, CancellationToken? cancellationToken = null);
|
||||
Task<SearchResult> SearchByKeyword(string keyword, int page = 1, CancellationToken? cancellationToken = null);
|
||||
}
|
||||
}
|
||||
+17
-13
@@ -7,25 +7,29 @@ using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using MediaBrowser.Common.Json;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Common.Net;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api
|
||||
{
|
||||
public class KinopoiskApiProxy
|
||||
public class KinopoiskApiProxy : IKinopoiskApiProxy
|
||||
{
|
||||
private readonly string _apiToken;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly string _apiToken;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web);
|
||||
private readonly JsonSerializerOptions _jsonOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
public KinopoiskApiProxy(ILogger logger, IHttpClientFactory httpClientFactory)
|
||||
public KinopoiskApiProxy(string apiToken, ILogger<KinopoiskApiProxy> logger, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
this._logger = logger;
|
||||
this._httpClientFactory = httpClientFactory;
|
||||
this._apiToken = Plugin.Instance.Configuration.ApiToken;
|
||||
if (string.IsNullOrEmpty(apiToken))
|
||||
{
|
||||
throw new ArgumentException($"'{nameof(apiToken)}' cannot be null or empty.", nameof(apiToken));
|
||||
}
|
||||
|
||||
_apiToken = apiToken;
|
||||
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this._httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
|
||||
this._jsonOptions.Converters.Add(new JsonStringEnumMemberConverter());
|
||||
}
|
||||
|
||||
@@ -70,10 +74,10 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
Uri uri = new Uri($"https://kinopoiskapiunofficial.tech/api/v1/staff?filmId={filmId}");
|
||||
|
||||
return await GetAsync<IEnumerable<StaffItem>>(uri, cancellationToken.Value);
|
||||
return await GetAsync<IEnumerable<StaffItem>>(uri, cancellationToken.Value);
|
||||
}
|
||||
|
||||
private async Task<T> GetAsync<T>(Uri uri, CancellationToken cancellationToken) where T: class
|
||||
private async Task<T> GetAsync<T>(Uri uri, CancellationToken cancellationToken) where T : class
|
||||
{
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, uri);
|
||||
request.Headers.Add("Accept", "application/json");
|
||||
@@ -84,7 +88,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
string content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||
_logger.LogError($"Received non-success result status code {response.StatusCode} from Kinopoisk API, response content is:\n{content}");
|
||||
return null;
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class CountryItem
|
||||
{
|
||||
+2
-2
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class FilmDetails
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
public string FilmLength { get; set; }
|
||||
public string Slogan { get; set; }
|
||||
public string Description { get; set; }
|
||||
public FilmType Type { get; set; }
|
||||
public Model.FilmType Type { get; set; }
|
||||
public string RatingMpaa { get; set; }
|
||||
public int? RatingAgeLimits { get; set; }
|
||||
public DateTime? PremiereRu { get; set; }
|
||||
+17
-17
@@ -1,17 +1,17 @@
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
{
|
||||
public enum FilmType
|
||||
{
|
||||
[EnumMember(Value = "UNKNOWN")]
|
||||
Unknown,
|
||||
|
||||
[EnumMember(Value = "FILM")]
|
||||
Film,
|
||||
|
||||
[EnumMember(Value = "TV_SHOW")]
|
||||
TvShow
|
||||
}
|
||||
}
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public enum FilmType
|
||||
{
|
||||
[EnumMember(Value = "UNKNOWN")]
|
||||
Unknown,
|
||||
|
||||
[EnumMember(Value = "FILM")]
|
||||
Film,
|
||||
|
||||
[EnumMember(Value = "TV_SHOW")]
|
||||
TvShow
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class GenreItem
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class SearchResult
|
||||
{
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
|
||||
namespace Jellyfin.Plugin.Kinopoisk.Api.Model
|
||||
{
|
||||
public class StaffItem
|
||||
{
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using static Jellyfin.Plugin.Kinopoisk.ApiModel.FilmDetails;
|
||||
using static Jellyfin.Plugin.Kinopoisk.Api.Model.FilmDetails;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
@@ -217,22 +217,15 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
public static string ToPersonType(this ProfessionEnum src)
|
||||
{
|
||||
switch (src)
|
||||
return src switch
|
||||
{
|
||||
case ProfessionEnum.Actor:
|
||||
return PersonType.Actor;
|
||||
case ProfessionEnum.Director:
|
||||
return PersonType.Director;
|
||||
case ProfessionEnum.Writer:
|
||||
return PersonType.Writer;
|
||||
case ProfessionEnum.Composer:
|
||||
return PersonType.Composer;
|
||||
case ProfessionEnum.Producer:
|
||||
case ProfessionEnum.ProducerUssr:
|
||||
return PersonType.Producer;
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
ProfessionEnum.Actor => PersonType.Actor,
|
||||
ProfessionEnum.Director => PersonType.Director,
|
||||
ProfessionEnum.Writer => PersonType.Writer,
|
||||
ProfessionEnum.Composer => PersonType.Composer,
|
||||
ProfessionEnum.Producer or ProfessionEnum.ProducerUssr => PersonType.Producer,
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
public static DateTime? GetPremiereDate(this FilmData src)
|
||||
@@ -370,7 +363,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
return res;
|
||||
|
||||
var i = 0;
|
||||
Func<int> startindex = () => years.Length - 1 - i;
|
||||
int startindex() => years.Length - 1 - i;
|
||||
while (true) {
|
||||
if (i > 4)
|
||||
return null;
|
||||
@@ -383,7 +376,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
}
|
||||
|
||||
return i > 0
|
||||
? (int?)Convert.ToInt32(years.Substring(startindex()))
|
||||
? (int?)Convert.ToInt32(years[startindex()..])
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskMovieProvider : KinopoiskVideoBaseProvider<Movie, MovieInfo>
|
||||
{
|
||||
public KinopoiskMovieProvider(ILogger<KinopoiskMovieProvider> logger, IHttpClientFactory httpClientFactory) : base(logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Movie ConvertResponseToItem(FilmDetails apiResponse)
|
||||
=> apiResponse.ToMovie();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
/// <summary>
|
||||
/// Registers services
|
||||
/// </summary>
|
||||
public class KinopoiskPluginServiceRegistrator : IPluginServiceRegistrator
|
||||
{
|
||||
public void RegisterServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection.AddSingleton<KinopoiskApiProxy>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public class KinopoiskSeriesProvider : KinopoiskVideoBaseProvider<Series, SeriesInfo>
|
||||
{
|
||||
public KinopoiskSeriesProvider(ILogger<KinopoiskSeriesProvider> logger, IHttpClientFactory httpClientFactory) : base(logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Series ConvertResponseToItem(FilmDetails apiResponse)
|
||||
=> apiResponse.ToSeries();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public abstract class BaseImageProvider : IRemoteImageProvider
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
|
||||
protected BaseImageProvider(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
|
||||
}
|
||||
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract bool Supports(BaseItem item);
|
||||
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
||||
}
|
||||
|
||||
public abstract Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken);
|
||||
|
||||
public abstract IEnumerable<ImageType> GetSupportedImages(BaseItem item);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class MovieProvider : VideoBaseProvider<Movie, MovieInfo>
|
||||
{
|
||||
public MovieProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<MovieProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiProxy, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Movie ConvertResponseToItem(FilmDetails apiResponse)
|
||||
=> apiResponse.ToMovie();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class PersonImageProvider : BaseImageProvider
|
||||
{
|
||||
private readonly KinopoiskApiProxy _kinopoiskApiProxy;
|
||||
private readonly ILogger<PersonImageProvider> _logger;
|
||||
|
||||
public PersonImageProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<PersonImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
_kinopoiskApiProxy = kinopoiskApiProxy ?? throw new System.ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
_logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
public override string Name => Utils.ProviderName;
|
||||
|
||||
public override bool Supports(BaseItem item)
|
||||
=> item is Person;
|
||||
|
||||
public override Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public override IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||
{
|
||||
yield return ImageType.Primary;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Net.Http;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class SeriesProvider : VideoBaseProvider<Series, SeriesInfo>
|
||||
{
|
||||
public SeriesProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<SeriesProvider> logger, IHttpClientFactory httpClientFactory) : base(kinopoiskApiProxy, logger, httpClientFactory)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Series ConvertResponseToItem(FilmDetails apiResponse)
|
||||
=> apiResponse.ToSeries();
|
||||
}
|
||||
}
|
||||
+9
-18
@@ -3,16 +3,17 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.Kinopoisk.ApiModel;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api.Model;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public abstract class KinopoiskVideoBaseProvider<TItemType, TLookupInfoType> : IRemoteMetadataProvider<TItemType, TLookupInfoType>
|
||||
public abstract class VideoBaseProvider<TItemType, TLookupInfoType> : IRemoteMetadataProvider<TItemType, TLookupInfoType>
|
||||
where TItemType : BaseItem, IHasLookupInfo<TLookupInfoType>
|
||||
where TLookupInfoType : ItemLookupInfo, new()
|
||||
{
|
||||
@@ -22,21 +23,11 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public KinopoiskVideoBaseProvider(ILogger logger, IHttpClientFactory httpClientFactory)
|
||||
public VideoBaseProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger logger, IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
if (logger is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (httpClientFactory is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(httpClientFactory));
|
||||
}
|
||||
|
||||
this._logger = logger;
|
||||
this._httpClientFactory = httpClientFactory;
|
||||
this._apiProxy = new KinopoiskApiProxy(logger, httpClientFactory);
|
||||
this._logger = logger ?? throw new System.ArgumentNullException(nameof(logger));
|
||||
this._httpClientFactory = httpClientFactory ?? throw new System.ArgumentNullException(nameof(httpClientFactory));
|
||||
this._apiProxy = kinopoiskApiProxy ?? throw new System.ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
}
|
||||
|
||||
protected abstract TItemType ConvertResponseToItem(FilmDetails apiResponse);
|
||||
@@ -68,7 +59,7 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
|
||||
|
||||
foreach(var item in staff.ToPersonInfos())
|
||||
foreach (var item in staff.ToPersonInfos())
|
||||
result.AddPerson(item);
|
||||
|
||||
return result;
|
||||
+15
-34
@@ -4,58 +4,41 @@ using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Net;
|
||||
using Jellyfin.Plugin.Kinopoisk.Api;
|
||||
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;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
namespace Jellyfin.Plugin.Kinopoisk.MetadataProviders
|
||||
{
|
||||
public class KinopoiskImageProvider : IRemoteImageProvider
|
||||
public class VideoImageProvider : BaseImageProvider
|
||||
{
|
||||
private readonly ILogger<KinopoiskImageProvider> _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly ILogger<VideoImageProvider> _logger;
|
||||
private readonly KinopoiskApiProxy _apiProxy;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
public override string Name => Utils.ProviderName;
|
||||
|
||||
public KinopoiskImageProvider(ILogger<KinopoiskImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
public VideoImageProvider(KinopoiskApiProxy kinopoiskApiProxy, ILogger<VideoImageProvider> logger, IHttpClientFactory httpClientFactory)
|
||||
: base(httpClientFactory)
|
||||
{
|
||||
if (logger is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(logger));
|
||||
}
|
||||
|
||||
if (httpClientFactory is null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(httpClientFactory));
|
||||
}
|
||||
|
||||
this._logger = logger;
|
||||
this._httpClientFactory = httpClientFactory;
|
||||
this._apiProxy = new KinopoiskApiProxy(logger, httpClientFactory);
|
||||
this._logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
this._apiProxy = kinopoiskApiProxy ?? throw new ArgumentNullException(nameof(kinopoiskApiProxy));
|
||||
}
|
||||
|
||||
public bool Supports(BaseItem item)
|
||||
public override bool Supports(BaseItem item)
|
||||
=> item is Movie || item is Series;
|
||||
|
||||
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||
public override IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
||||
=> new ImageType[]
|
||||
{
|
||||
ImageType.Primary,
|
||||
ImageType.Backdrop
|
||||
};
|
||||
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
public override async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Utils.TryGetKinopoiskId(item, _logger, out var kinopoiskId))
|
||||
return Enumerable.Empty<RemoteImageInfo>();
|
||||
@@ -68,12 +51,10 @@ namespace Jellyfin.Plugin.Kinopoisk
|
||||
|
||||
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)));
|
||||
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);
|
||||
}
|
||||
return res.Where(i => i != null);
|
||||
}
|
||||
|
||||
private async Task<RemoteImageInfo> NullIfEmptyImage(RemoteImageInfo info, HttpClient httpClient)
|
||||
@@ -11,8 +11,6 @@ namespace Jellyfin.Plugin.Kinopoisk.Model
|
||||
{
|
||||
public string ProviderName => Utils.ProviderName;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public string Key => Utils.ProviderId;
|
||||
|
||||
public string UrlFormatString => "https://www.kinopoisk.ru/film/{0}";
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
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;
|
||||
@@ -11,8 +9,6 @@ namespace Jellyfin.Plugin.Kinopoisk.Model
|
||||
{
|
||||
public string ProviderName => Utils.ProviderName;
|
||||
|
||||
public string Name => Utils.ProviderName;
|
||||
|
||||
public string Key => Utils.ProviderId;
|
||||
|
||||
public string UrlFormatString => "https://www.kinopoisk.ru/name/{0}";
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// Copyright: https://calmsen.ru/transliteraciya-na-c
|
||||
// Copyright: http://usanov.net/748-transliteraciya-rus-2-lat-na-c
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Jellyfin.Plugin.Kinopoisk
|
||||
{
|
||||
public static class TransliterationStringExtensions
|
||||
{
|
||||
//ISO 9-95
|
||||
private static Dictionary<string, string> _replaceDictionary = new()
|
||||
{
|
||||
{ "Є", "Ye" },
|
||||
{ "І", "I" },
|
||||
{ "Ѓ", "G" },
|
||||
{ "і", "i" },
|
||||
{ "№", "#" },
|
||||
{ "є", "ye" },
|
||||
{ "ѓ", "g" },
|
||||
{ "А", "A" },
|
||||
{ "Б", "B" },
|
||||
{ "В", "V" },
|
||||
{ "Г", "G" },
|
||||
{ "Д", "D" },
|
||||
{ "Е", "E" },
|
||||
{ "Ё", "Yo" },
|
||||
{ "Ж", "Zh" },
|
||||
{ "З", "Z" },
|
||||
{ "И", "I" },
|
||||
{ "Й", "J" },
|
||||
{ "К", "K" },
|
||||
{ "Л", "L" },
|
||||
{ "М", "M" },
|
||||
{ "Н", "N" },
|
||||
{ "О", "O" },
|
||||
{ "П", "P" },
|
||||
{ "Р", "R" },
|
||||
{ "С", "S" },
|
||||
{ "Т", "T" },
|
||||
{ "У", "U" },
|
||||
{ "Ф", "F" },
|
||||
{ "Х", "X" },
|
||||
{ "Ц", "C" },
|
||||
{ "Ч", "Ch" },
|
||||
{ "Ш", "Sh" },
|
||||
{ "Щ", "Shh" },
|
||||
{ "Ъ", "'" },
|
||||
{ "Ы", "Y" },
|
||||
{ "Ь", "" },
|
||||
{ "Э", "E" },
|
||||
{ "Ю", "Yu" },
|
||||
{ "Я", "Ya" },
|
||||
{ "а", "a" },
|
||||
{ "б", "b" },
|
||||
{ "в", "v" },
|
||||
{ "г", "g" },
|
||||
{ "д", "d" },
|
||||
{ "е", "e" },
|
||||
{ "ё", "yo" },
|
||||
{ "ж", "zh" },
|
||||
{ "з", "z" },
|
||||
{ "и", "i" },
|
||||
{ "й", "j" },
|
||||
{ "к", "k" },
|
||||
{ "л", "l" },
|
||||
{ "м", "m" },
|
||||
{ "н", "n" },
|
||||
{ "о", "o" },
|
||||
{ "п", "p" },
|
||||
{ "р", "r" },
|
||||
{ "с", "s" },
|
||||
{ "т", "t" },
|
||||
{ "у", "u" },
|
||||
{ "ф", "f" },
|
||||
{ "х", "x" },
|
||||
{ "ц", "c" },
|
||||
{ "ч", "ch" },
|
||||
{ "ш", "sh" },
|
||||
{ "щ", "shh" },
|
||||
{ "ъ", "" },
|
||||
{ "ы", "y" },
|
||||
{ "ь", "" },
|
||||
{ "э", "e" },
|
||||
{ "ю", "yu" },
|
||||
{ "я", "ya" },
|
||||
};
|
||||
|
||||
public static string TransliterateToLatin(this string text)
|
||||
{
|
||||
string output = text;
|
||||
|
||||
output = Regex.Replace(output, @"\s|\.|\(", " ");
|
||||
output = Regex.Replace(output, @"\s+", " ");
|
||||
output = Regex.Replace(output, @"[^\s\w\d-]", "");
|
||||
output = output.Trim();
|
||||
|
||||
foreach (KeyValuePair<string, string> key in _replaceDictionary)
|
||||
{
|
||||
output = output.Replace(key.Key, key.Value);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public static string TransliterateToCyrillic(this string text)
|
||||
{
|
||||
string output = text;
|
||||
|
||||
foreach (KeyValuePair<string, string> key in _replaceDictionary)
|
||||
{
|
||||
output = output.Replace(key.Value, key.Key);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user