更新 ChineseNfoRegistry 类,简化季号和集号的处理逻辑,增强错误日志记录,确保在处理 NFO 文件时更好地捕获异常情况。
This commit is contained in:
@@ -113,7 +113,10 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
{
|
{
|
||||||
ctn.tvNfoPath = tv;
|
ctn.tvNfoPath = tv;
|
||||||
|
|
||||||
await HandleTv();
|
if (await HandleTv() == false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var seasonNfos = Directory.GetFiles(Path.GetDirectoryName(tv) ?? string.Empty, "season.nfo", SearchOption.AllDirectories);
|
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)
|
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;
|
ctn.seasonNfoPath = season;
|
||||||
}
|
|
||||||
|
|
||||||
await HandleSeason();
|
if (await HandleSeason() == false)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var episodeNfos = Directory
|
var episodeNfos = Directory
|
||||||
.GetFiles(Path.GetDirectoryName(season) ?? string.Empty, "*.nfo", SearchOption.AllDirectories)
|
.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))
|
if (!string.IsNullOrEmpty(requestPath))
|
||||||
{
|
{
|
||||||
@@ -183,23 +180,39 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (!ctn.tvNfoPath.Contains(latestPath))
|
if (!ctn.tvNfoPath.Contains(latestPath))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("tv is contains path");
|
_logger.LogInformation("开始处理 TV");
|
||||||
}
|
|
||||||
|
|
||||||
var nfoContent = File.ReadAllText(ctn.tvNfoPath);
|
var nfoContent = File.ReadAllText(ctn.tvNfoPath);
|
||||||
|
|
||||||
var tvXml = new XmlDocument();
|
var tvXml = new XmlDocument();
|
||||||
tvXml.LoadXml(nfoContent);
|
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");
|
var isLockedNode = tvXml.SelectSingleNode("//locked");
|
||||||
|
|
||||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("tvNfo is locked");
|
_logger.LogInformation("tvNfo is locked");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isCompletedNode = tvXml.SelectSingleNode("//completed");
|
var isCompletedNode = tvXml.SelectSingleNode("//completed");
|
||||||
@@ -207,21 +220,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("tvNfo is completed");
|
_logger.LogInformation("tvNfo is completed");
|
||||||
return;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var tvInfo = await GetTmdbTv(ctn.tvNfoPath, tmdbId);
|
var tvInfo = await GetTmdbTv(ctn.tvNfoPath, tmdbId);
|
||||||
@@ -229,7 +228,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
if (tvInfo == null)
|
if (tvInfo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("tvInfo is null");
|
_logger.LogError("tvInfo is null");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tvInfo["name"] != null)
|
if (tvInfo["name"] != null)
|
||||||
@@ -312,19 +311,16 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
tvXml.Save(ctn.tvNfoPath);
|
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");
|
_logger.LogError("seasonNfoPath is null or empty");
|
||||||
return;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (requestEpisodeNumber != null && ctn.episodeNumber != requestEpisodeNumber)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nfoContent = File.ReadAllText(ctn.seasonNfoPath);
|
var nfoContent = File.ReadAllText(ctn.seasonNfoPath);
|
||||||
@@ -332,34 +328,43 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
var seasonXml = new XmlDocument();
|
var seasonXml = new XmlDocument();
|
||||||
seasonXml.LoadXml(nfoContent);
|
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");
|
var isLockedNode = seasonXml.SelectSingleNode("//locked");
|
||||||
|
|
||||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("tvNfo is locked");
|
_logger.LogInformation("seasonNfo is locked");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var isCompletedNode = seasonXml.SelectSingleNode("//completed");
|
var isCompletedNode = seasonXml.SelectSingleNode("//completed");
|
||||||
|
|
||||||
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("tvNfo is completed");
|
_logger.LogInformation("seasonNfo is completed");
|
||||||
return;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var seasonInfo = await GetTmdbSeason(ctn);
|
var seasonInfo = await GetTmdbSeason(ctn);
|
||||||
@@ -367,7 +372,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
if (seasonInfo == null)
|
if (seasonInfo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("seasonInfo is null");
|
_logger.LogError("seasonInfo is null");
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var titleNode = seasonXml.SelectSingleNode("//sorttitle");
|
var titleNode = seasonXml.SelectSingleNode("//sorttitle");
|
||||||
@@ -425,6 +430,8 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
seasonXml.Save(ctn.seasonNfoPath);
|
seasonXml.Save(ctn.seasonNfoPath);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task HandleEpisode()
|
async Task HandleEpisode()
|
||||||
@@ -440,22 +447,6 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
var episodeXml = new XmlDocument();
|
var episodeXml = new XmlDocument();
|
||||||
episodeXml.LoadXml(nfoContent);
|
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");
|
var episodeNumberNode = episodeXml.SelectSingleNode("//episode");
|
||||||
|
|
||||||
if (episodeNumberNode == null)
|
if (episodeNumberNode == null)
|
||||||
@@ -472,6 +463,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
ctn.episodeNumber = episodeNumber;
|
ctn.episodeNumber = episodeNumber;
|
||||||
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(requestPath))
|
if (!string.IsNullOrEmpty(requestPath))
|
||||||
{
|
{
|
||||||
if (requestSeasonNumber != null)
|
if (requestSeasonNumber != null)
|
||||||
@@ -482,13 +474,26 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
{
|
{
|
||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
var isCompletedNode = episodeXml.SelectSingleNode("//completed");
|
||||||
|
|
||||||
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("episodeNfo is completed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var episodeInfo = await GetTmdbEpisode(ctn);
|
var episodeInfo = await GetTmdbEpisode(ctn);
|
||||||
|
|||||||
Reference in New Issue
Block a user