From 7a18330524d05f99e3220bf15fad484854bb440f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Tue, 22 Apr 2025 16:17:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ChineseNfoRegistry=20?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E7=AE=80=E5=8C=96=E5=AD=A3=E5=8F=B7=E5=92=8C?= =?UTF-8?q?=E9=9B=86=E5=8F=B7=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=BC=BA=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8=E5=A4=84?= =?UTF-8?q?=E7=90=86=20NFO=20=E6=96=87=E4=BB=B6=E6=97=B6=E6=9B=B4=E5=A5=BD?= =?UTF-8?q?=E5=9C=B0=E6=8D=95=E8=8E=B7=E5=BC=82=E5=B8=B8=E6=83=85=E5=86=B5?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Service/Jobs/ChineseNfoRegistry.cs | 163 +++++++++++++------------ 1 file changed, 84 insertions(+), 79 deletions(-) diff --git a/src/Service/Jobs/ChineseNfoRegistry.cs b/src/Service/Jobs/ChineseNfoRegistry.cs index 3cbb61d..5610ed9 100644 --- a/src/Service/Jobs/ChineseNfoRegistry.cs +++ b/src/Service/Jobs/ChineseNfoRegistry.cs @@ -113,7 +113,10 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry { ctn.tvNfoPath = tv; - await HandleTv(); + if (await HandleTv() == false) + { + continue; + } var seasonNfos = Directory.GetFiles(Path.GetDirectoryName(tv) ?? string.Empty, "season.nfo", SearchOption.AllDirectories); @@ -147,19 +150,13 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry foreach (var season in seasonNfos) { - var seasonNumber = season - .Split("Season ").LastOrDefault() - ?.Split(Path.DirectorySeparatorChar) - .FirstOrDefault(); + ctn.seasonNfoPath = season; - if (int.TryParse(seasonNumber, out var seasonNumberInt)) + if (await HandleSeason() == false) { - ctn.seasonNumber = seasonNumberInt; - ctn.seasonNfoPath = season; + continue; } - await HandleSeason(); - var episodeNfos = Directory .GetFiles(Path.GetDirectoryName(season) ?? string.Empty, "*.nfo", SearchOption.AllDirectories) .Where(x => !x.EndsWith("season.nfo")) @@ -175,7 +172,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry } - async Task HandleTv() + async Task HandleTv() { if (!string.IsNullOrEmpty(requestPath)) { @@ -183,23 +180,39 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry if (!ctn.tvNfoPath.Contains(latestPath)) { - return; + return false; } - - _logger.LogInformation("tv is contains path"); } + _logger.LogInformation("开始处理 TV"); + var nfoContent = File.ReadAllText(ctn.tvNfoPath); var tvXml = new XmlDocument(); tvXml.LoadXml(nfoContent); + var uniqueIdNode = tvXml.SelectSingleNode("//uniqueid[@type='tmdb']"); + + if (uniqueIdNode == null) + { + _logger.LogError("uniqueIdNode is null"); + return false; + } + + if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId)) + { + _logger.LogError("tmdbId is null"); + return false; + } + + ctn.tvId = tmdbId; + var isLockedNode = tvXml.SelectSingleNode("//locked"); if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked) { _logger.LogInformation("tvNfo is locked"); - return; + return true; } var isCompletedNode = tvXml.SelectSingleNode("//completed"); @@ -207,21 +220,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted) { _logger.LogInformation("tvNfo is completed"); - return; - } - - var uniqueIdNode = tvXml.SelectSingleNode("//uniqueid[@type='tmdb']"); - - if (uniqueIdNode == null) - { - _logger.LogError("uniqueIdNode is null"); - return; - } - - if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId)) - { - _logger.LogError("tmdbId is null"); - return; + return true; } var tvInfo = await GetTmdbTv(ctn.tvNfoPath, tmdbId); @@ -229,7 +228,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry if (tvInfo == null) { _logger.LogError("tvInfo is null"); - return; + return true; } if (tvInfo["name"] != null) @@ -312,19 +311,16 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry // 保存 tvXml.Save(ctn.tvNfoPath); + + return true; } - async Task HandleSeason() + async Task HandleSeason() { - if (ctn.seasonNumber == 0 || string.IsNullOrEmpty(ctn.seasonNfoPath)) + if (string.IsNullOrEmpty(ctn.seasonNfoPath)) { _logger.LogError("seasonNfoPath is null or empty"); - return; - } - - if (requestEpisodeNumber != null && ctn.episodeNumber != requestEpisodeNumber) - { - return; + return false; } var nfoContent = File.ReadAllText(ctn.seasonNfoPath); @@ -332,34 +328,43 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry var seasonXml = new XmlDocument(); seasonXml.LoadXml(nfoContent); + var seasonNumberNode = seasonXml.SelectSingleNode("//seasonnumber"); + + if (seasonNumberNode == null) + { + _logger.LogError("seasonNumberNode is null"); + return false; + } + + if (!int.TryParse(seasonNumberNode.InnerText, out var seasonNumber)) + { + _logger.LogError("seasonNumber is null"); + return false; + } + + ctn.seasonNumber = seasonNumber; + + if (requestSeasonNumber != null && requestSeasonNumber != seasonNumber) + { + return false; + } + + _logger.LogInformation("开始处理 Season"); + var isLockedNode = seasonXml.SelectSingleNode("//locked"); if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked) { - _logger.LogInformation("tvNfo is locked"); - return; + _logger.LogInformation("seasonNfo is locked"); + return true; } var isCompletedNode = seasonXml.SelectSingleNode("//completed"); if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted) { - _logger.LogInformation("tvNfo is completed"); - return; - } - - var seasonNumberNode = seasonXml.SelectSingleNode("//seasonnumber"); - - if (seasonNumberNode == null) - { - _logger.LogError("seasonNumberNode is null"); - return; - } - - if (!int.TryParse(seasonNumberNode.InnerText, out var seasonNumber)) - { - _logger.LogError("seasonNumber is null"); - return; + _logger.LogInformation("seasonNfo is completed"); + return true; } var seasonInfo = await GetTmdbSeason(ctn); @@ -367,7 +372,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry if (seasonInfo == null) { _logger.LogError("seasonInfo is null"); - return; + return true; } var titleNode = seasonXml.SelectSingleNode("//sorttitle"); @@ -425,6 +430,8 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry } seasonXml.Save(ctn.seasonNfoPath); + + return true; } async Task HandleEpisode() @@ -440,22 +447,6 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry var episodeXml = new XmlDocument(); episodeXml.LoadXml(nfoContent); - var isLockedNode = episodeXml.SelectSingleNode("//locked"); - - if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked) - { - _logger.LogInformation("tvNfo is locked"); - return; - } - - var isCompletedNode = episodeXml.SelectSingleNode("//completed"); - - if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted) - { - _logger.LogInformation("tvNfo is completed"); - return; - } - var episodeNumberNode = episodeXml.SelectSingleNode("//episode"); if (episodeNumberNode == null) @@ -472,6 +463,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry ctn.episodeNumber = episodeNumber; + if (!string.IsNullOrEmpty(requestPath)) { if (requestSeasonNumber != null) @@ -482,15 +474,28 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry { return; } - else - { - _logger.LogInformation("episodeNumber is equal"); - return; - } } } } + _logger.LogInformation("开始处理 Episode"); + + var isLockedNode = episodeXml.SelectSingleNode("//locked"); + + if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked) + { + _logger.LogInformation("episodeNfo is locked"); + return; + } + + var isCompletedNode = episodeXml.SelectSingleNode("//completed"); + + if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted) + { + _logger.LogInformation("episodeNfo is completed"); + return; + } + var episodeInfo = await GetTmdbEpisode(ctn); if (episodeInfo == null)