diff --git a/.vscode/launch.json b/.vscode/launch.json
index b70caee..2eab03a 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -11,7 +11,7 @@
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Jellyfin.Plugin.Kinopoisk/bin/Debug/netstandard2.1/Jellyfin.Plugin.Kinopoisk.dll",
"args": [],
- "cwd": "${workspaceFolder}",
+ "cwd": "${workspaceFolder}/src",
"console": "internalConsole",
"stopAtEntry": false
},
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 04e0bb7..2eb250f 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -9,11 +9,12 @@
"type": "shell",
"args": [
"build",
- "${workspaceFolder}/src/Jellyfin.Plugin.Kinopoisk/Jellyfin.Plugin.Kinopoisk.csproj"
+ "${workspaceFolder}/src/Kinopoisk.sln"
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
- "/consoleloggerparameters:NoSummary"
+ "/consoleloggerparameters:NoSummary",
+ "/property:Version=10.6.0.1"
],
"group": "build",
"presentation": {
@@ -21,20 +22,6 @@
},
"problemMatcher": "$msCompile"
},
- {
- "label": "test",
- "command": "dotnet",
- "type": "shell",
- "args": [
- "test",
- "${workspaceFolder}/src/Jellyfin.Plugin.Kinopoisk/Jellyfin.Plugin.Kinopoisk.csproj"
- ],
- "group": "test",
- "presentation": {
- "reveal": "silent"
- },
- "problemMatcher": "$msCompile"
- },
{
"label": "make-dist",
"command": "powershell",
@@ -42,7 +29,7 @@
"args": [
"Compress-Archive",
"-Path", "${workspaceFolder}/src/Jellyfin.Plugin.Kinopoisk/bin/Debug/netstandard2.1/Jellyfin.Plugin.Kinopoisk.dll",
- "-DestinationPath", "${workspaceFolder}/dist/jellyfin-plugin-kinopoisk_10.6.0.0.zip"
+ "-DestinationPath", "${workspaceFolder}/dist/jellyfin-plugin-kinopoisk_10.6.0.1.zip"
],
"group": "build",
"presentation": {
diff --git a/dist/jellyfin-plugin-kinopoisk_10.6.0.1.zip b/dist/jellyfin-plugin-kinopoisk_10.6.0.1.zip
new file mode 100644
index 0000000..1199c55
Binary files /dev/null and b/dist/jellyfin-plugin-kinopoisk_10.6.0.1.zip differ
diff --git a/dist/manifest.json b/dist/manifest.json
index 6384ce1..1019b4d 100644
--- a/dist/manifest.json
+++ b/dist/manifest.json
@@ -17,6 +17,17 @@
"filename": "jellyfin-plugin-kinopoisk_10.6.0.0.zip",
"timestamp": "2020-07-07 10:00:00",
"version": "10.6.0.0"
+ },
+ {
+ "checksum": "a877cde0df7d70266fdb9362b72884c1",
+ "changelog": "new release",
+ "name": "КиноПоиск",
+ "targetAbi": "10.6.0",
+ "runtimes": "netframework,netcore",
+ "sourceUrl": "https://github.com/LinFor/jellyfin-plugin-kinopoisk/raw/master/dist/jellyfin-plugin-kinopoisk_10.6.0.1.zip",
+ "filename": "jellyfin-plugin-kinopoisk_10.6.0.1.zip",
+ "timestamp": "2020-07-07 19:00:00",
+ "version": "10.6.0.1"
}
]
}
diff --git a/kinopoisk.code-workspace b/kinopoisk.code-workspace
index 362d7c2..feb5b8b 100644
--- a/kinopoisk.code-workspace
+++ b/kinopoisk.code-workspace
@@ -3,5 +3,12 @@
{
"path": "."
}
- ]
-}
\ No newline at end of file
+ ],
+ "settings": {
+ "csharp.unitTestDebuggingOptions": {
+ "sourceFileMap": {
+ "${workspaceFolder}\\src\\Jellyfin.Plugin.Kinopoisk\\bin\\Debug\\netstandard2.1\\Jellyfin.Plugin.Kinopoisk.dll": "${workspaceFolder}/src/Jellyfin.Plugin.Kinopoisk.Test/bin/Debug/net5.0"
+ }
+ }
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk.Tests/Jellyfin.Plugin.Kinopoisk.Tests.csproj b/src/Jellyfin.Plugin.Kinopoisk.Test/Jellyfin.Plugin.Kinopoisk.Test.csproj
similarity index 89%
rename from src/Jellyfin.Plugin.Kinopoisk.Tests/Jellyfin.Plugin.Kinopoisk.Tests.csproj
rename to src/Jellyfin.Plugin.Kinopoisk.Test/Jellyfin.Plugin.Kinopoisk.Test.csproj
index c2e1ee3..dc0d2fa 100644
--- a/src/Jellyfin.Plugin.Kinopoisk.Tests/Jellyfin.Plugin.Kinopoisk.Tests.csproj
+++ b/src/Jellyfin.Plugin.Kinopoisk.Test/Jellyfin.Plugin.Kinopoisk.Test.csproj
@@ -1,20 +1,21 @@
-
-
-
- net5.0
-
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ net5.0
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Jellyfin.Plugin.Kinopoisk.Test/UtilsTests.cs b/src/Jellyfin.Plugin.Kinopoisk.Test/UtilsTests.cs
new file mode 100644
index 0000000..e92bf67
--- /dev/null
+++ b/src/Jellyfin.Plugin.Kinopoisk.Test/UtilsTests.cs
@@ -0,0 +1,42 @@
+using System;
+using Xunit;
+
+namespace Jellyfin.Plugin.Kinopoisk.Tests
+{
+ public class UtilsTests
+ {
+ [Theory]
+ [InlineData("2015", 2015)]
+ [InlineData("2014-2017", 2014)]
+ [InlineData("2014-20317", 2014)]
+ [InlineData("20314-2017", null)]
+ [InlineData("2020-...", 2020)]
+ public void GetFirstYear_ShouldParseYearsSpan(string src, int? expected)
+ {
+ var res = ApiModelExtensions.GetFirstYear(src);
+ Assert.Equal(expected, res);
+ }
+
+ [Theory]
+ [InlineData("2015", false)]
+ [InlineData("2014-2017", false)]
+ [InlineData("2020-...", true)]
+ public void IsСontinues_ShouldParseYearsSpan(string src, bool expected)
+ {
+ var res = ApiModelExtensions.IsСontinuing(src);
+ Assert.Equal(expected, res);
+ }
+
+ [Theory]
+ [InlineData("2015", 2015)]
+ [InlineData("2014-2017", 2017)]
+ [InlineData("2014-20317", null)]
+ [InlineData("20314-2017", 2017)]
+ [InlineData("2020-...", null)]
+ public void GetLastYear_ShouldFindContinuing(string src, int? expected)
+ {
+ var res = ApiModelExtensions.GetLastYear(src);
+ Assert.Equal(expected, res);
+ }
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk.Tests/UtilsTests.cs b/src/Jellyfin.Plugin.Kinopoisk.Tests/UtilsTests.cs
deleted file mode 100644
index 85b3ecc..0000000
--- a/src/Jellyfin.Plugin.Kinopoisk.Tests/UtilsTests.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System;
-using Xunit;
-
-namespace Jellyfin.Plugin.Kinopoisk.Tests
-{
- public class UtilsTests
- {
- [Fact]
- public void GetFirstYear_ShouldParseYearsSpan()
- {
- var inp = "2014-2017";
- var res = Utils.GetFirstYear(inp);
- Assert.Equal(2014, res);
- }
- }
-}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/CountryItem.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/CountryItem.cs
new file mode 100644
index 0000000..6c72bfa
--- /dev/null
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/CountryItem.cs
@@ -0,0 +1,7 @@
+namespace Jellyfin.Plugin.Kinopoisk.ApiModel
+{
+ public class CountryItem
+ {
+ public string Country { get; set; }
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmDetails.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmDetails.cs
index 75949cd..25c84d4 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmDetails.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmDetails.cs
@@ -1,4 +1,6 @@
+using System;
using System.Collections.Generic;
+using System.Runtime.Serialization;
namespace Jellyfin.Plugin.Kinopoisk.ApiModel
{
@@ -37,29 +39,19 @@ namespace Jellyfin.Plugin.Kinopoisk.ApiModel
public string FilmLength { get; set; }
public string Slogan { get; set; }
public string Description { get; set; }
- public string Type { get; set; } // FILM, TV_SHOW
+ public FilmType Type { get; set; }
public string RatingMpaa { get; set; }
- public string RatingAgeLimits { get; set; }
- public string PremiereRu { get; set; }
+ public int? RatingAgeLimits { get; set; }
+ public DateTime? PremiereRu { get; set; }
public string Distributors { get; set; }
- public string PremiereWorld { get; set; }
- public string PremiereDigital { get; set; }
+ public DateTime? PremiereWorld { get; set; }
+ public DateTime? PremiereDigital { get; set; }
public string PremiereWorldCountry { get; set; }
- public string PremiereDvd { get; set; }
- public string PremiereBluRay { get; set; }
+ public DateTime? PremiereDvd { get; set; }
+ public DateTime? PremiereBluRay { get; set; }
public string DistributorRelease { get; set; }
public CountryItem[] Countries { get; set; }
public GenreItem[] Genres { get; set; }
-
- public class CountryItem
- {
- public string Country { get; set; }
- }
-
- public class GenreItem
- {
- public string Genre { get; set; }
- }
}
public class FilmExtId
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmType.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmType.cs
new file mode 100644
index 0000000..acc4a7a
--- /dev/null
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/FilmType.cs
@@ -0,0 +1,17 @@
+using System.Runtime.Serialization;
+
+namespace Jellyfin.Plugin.Kinopoisk.ApiModel
+{
+ [DataContract]
+ public enum FilmType
+ {
+ [EnumMember(Value = "UNKNOWN")]
+ Unknown,
+
+ [EnumMember(Value = "FILM")]
+ Film,
+
+ [EnumMember(Value = "TV_SHOW")]
+ TvShow
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/GenreItem.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/GenreItem.cs
new file mode 100644
index 0000000..2151c2c
--- /dev/null
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/GenreItem.cs
@@ -0,0 +1,7 @@
+namespace Jellyfin.Plugin.Kinopoisk.ApiModel
+{
+ public class GenreItem
+ {
+ public string Genre { get; set; }
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/SearchResult.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/SearchResult.cs
index c463e47..b4a570e 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/ApiModel/SearchResult.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModel/SearchResult.cs
@@ -13,10 +13,12 @@ namespace Jellyfin.Plugin.Kinopoisk.ApiModel
public int FilmId { get; set; }
public string NameRu { get; set; }
public string NameEn { get; set; }
- public string Type { get; set; }
+ public FilmType Type { get; set; }
public string Year { get; set; }
public string Description { get; set; }
public string FilmLength { get; set; }
+ public CountryItem[] Countries { get; set; }
+ public GenreItem[] Genres { get; set; }
public string Rating { get; set; }
public string RatingVoteCount { get; set; }
public string PosterUrl { get; set; }
diff --git a/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs b/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs
index 9eed886..acf9ed1 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/ApiModelExtensions.cs
@@ -13,21 +13,68 @@ namespace Jellyfin.Plugin.Kinopoisk
{
public static class ApiModelExtensions
{
+ public static RemoteSearchResult ToRemoteSearchResult(this FilmDetails src)
+ {
+ if (src?.Data is null)
+ return null;
+
+ var res = new RemoteSearchResult() {
+ Name = src.GetLocalName(),
+ ImageUrl = src.Data.PosterUrl,
+ PremiereDate = src.Data.GetPremiereDate(),
+ Overview = src.Data.Description,
+ SearchProviderName = Utils.ProviderName
+ };
+ res.SetProviderId(Utils.ProviderId, Convert.ToString(src.Data.FilmId));
+
+ return res;
+ }
+
+ public static IEnumerable ToRemoteSearchResults(this SearchResult src)
+ {
+ if (src?.Films is null)
+ return Enumerable.Empty();
+
+ return src.Films.Select(s => s.ToRemoteSearchResult());
+ }
+
+ public static RemoteSearchResult ToRemoteSearchResult(this SearchResult.Film src)
+ {
+ if (src is null)
+ return null;
+
+ var res = new RemoteSearchResult() {
+ Name = src.GetLocalName(),
+ ImageUrl = src.PosterUrl,
+ PremiereDate = src.GetPremiereDate(),
+ Overview = src.Description,
+ SearchProviderName = Utils.ProviderName
+ };
+ res.SetProviderId(Utils.ProviderId, Convert.ToString(src.FilmId));
+
+ return res;
+ }
+
public static Series ToSeries(this FilmDetails src)
{
- if (src.Data is null)
+ if (src?.Data is null)
return null;
var res = new Series();
FillCommonFilmInfo(src, res);
+ res.EndDate = src.Data.GetEndDate();
+ res.Status = src.Data.IsContinuing()
+ ? SeriesStatus.Continuing
+ : SeriesStatus.Ended;
+
return res;
}
public static Movie ToMovie(this FilmDetails src)
{
- if (src.Data is null)
+ if (src?.Data is null)
return null;
var res = new Movie();
@@ -40,19 +87,16 @@ namespace Jellyfin.Plugin.Kinopoisk
private static void FillCommonFilmInfo(FilmDetails src, BaseItem dst)
{
dst.SetProviderId(Utils.ProviderId, Convert.ToString(src.Data.FilmId));
- dst.Name = src.Data.NameRu;
- if (string.IsNullOrWhiteSpace(dst.Name))
- dst.Name = src.Data.NameEn;
- // if (!string.IsNullOrWhiteSpace(film.Data.WebUrl))
- // result.Item.HomePageUrl = film.Data.WebUrl;
- dst.ProductionYear = Utils.GetFirstYear(src.Data.Year);
+ dst.Name = src.GetLocalName();
+ dst.OriginalTitle = src.GetOriginalNameIfNotSame();
+ dst.PremiereDate = src.Data.GetPremiereDate();
dst.Overview = src.Data.Description;
if (src.Data.Countries != null)
dst.ProductionLocations = src.Data.Countries.Select(c => c.Country).ToArray();
if (src.Data.Genres != null)
foreach(var genre in src.Data.Genres.Select(c => c.Genre))
dst.AddGenre(genre);
- if (!string.IsNullOrWhiteSpace(src.Data.RatingAgeLimits))
+ if (src.Data.RatingAgeLimits.HasValue)
dst.OfficialRating = $"{src.Data.RatingAgeLimits}+";
else
dst.OfficialRating = src.Data.RatingMpaa;
@@ -190,5 +234,157 @@ namespace Jellyfin.Plugin.Kinopoisk
return null;
}
}
+
+ public static DateTime? GetPremiereDate(this FilmData src)
+ {
+ var res = src.IsRussianSpokenOriginated()
+ ? src.PremiereRu
+ : src.PremiereWorld;
+ if (src.PremiereRu < res)
+ res = src.PremiereRu;
+ if (src.PremiereWorld < res)
+ res = src.PremiereWorld;
+ if (src.PremiereDigital < res)
+ res = src.PremiereDigital;
+ if (src.PremiereDvd < res)
+ res = src.PremiereDvd;
+ if (src.PremiereBluRay < res)
+ res = src.PremiereBluRay;
+
+ if (res.HasValue)
+ return res;
+
+ var firstYear = GetFirstYear(src.Year);
+ if (firstYear != null)
+ return new DateTime(firstYear.Value, 1, 1);
+
+ return null;
+ }
+
+ public static DateTime? GetPremiereDate(this SearchResult.Film src)
+ {
+ var firstYear = GetFirstYear(src.Year);
+ if (firstYear != null)
+ return new DateTime(firstYear.Value, 1, 1);
+
+ return null;
+ }
+
+ public static DateTime? GetEndDate(this FilmData src)
+ {
+ var lastYear = GetLastYear(src.Year);
+ if (lastYear != null)
+ return new DateTime(lastYear.Value, 12, 31);
+
+ return null;
+ }
+
+ public static bool IsContinuing(this FilmData src)
+ => IsСontinuing(src?.Year);
+
+ public static string GetLocalName(this FilmDetails src)
+ {
+ var res = src?.Data?.NameRu;
+ if (string.IsNullOrWhiteSpace(res))
+ res = src?.Data?.NameEn;
+ return res;
+ }
+
+ public static string GetLocalName(this SearchResult.Film src)
+ {
+ var res = src?.NameRu;
+ if (string.IsNullOrWhiteSpace(res))
+ res = src?.NameEn;
+ return res;
+ }
+
+ public static string GetOriginalName(this FilmDetails src)
+ => src.IsRussianSpokenOriginated()
+ ? src?.Data?.NameRu
+ : src?.Data?.NameEn;
+
+ public static string GetOriginalNameIfNotSame(this FilmDetails src)
+ {
+ var localName = src.GetLocalName();
+ var originalName = src.GetOriginalName();
+ if (!string.IsNullOrWhiteSpace(originalName) && !string.Equals(localName, originalName))
+ return originalName;
+
+ return string.Empty;
+ }
+
+ public static bool IsRussianSpokenOriginated(this FilmDetails src)
+ => src?.Data?.IsRussianSpokenOriginated() ?? false;
+
+ public static bool IsRussianSpokenOriginated(this FilmData src)
+ => src?.Countries?.IsRussianSpokenOriginated() ?? false;
+
+ public static bool IsRussianSpokenOriginated(this IEnumerable src)
+ {
+ if (src is null)
+ return false;
+
+ foreach(var country in src)
+ switch(country.Country)
+ {
+ case "Россия":
+ return true;
+ }
+
+ return false;
+ }
+
+ public static int? GetFirstYear(string years)
+ {
+ if (string.IsNullOrWhiteSpace(years))
+ return null;
+
+ years = years.Trim();
+
+ if (int.TryParse(years, out var res))
+ return res;
+
+ var i = 0;
+ while (true) {
+ if (i > 4)
+ return null;
+ if (!char.IsDigit(years[i]))
+ break;
+ i++;
+ }
+
+ return Convert.ToInt32(years.Substring(0, i));
+ }
+
+ public static bool IsСontinuing(string years)
+ => years?.EndsWith("-...") ?? false;
+
+ public static int? GetLastYear(string years)
+ {
+ if (string.IsNullOrWhiteSpace(years))
+ return null;
+
+ years = years.Trim();
+
+ if (int.TryParse(years, out var res))
+ return res;
+
+ var i = 0;
+ Func startindex = () => years.Length - 1 - i;
+ while (true) {
+ if (i > 4)
+ return null;
+ if (!char.IsDigit(years[startindex()]))
+ {
+ i--;
+ break;
+ }
+ i++;
+ }
+
+ return i > 0
+ ? (int?)Convert.ToInt32(years.Substring(startindex()))
+ : null;
+ }
}
}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/KinopoiskMovieProvider.cs b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskMovieProvider.cs
index fbe2210..2a01ae6 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/KinopoiskMovieProvider.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskMovieProvider.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Jellyfin.Plugin.Kinopoisk.ApiModel;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
@@ -13,107 +14,16 @@ using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.Kinopoisk
{
- public class KinopoiskMovieProvider : IRemoteMetadataProvider
+ public class KinopoiskMovieProvider : KinopoiskVideoBaseProvider
{
- private readonly ILogger _logger;
- private readonly IHttpClient _httpClient;
- private readonly IJsonSerializer _jsonSerializer;
- private readonly KinopoiskApiProxy _apiProxy;
-
- public string Name => Utils.ProviderName;
-
public KinopoiskMovieProvider(ILogger logger,
IHttpClient httpClient,
IJsonSerializer jsonSerializer)
+ : base(logger, httpClient, jsonSerializer)
{
- if (logger is null)
- {
- throw new System.ArgumentNullException(nameof(logger));
- }
-
- if (httpClient is null)
- {
- throw new System.ArgumentNullException(nameof(httpClient));
- }
-
- if (jsonSerializer is null)
- {
- throw new System.ArgumentNullException(nameof(jsonSerializer));
- }
-
- this._logger = logger;
- this._httpClient = httpClient;
- this._jsonSerializer = jsonSerializer;
- this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
}
- public Task GetImageResponse(string url, CancellationToken cancellationToken)
- {
- return _httpClient.GetResponse(new HttpRequestOptions
- {
- CancellationToken = cancellationToken,
- Url = url
- });
- }
-
- public async Task> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
- {
- var result = new MetadataResult()
- {
- QueriedById = true,
- Provider = Utils.ProviderName,
- ResultLanguage = Utils.ProviderMetadataLanguage
- };
-
- if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
- return result;
-
- var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
-
- result.Item = film.ToMovie();
- if (result.Item != null)
- result.HasMetadata = true;
-
- cancellationToken.ThrowIfCancellationRequested();
-
- var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
-
- foreach(var item in staff.ToPersonInfos())
- result.AddPerson(item);
-
- return result;
- }
-
- public async Task> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
- {
- if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
- {
- var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
- var singleResult = new RemoteSearchResult() {
- Name = film.Data.NameRu ?? film.Data.NameEn,
- ImageUrl = film.Data.PosterUrl,
- ProductionYear = Utils.GetFirstYear(film.Data.Year),
- Overview = film.Data.Description,
- SearchProviderName = Utils.ProviderName
- };
- singleResult.SetProviderId(Utils.ProviderId, Convert.ToString(film.Data.FilmId));
- return Enumerable.Repeat(singleResult, 1);
- }
- else
- {
- var searchResults = await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken);
- return searchResults.Films.Select(f => {
- var res = new RemoteSearchResult() {
- Name = f.NameRu ?? f.NameEn,
- ImageUrl = f.PosterUrl,
- ProductionYear = Utils.GetFirstYear(f.Year),
- Overview = f.Description,
- SearchProviderName = Utils.ProviderName
- };
- res.SetProviderId(Utils.ProviderId, Convert.ToString(f.FilmId));
- return res;
- });
- }
- }
+ protected override Movie ConvertResponseToItem(FilmDetails apiResponse)
+ => apiResponse.ToMovie();
}
}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/KinopoiskSeriesProvider.cs b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskSeriesProvider.cs
index 9118d2a..2b14c96 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/KinopoiskSeriesProvider.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskSeriesProvider.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Jellyfin.Plugin.Kinopoisk.ApiModel;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
@@ -13,107 +14,17 @@ using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.Kinopoisk
{
- public class KinopoiskSeriesProvider : IRemoteMetadataProvider
+ public class KinopoiskSeriesProvider : KinopoiskVideoBaseProvider
{
- private readonly ILogger _logger;
- private readonly IHttpClient _httpClient;
- private readonly IJsonSerializer _jsonSerializer;
- private readonly KinopoiskApiProxy _apiProxy;
-
- public string Name => Utils.ProviderName;
-
public KinopoiskSeriesProvider(ILogger logger,
IHttpClient httpClient,
IJsonSerializer jsonSerializer)
+ : base(logger, httpClient, jsonSerializer)
{
- if (logger is null)
- {
- throw new System.ArgumentNullException(nameof(logger));
- }
- if (httpClient is null)
- {
- throw new System.ArgumentNullException(nameof(httpClient));
- }
-
- if (jsonSerializer is null)
- {
- throw new System.ArgumentNullException(nameof(jsonSerializer));
- }
-
- this._logger = logger;
- this._httpClient = httpClient;
- this._jsonSerializer = jsonSerializer;
- this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
}
- public Task GetImageResponse(string url, CancellationToken cancellationToken)
- {
- return _httpClient.GetResponse(new HttpRequestOptions
- {
- CancellationToken = cancellationToken,
- Url = url
- });
- }
-
- public async Task> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
- {
- var result = new MetadataResult()
- {
- QueriedById = true,
- Provider = Utils.ProviderName,
- ResultLanguage = Utils.ProviderMetadataLanguage
- };
-
- if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
- return result;
-
- var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
-
- result.Item = film.ToSeries();
- if (result.Item != null)
- result.HasMetadata = true;
-
- cancellationToken.ThrowIfCancellationRequested();
-
- var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
-
- foreach(var item in staff.ToPersonInfos())
- result.AddPerson(item);
-
- return result;
- }
-
- public async Task> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
- {
- if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
- {
- var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
- var singleResult = new RemoteSearchResult() {
- Name = film.Data.NameRu ?? film.Data.NameEn,
- ImageUrl = film.Data.PosterUrl,
- ProductionYear = Utils.GetFirstYear(film.Data.Year),
- Overview = film.Data.Description,
- SearchProviderName = Utils.ProviderName
- };
- singleResult.SetProviderId(Utils.ProviderId, Convert.ToString(film.Data.FilmId));
- return Enumerable.Repeat(singleResult, 1);
- }
- else
- {
- var searchResults = await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken);
- return searchResults.Films.Select(f => {
- var res = new RemoteSearchResult() {
- Name = f.NameRu ?? f.NameEn,
- ImageUrl = f.PosterUrl,
- ProductionYear = Utils.GetFirstYear(f.Year),
- Overview = f.Description,
- SearchProviderName = Utils.ProviderName
- };
- res.SetProviderId(Utils.ProviderId, Convert.ToString(f.FilmId));
- return res;
- });
- }
- }
+ protected override Series ConvertResponseToItem(FilmDetails apiResponse)
+ => apiResponse.ToSeries();
}
}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/KinopoiskVideoBaseProvider.cs b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskVideoBaseProvider.cs
new file mode 100644
index 0000000..88ca36b
--- /dev/null
+++ b/src/Jellyfin.Plugin.Kinopoisk/KinopoiskVideoBaseProvider.cs
@@ -0,0 +1,103 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Jellyfin.Plugin.Kinopoisk.ApiModel;
+using MediaBrowser.Common.Net;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Providers;
+using MediaBrowser.Model.Providers;
+using MediaBrowser.Model.Serialization;
+using Microsoft.Extensions.Logging;
+
+namespace Jellyfin.Plugin.Kinopoisk
+{
+ public abstract class KinopoiskVideoBaseProvider : IRemoteMetadataProvider
+ where TItemType : BaseItem, IHasLookupInfo
+ where TLookupInfoType : ItemLookupInfo, new()
+ {
+ private readonly ILogger _logger;
+ private readonly IHttpClient _httpClient;
+ private readonly IJsonSerializer _jsonSerializer;
+ private readonly KinopoiskApiProxy _apiProxy;
+
+ public string Name => Utils.ProviderName;
+
+ public KinopoiskVideoBaseProvider(ILogger logger,
+ IHttpClient httpClient,
+ IJsonSerializer jsonSerializer)
+ {
+ if (logger is null)
+ {
+ throw new System.ArgumentNullException(nameof(logger));
+ }
+
+ if (httpClient is null)
+ {
+ throw new System.ArgumentNullException(nameof(httpClient));
+ }
+
+ if (jsonSerializer is null)
+ {
+ throw new System.ArgumentNullException(nameof(jsonSerializer));
+ }
+
+ this._logger = logger;
+ this._httpClient = httpClient;
+ this._jsonSerializer = jsonSerializer;
+ this._apiProxy = new KinopoiskApiProxy(logger, httpClient, jsonSerializer);
+ }
+
+ protected abstract TItemType ConvertResponseToItem(FilmDetails apiResponse);
+
+ public Task GetImageResponse(string url, CancellationToken cancellationToken)
+ {
+ return _httpClient.GetResponse(new HttpRequestOptions
+ {
+ CancellationToken = cancellationToken,
+ Url = url
+ });
+ }
+
+ public async Task> GetMetadata(TLookupInfoType info, CancellationToken cancellationToken)
+ {
+ var result = new MetadataResult()
+ {
+ QueriedById = true,
+ Provider = Utils.ProviderName,
+ ResultLanguage = Utils.ProviderMetadataLanguage
+ };
+
+ if (!Utils.TryGetKinopoiskId(info, _logger, out var kinopoiskId))
+ return result;
+
+ var film = await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken);
+
+ result.Item = ConvertResponseToItem(film);
+ if (result.Item != null)
+ result.HasMetadata = true;
+
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var staff = await _apiProxy.GetStaff(kinopoiskId, cancellationToken);
+
+ foreach(var item in staff.ToPersonInfos())
+ result.AddPerson(item);
+
+ return result;
+ }
+
+ public async Task> GetSearchResults(TLookupInfoType searchInfo, CancellationToken cancellationToken)
+ {
+ if (Utils.TryGetKinopoiskId(searchInfo, _logger, out var kinopoiskId))
+ {
+ var singleResult = (await _apiProxy.GetSingleFilm(kinopoiskId, cancellationToken)).ToRemoteSearchResult();
+ return Enumerable.Repeat(singleResult, 1);
+ }
+ else
+ {
+ return (await _apiProxy.SearchByKeyword(searchInfo.Name, cancellationToken: cancellationToken)).ToRemoteSearchResults();
+ }
+ }
+ }
+}
diff --git a/src/Jellyfin.Plugin.Kinopoisk/Utils.cs b/src/Jellyfin.Plugin.Kinopoisk/Utils.cs
index 6334dd9..428a26f 100644
--- a/src/Jellyfin.Plugin.Kinopoisk/Utils.cs
+++ b/src/Jellyfin.Plugin.Kinopoisk/Utils.cs
@@ -11,26 +11,6 @@ namespace Jellyfin.Plugin.Kinopoisk
public const string ProviderDescription = "Загружает рейтинги сайта КиноПоиск";
public const string ProviderMetadataLanguage = "ru";
- public static int? GetFirstYear(string years)
- {
- if (string.IsNullOrWhiteSpace(years))
- return null;
-
- years = years.Trim();
-
- if (int.TryParse(years, out var res))
- return res;
-
- var i = 0;
- while (i < 4) {
- if (!char.IsDigit(years[i]))
- break;
- i++;
- }
-
- return Convert.ToInt32(years.Substring(0, i));
- }
-
public static bool TryGetKinopoiskId(IHasProviderIds item, ILogger logger, out int result)
{
var kinopoiskIdStr = item.GetProviderId(Utils.ProviderId);
@@ -44,7 +24,7 @@ namespace Jellyfin.Plugin.Kinopoisk
if (!int.TryParse(kinopoiskIdStr, out result))
{
- logger.LogDebug($"Can't parse ProviderId to int, skipping ({kinopoiskIdStr})");
+ logger.LogWarning($"Can't parse Kinopoisk ProviderId to int, skipping ({kinopoiskIdStr})");
result = 0;
return false;
}
diff --git a/src/Kinopoisk.sln b/src/Kinopoisk.sln
index 3c4b484..021463e 100644
--- a/src/Kinopoisk.sln
+++ b/src/Kinopoisk.sln
@@ -1,48 +1,48 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-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.Tests", "Jellyfin.Plugin.Kinopoisk.Tests\Jellyfin.Plugin.Kinopoisk.Tests.csproj", "{7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x64.ActiveCfg = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x64.Build.0 = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x86.ActiveCfg = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x86.Build.0 = Debug|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|Any CPU.Build.0 = Release|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x64.ActiveCfg = Release|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x64.Build.0 = Release|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x86.ActiveCfg = Release|Any CPU
- {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x86.Build.0 = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x64.ActiveCfg = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x64.Build.0 = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x86.ActiveCfg = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x86.Build.0 = Debug|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|Any CPU.Build.0 = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x64.ActiveCfg = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x64.Build.0 = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x86.ActiveCfg = Release|Any CPU
- {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x86.Build.0 = Release|Any CPU
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+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}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|Any CPU = Release|Any CPU
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x64.Build.0 = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Debug|x86.Build.0 = Debug|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x64.ActiveCfg = Release|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x64.Build.0 = Release|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x86.ActiveCfg = Release|Any CPU
+ {C9335ABD-972B-4FF9-B564-72D9FF7122A2}.Release|x86.Build.0 = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x64.Build.0 = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Debug|x86.Build.0 = Debug|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x64.ActiveCfg = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x64.Build.0 = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x86.ActiveCfg = Release|Any CPU
+ {7DB17100-0B13-4713-AEDE-B4B9CA96E1CD}.Release|x86.Build.0 = Release|Any CPU
+ EndGlobalSection
+EndGlobal