更新 ChineseNfoRegistry 类,简化季号和集号的处理逻辑,增强错误日志记录,确保在处理 NFO 文件时更好地捕获异常情况。
This commit is contained in:
@@ -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,18 +150,12 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
||||
|
||||
foreach (var season in seasonNfos)
|
||||
{
|
||||
var seasonNumber = season
|
||||
.Split("Season ").LastOrDefault()
|
||||
?.Split(Path.DirectorySeparatorChar)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (int.TryParse(seasonNumber, out var seasonNumberInt))
|
||||
{
|
||||
ctn.seasonNumber = seasonNumberInt;
|
||||
ctn.seasonNfoPath = season;
|
||||
}
|
||||
|
||||
await HandleSeason();
|
||||
if (await HandleSeason() == false)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var episodeNfos = Directory
|
||||
.GetFiles(Path.GetDirectoryName(season) ?? string.Empty, "*.nfo", SearchOption.AllDirectories)
|
||||
@@ -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,13 +474,26 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation("开始处理 Episode");
|
||||
|
||||
var isLockedNode = episodeXml.SelectSingleNode("//locked");
|
||||
|
||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||
{
|
||||
_logger.LogInformation("episodeNumber is equal");
|
||||
_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);
|
||||
|
||||
Reference in New Issue
Block a user