更新 ChineseNfoRegistry 类,简化季号和集号的处理逻辑,增强错误日志记录,确保在处理 NFO 文件时更好地捕获异常情况。
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 14s
Docker Build & Deploy / Deploy to Production (push) Successful in 4s

This commit is contained in:
孙诚
2025-04-22 16:17:09 +08:00
parent 84e35fb631
commit 7a18330524

View File

@@ -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<bool> 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<bool> 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)