Refactor ChineseNfoRegistry for improved readability and consistency
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 12s
Docker Build & Deploy / Deploy to Production (push) Successful in 4s

This commit is contained in:
孙诚
2025-03-19 14:03:33 +08:00
parent df1d36975d
commit adb69f6ef4

View File

@@ -19,12 +19,12 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
{ {
_configuration = configuration; _configuration = configuration;
_logger = logger; _logger = logger;
var httpClientHandler = new HttpClientHandler(); var httpClientHandler = new HttpClientHandler();
var proxyAddress = _configuration["ChineseNfo:HttpProxy"]; var proxyAddress = _configuration["ChineseNfo:HttpProxy"];
if(string.IsNullOrEmpty(proxyAddress) == false) if (string.IsNullOrEmpty(proxyAddress) == false)
{ {
httpClientHandler.Proxy = string.IsNullOrEmpty(proxyAddress) ? null : new WebProxy(proxyAddress, false); httpClientHandler.Proxy = string.IsNullOrEmpty(proxyAddress) ? null : new WebProxy(proxyAddress, false);
httpClientHandler.UseProxy = !string.IsNullOrEmpty(proxyAddress); httpClientHandler.UseProxy = !string.IsNullOrEmpty(proxyAddress);
@@ -32,7 +32,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
_client = new HttpClient(httpClientHandler); _client = new HttpClient(httpClientHandler);
_client.BaseAddress = new Uri("https://api.themoviedb.org"); _client.BaseAddress = new Uri("https://api.themoviedb.org");
Schedule(() => Job(true, true)).ToRunEvery(1).Days(); Schedule(() => Job(true, true)).ToRunEvery(1).Days();
} }
@@ -62,7 +62,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
var successCount = 0; var successCount = 0;
var failedCount = 0; var failedCount = 0;
var skippedCount = 0; var skippedCount = 0;
// 扫描 tvshow.nfo 文件 // 扫描 tvshow.nfo 文件
var tvShowFiles = Directory.GetFiles(tvFolder, "tvshow.nfo", SearchOption.AllDirectories); var tvShowFiles = Directory.GetFiles(tvFolder, "tvshow.nfo", SearchOption.AllDirectories);
@@ -209,7 +209,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
} }
successCount++; successCount++;
// 添加一个已完成节点 // 添加一个已完成节点
if (completedNode == null) if (completedNode == null)
{ {
@@ -243,17 +243,17 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
await Task.Delay(10000); await Task.Delay(10000);
} }
} }
await WxNotify.SendCommonAsync($"ChineseNfoRegistry.Job() success: {successCount}, failed: {failedCount}, skipped: {skippedCount}"); await WxNotify.SendCommonAsync($"ChineseNfoRegistry.Job() success: {successCount}, failed: {failedCount}, skipped: {skippedCount}");
} }
private async Task<JsonObject?> GetTmdbEpisode(int tmdbId, int season, int episode) private async Task<JsonObject?> GetTmdbEpisode(int tmdbId, int season, int episode)
{ {
const string episodeUrl = "/3/tv/{0}/season/{1}/episode/{2}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN";
var requestUrl = string.Format(episodeUrl, tmdbId, season, episode);
try try
{ {
const string episodeUrl = "/3/tv/{0}/season/{1}/episode/{2}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN";
var requestUrl = string.Format(episodeUrl, tmdbId, season, episode);
var response = await _client.GetAsync(requestUrl); var response = await _client.GetAsync(requestUrl);
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {
@@ -267,7 +267,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine($"{tmdbId} & {season} & {episode} & {e}"); Console.WriteLine($"{requestUrl} \r {e}");
return null; return null;
} }
} }