Optimize identity
This commit is contained in:
parent
4e31feecc6
commit
4f4433fe63
|
@ -45,5 +45,29 @@ namespace Jellyfin.Plugin.MetaShark.Core
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 转换中文数字
|
||||
/// </summary>
|
||||
public static string? ToChineseNumber(int? number)
|
||||
{
|
||||
if (number is null) return null;
|
||||
|
||||
var chineseNumberMap = new Dictionary<Char, Char>() {
|
||||
{'1','一'},
|
||||
{'2','二'},
|
||||
{'3','三'},
|
||||
{'4','四'},
|
||||
{'5','五'},
|
||||
{'6','六'},
|
||||
{'7','七'},
|
||||
{'8','八'},
|
||||
{'9','九'},
|
||||
{'0','零'},
|
||||
};
|
||||
|
||||
var numberArr = $"{number}".ToCharArray().Select(x => chineseNumberMap.ContainsKey(x) ? chineseNumberMap[x] : x).ToArray();
|
||||
return new string(numberArr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
protected readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
protected Regex regMetaSourcePrefix = new Regex(@"^\[.+\]", RegexOptions.Compiled);
|
||||
protected Regex regSeasonNameSuffix = new Regex(@"\s第[0-9一二三四五六七八九十]+?季$", RegexOptions.Compiled);
|
||||
protected Regex regSeasonNameSuffix = new Regex(@"\s第[0-9一二三四五六七八九十]+?季$|(?<![0-9a-zA-Z])\d$", RegexOptions.Compiled);
|
||||
|
||||
protected PluginConfiguration config
|
||||
{
|
||||
|
@ -212,6 +212,41 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
return null;
|
||||
}
|
||||
|
||||
public async Task<string?> GuestDoubanSeasonBySeasonNameAsync(string name, int? seasonNumber, CancellationToken cancellationToken)
|
||||
{
|
||||
if (seasonNumber is null or 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var chineseSeasonNumber = Utils.ToChineseNumber(seasonNumber);
|
||||
if (string.IsNullOrEmpty(chineseSeasonNumber))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var seasonName = $"{name}{seasonNumber}";
|
||||
var chineseSeasonName = $"{name} 第{chineseSeasonNumber}季";
|
||||
if (seasonNumber == 1)
|
||||
{
|
||||
seasonName = name;
|
||||
}
|
||||
this.Log($"GuestDoubanSeasonBySeasonNameAsync of [name]: {seasonName} 或 {chineseSeasonName}");
|
||||
|
||||
// 通过名称精确匹配
|
||||
var result = await this._doubanApi.SearchAsync(name, cancellationToken).ConfigureAwait(false);
|
||||
var item = result.Where(x => x.Category == "电视剧" && x.Rating > 0 && (x.Name == seasonName || x.Name == chineseSeasonName)).FirstOrDefault();
|
||||
if (item != null && !string.IsNullOrEmpty(item.Sid))
|
||||
{
|
||||
this.Log($"Found douban [id]: {item.Name}({item.Sid})");
|
||||
return item.Sid;
|
||||
}
|
||||
|
||||
|
||||
this.Log($"GuestDoubanSeasonBySeasonNameAsync not found!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected async Task<string?> GuestByTmdbAsync(string name, int? year, ItemLookupInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
|
|
|
@ -165,7 +165,17 @@ namespace Jellyfin.Plugin.MetaShark.Providers
|
|||
|
||||
if (!string.IsNullOrEmpty(seriesName) && seasonYear > 0)
|
||||
{
|
||||
return await this.GuestDoubanSeasonByYearAsync(seriesName, seasonYear, cancellationToken).ConfigureAwait(false);
|
||||
var seasonSid = await this.GuestDoubanSeasonByYearAsync(seriesName, seasonYear, cancellationToken).ConfigureAwait(false);
|
||||
if (!string.IsNullOrEmpty(seasonSid))
|
||||
{
|
||||
return seasonSid;
|
||||
}
|
||||
}
|
||||
|
||||
// 通过季名匹配douban id,作为关闭tmdb api/api超时的后备方法使用
|
||||
if (!string.IsNullOrEmpty(seriesName) && seasonNumber.HasValue && seasonNumber > 0)
|
||||
{
|
||||
return await this.GuestDoubanSeasonBySeasonNameAsync(seriesName, seasonNumber, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue