更新 IChineseNfoRegistry 和 ChineseNfoRegistry 类,修改 Job 方法的季号和集号参数类型为 int,增强类型安全性;简化日志记录,减少冗余信息,提高可读性。
This commit is contained in:
@@ -4,8 +4,8 @@ public interface IChineseNfoRegistry
|
|||||||
{
|
{
|
||||||
void Job(
|
void Job(
|
||||||
string? path = null,
|
string? path = null,
|
||||||
string? seasonNumber = null,
|
int? seasonNumber = null,
|
||||||
string? episodeNumber = null,
|
int? episodeNumber = null,
|
||||||
bool ignoreLocked = false,
|
bool ignoreLocked = false,
|
||||||
bool ignoreCompleted = false
|
bool ignoreCompleted = false
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using Core;
|
||||||
using FluentScheduler;
|
using FluentScheduler;
|
||||||
using FreeSql;
|
using FreeSql;
|
||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
@@ -50,8 +51,8 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
public void Job(
|
public void Job(
|
||||||
string? path = null,
|
string? path = null,
|
||||||
string? seasonNumber = null,
|
int? seasonNumber = null,
|
||||||
string? episodeNumber = null,
|
int? episodeNumber = null,
|
||||||
bool ignoreLocked = false,
|
bool ignoreLocked = false,
|
||||||
bool ignoreCompleted = false
|
bool ignoreCompleted = false
|
||||||
)
|
)
|
||||||
@@ -72,14 +73,15 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError(e, "ChineseNfoRegistry.Job() error");
|
_logger.LogError(e, "error");
|
||||||
|
WxNotify.SendCommonAsync($"ChineseNfoRegistry.Job() 执行失败 {e.Message}").Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task JobExecute(
|
private async Task JobExecute(
|
||||||
string? requestPath = null,
|
string? requestPath = null,
|
||||||
string? requestSeasonNumber = null,
|
int? requestSeasonNumber = null,
|
||||||
string? requestEpisodeNumber = null,
|
int? requestEpisodeNumber = null,
|
||||||
bool ignoreLocked = false,
|
bool ignoreLocked = false,
|
||||||
bool ignoreCompleted = false)
|
bool ignoreCompleted = false)
|
||||||
{
|
{
|
||||||
@@ -87,7 +89,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(tvFolder))
|
if (string.IsNullOrEmpty(tvFolder))
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tvFolder is null or empty");
|
_logger.LogError("tvFolder is null or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,34 +103,18 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (tvNfos.Length == 0)
|
if (tvNfos.Length == 0)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tvNfo is null or empty");
|
_logger.LogError("tvNfo is null or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ctn = new ChineseNfoContent();
|
||||||
|
|
||||||
foreach (var tv in tvNfos)
|
foreach (var tv in tvNfos)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(requestPath))
|
ctn.tvNfoPath = tv;
|
||||||
{
|
|
||||||
var latestPath = Path.GetFileName(requestPath) ?? string.Empty;
|
|
||||||
|
|
||||||
if (!tv.Contains(latestPath))
|
await HandleTv();
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tv is contains path");
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await HandleTv(tv);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError(e, "ChineseNfoRegistry.Job() HandleTv() error");
|
|
||||||
}
|
|
||||||
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);
|
||||||
|
|
||||||
// 如果seasonNfos为空,则创建
|
// 如果seasonNfos为空,则创建
|
||||||
@@ -162,29 +148,18 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
foreach (var season in seasonNfos)
|
foreach (var season in seasonNfos)
|
||||||
{
|
{
|
||||||
var seasonNumber = season
|
var seasonNumber = season
|
||||||
.Split("Season ")[1]
|
.Split("Season ").LastOrDefault()
|
||||||
.Split(Path.DirectorySeparatorChar)[0];
|
?.Split(Path.DirectorySeparatorChar)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
try
|
if (int.TryParse(seasonNumber, out var seasonNumberInt))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(requestSeasonNumber))
|
ctn.seasonNumber = seasonNumberInt;
|
||||||
{
|
ctn.seasonNfoPath = season;
|
||||||
if (seasonNumber != requestSeasonNumber)
|
}
|
||||||
{
|
|
||||||
continue;
|
await HandleSeason();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() seasonNumber is equal");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await HandleSeason(tv, season);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError(e, "ChineseNfoRegistry.Job() HandleSeason() error");
|
|
||||||
}
|
|
||||||
var episodeNfos = Directory
|
var episodeNfos = Directory
|
||||||
.GetFiles(Path.GetDirectoryName(season) ?? string.Empty, "*.nfo", SearchOption.AllDirectories)
|
.GetFiles(Path.GetDirectoryName(season) ?? string.Empty, "*.nfo", SearchOption.AllDirectories)
|
||||||
.Where(x => !x.EndsWith("season.nfo"))
|
.Where(x => !x.EndsWith("season.nfo"))
|
||||||
@@ -192,39 +167,29 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
foreach (var episode in episodeNfos)
|
foreach (var episode in episodeNfos)
|
||||||
{
|
{
|
||||||
try
|
ctn.episodeNfoPath = episode;
|
||||||
{
|
|
||||||
var split = $"S{(seasonNumber.Length == 1 ? $"0{seasonNumber}" : seasonNumber)}E";
|
|
||||||
var episodeNumber = Path.GetFileName(episode)
|
|
||||||
.Split(split, StringSplitOptions.None)[1]
|
|
||||||
.Split(" - ", StringSplitOptions.None)[0];
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(requestEpisodeNumber))
|
await HandleEpisode();
|
||||||
{
|
|
||||||
if (int.Parse(episodeNumber).ToString() != requestEpisodeNumber)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() episodeNumber is equal");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await HandleEpisode(tv, season, episode);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
_logger.LogError(e, "ChineseNfoRegistry.Job() episodeNfo is null or empty");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async Task HandleTv(string tvNfo)
|
async Task HandleTv()
|
||||||
{
|
{
|
||||||
var nfoContent = File.ReadAllText(tvNfo);
|
if (!string.IsNullOrEmpty(requestPath))
|
||||||
|
{
|
||||||
|
var latestPath = Path.GetFileName(requestPath) ?? string.Empty;
|
||||||
|
|
||||||
|
if (!ctn.tvNfoPath.Contains(latestPath))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("tv is contains path");
|
||||||
|
}
|
||||||
|
|
||||||
|
var nfoContent = File.ReadAllText(ctn.tvNfoPath);
|
||||||
|
|
||||||
var tvXml = new XmlDocument();
|
var tvXml = new XmlDocument();
|
||||||
tvXml.LoadXml(nfoContent);
|
tvXml.LoadXml(nfoContent);
|
||||||
@@ -233,7 +198,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is locked");
|
_logger.LogInformation("tvNfo is locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +206,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is completed");
|
_logger.LogInformation("tvNfo is completed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,21 +214,21 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (uniqueIdNode == null)
|
if (uniqueIdNode == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() uniqueIdNode is null");
|
_logger.LogError("uniqueIdNode is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId))
|
if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId))
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tmdbId is null");
|
_logger.LogError("tmdbId is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var tvInfo = await GetTmdbTv(tvNfo, tmdbId);
|
var tvInfo = await GetTmdbTv(ctn.tvNfoPath, tmdbId);
|
||||||
|
|
||||||
if (tvInfo == null)
|
if (tvInfo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tvInfo is null");
|
_logger.LogError("tvInfo is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +246,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
sorttitleNode.InnerXml = $"<![CDATA[{tvInfo["name"]}]]>";
|
sorttitleNode.InnerXml = $"<![CDATA[{tvInfo["name"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvInfo: {tvInfo}", tvInfo["name"]);
|
_logger.LogInformation("tvInfo: {tvInfo}", tvInfo["name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tvInfo["overview"] != null)
|
if (tvInfo["overview"] != null)
|
||||||
@@ -298,16 +263,16 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
outlineNode.InnerXml = $"<![CDATA[{tvInfo["overview"]}]]>";
|
outlineNode.InnerXml = $"<![CDATA[{tvInfo["overview"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvInfo: {tvInfo}", tvInfo["overview"]);
|
_logger.LogInformation("tvInfo: {tvInfo}", tvInfo["overview"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tvInfo["poster_path"] != null)
|
if (tvInfo["poster_path"] != null)
|
||||||
{
|
{
|
||||||
var posterPath = tvInfo["poster_path"]!.ToString();
|
var posterPath = tvInfo["poster_path"]!.ToString();
|
||||||
var image = await GetTmdbImage(tvNfo, posterPath);
|
var image = await GetTmdbImage(ctn.tvNfoPath, posterPath);
|
||||||
if (image != null)
|
if (image != null)
|
||||||
{
|
{
|
||||||
var imagePath = Path.Combine(Path.GetDirectoryName(tvNfo) ?? string.Empty, "poster" + Path.GetExtension(posterPath));
|
var imagePath = Path.Combine(Path.GetDirectoryName(ctn.tvNfoPath) ?? string.Empty, "poster" + Path.GetExtension(posterPath));
|
||||||
await File.WriteAllBytesAsync(imagePath, image);
|
await File.WriteAllBytesAsync(imagePath, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -321,7 +286,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tmdbId: {tmdbId}, name: {name}", tmdbId, tvInfo["name"]?.ToString());
|
_logger.LogInformation("tmdbId: {tmdbId}, name: {name}", tmdbId, tvInfo["name"]?.ToString());
|
||||||
|
|
||||||
if (isLockedNode != null)
|
if (isLockedNode != null)
|
||||||
{
|
{
|
||||||
@@ -346,31 +311,23 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
tvXml.Save(tvNfo);
|
tvXml.Save(ctn.tvNfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task HandleSeason(string tvNfo, string seasonNfo)
|
async Task HandleSeason()
|
||||||
{
|
{
|
||||||
var tvNfoContent = File.ReadAllText(tvNfo);
|
if (ctn.seasonNumber == 0 || string.IsNullOrEmpty(ctn.seasonNfoPath))
|
||||||
|
|
||||||
var tvXml = new XmlDocument();
|
|
||||||
tvXml.LoadXml(tvNfoContent);
|
|
||||||
|
|
||||||
var uniqueIdNode = tvXml.SelectSingleNode("//uniqueid[@type='tmdb']");
|
|
||||||
|
|
||||||
if (uniqueIdNode == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() uniqueIdNode is null");
|
_logger.LogError("seasonNfoPath is null or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId))
|
if (requestEpisodeNumber != null && ctn.episodeNumber != requestEpisodeNumber)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tmdbId is null");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var nfoContent = File.ReadAllText(seasonNfo);
|
var nfoContent = File.ReadAllText(ctn.seasonNfoPath);
|
||||||
|
|
||||||
var seasonXml = new XmlDocument();
|
var seasonXml = new XmlDocument();
|
||||||
seasonXml.LoadXml(nfoContent);
|
seasonXml.LoadXml(nfoContent);
|
||||||
@@ -379,7 +336,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is locked");
|
_logger.LogInformation("tvNfo is locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,7 +344,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is completed");
|
_logger.LogInformation("tvNfo is completed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,68 +352,52 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (seasonNumberNode == null)
|
if (seasonNumberNode == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() seasonNumberNode is null");
|
_logger.LogError("seasonNumberNode is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(seasonNumberNode.InnerText, out var seasonNumber))
|
if (!int.TryParse(seasonNumberNode.InnerText, out var seasonNumber))
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() seasonNumber is null");
|
_logger.LogError("seasonNumber is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(requestPath))
|
var seasonInfo = await GetTmdbSeason(ctn);
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(requestSeasonNumber))
|
|
||||||
{
|
|
||||||
if (seasonNumber != int.Parse(requestSeasonNumber))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() seasonNumber is equal");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var seasonInfo = await GetTmdbSeason(seasonNfo, tmdbId, seasonNumber);
|
|
||||||
|
|
||||||
if (seasonInfo == null)
|
if (seasonInfo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() seasonInfo is null");
|
_logger.LogError("seasonInfo is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var titleNode = seasonXml.SelectSingleNode("//sorttitle");
|
var titleNode = seasonXml.SelectSingleNode("//sorttitle");
|
||||||
if (titleNode != null && seasonInfo["name"] != null)
|
if (titleNode != null && seasonInfo["name"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() seasonInfo: {seasonInfo}", seasonInfo["name"]);
|
_logger.LogInformation("seasonInfo: {seasonInfo}", seasonInfo["name"]);
|
||||||
titleNode.InnerXml = $"<![CDATA[{seasonInfo["name"]}]]>";
|
titleNode.InnerXml = $"<![CDATA[{seasonInfo["name"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var plotNode = seasonXml.SelectSingleNode("//plot");
|
var plotNode = seasonXml.SelectSingleNode("//plot");
|
||||||
if (plotNode != null && seasonInfo["overview"] != null)
|
if (plotNode != null && seasonInfo["overview"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() seasonInfo: {seasonInfo}", seasonInfo["overview"]);
|
_logger.LogInformation("seasonInfo: {seasonInfo}", seasonInfo["overview"]);
|
||||||
plotNode.InnerXml = $"<![CDATA[{seasonInfo["overview"]}]]>";
|
plotNode.InnerXml = $"<![CDATA[{seasonInfo["overview"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var outlineNode = seasonXml.SelectSingleNode("//outline");
|
var outlineNode = seasonXml.SelectSingleNode("//outline");
|
||||||
if (outlineNode != null && seasonInfo["overview"] != null)
|
if (outlineNode != null && seasonInfo["overview"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() seasonInfo: {seasonInfo}", seasonInfo["overview"]);
|
_logger.LogInformation("seasonInfo: {seasonInfo}", seasonInfo["overview"]);
|
||||||
outlineNode.InnerXml = $"<![CDATA[{seasonInfo["overview"]}]]>";
|
outlineNode.InnerXml = $"<![CDATA[{seasonInfo["overview"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var poster_path = seasonInfo["poster_path"]?.ToString();
|
var poster_path = seasonInfo["poster_path"]?.ToString();
|
||||||
if (poster_path != null)
|
if (poster_path != null)
|
||||||
{
|
{
|
||||||
var image = await GetTmdbImage(seasonNfo, poster_path);
|
var image = await GetTmdbImage(ctn.seasonNfoPath, poster_path);
|
||||||
if (image != null)
|
if (image != null)
|
||||||
{
|
{
|
||||||
var imagePath = Path.Combine(Path.GetDirectoryName(tvNfo) ?? string.Empty, "season" + seasonNumber.ToString("D2") + "-poster" + Path.GetExtension(poster_path));
|
var imagePath = Path.Combine(Path.GetDirectoryName(ctn.tvNfoPath) ?? string.Empty, "season" + seasonNumber.ToString("D2") + "-poster" + Path.GetExtension(poster_path));
|
||||||
await File.WriteAllBytesAsync(imagePath, image);
|
await File.WriteAllBytesAsync(imagePath, image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -483,50 +424,18 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
isCompletedNode.InnerText = "true";
|
isCompletedNode.InnerText = "true";
|
||||||
}
|
}
|
||||||
|
|
||||||
seasonXml.Save(seasonNfo);
|
seasonXml.Save(ctn.seasonNfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task HandleEpisode(string tvNfo, string seasonNfo, string episodeNfo)
|
async Task HandleEpisode()
|
||||||
{
|
{
|
||||||
var tvNfoContent = File.ReadAllText(tvNfo);
|
if (string.IsNullOrEmpty(ctn.episodeNfoPath))
|
||||||
|
|
||||||
var tvXml = new XmlDocument();
|
|
||||||
tvXml.LoadXml(tvNfoContent);
|
|
||||||
|
|
||||||
var uniqueIdNode = tvXml.SelectSingleNode("//uniqueid[@type='tmdb']");
|
|
||||||
|
|
||||||
if (uniqueIdNode == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() uniqueIdNode is null");
|
_logger.LogError("episodeNfoPath is null or empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(uniqueIdNode.InnerText, out var tmdbId))
|
var nfoContent = File.ReadAllText(ctn.episodeNfoPath);
|
||||||
{
|
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() tmdbId is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var seasonNfoContent = File.ReadAllText(seasonNfo);
|
|
||||||
|
|
||||||
var seasonXml = new XmlDocument();
|
|
||||||
seasonXml.LoadXml(seasonNfoContent);
|
|
||||||
|
|
||||||
var seasonNumberNode = seasonXml.SelectSingleNode("//seasonnumber");
|
|
||||||
|
|
||||||
if (seasonNumberNode == null)
|
|
||||||
{
|
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() seasonNumberNode is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!int.TryParse(seasonNumberNode.InnerText, out var seasonNumber))
|
|
||||||
{
|
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() seasonNumber is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var nfoContent = File.ReadAllText(episodeNfo);
|
|
||||||
|
|
||||||
var episodeXml = new XmlDocument();
|
var episodeXml = new XmlDocument();
|
||||||
episodeXml.LoadXml(nfoContent);
|
episodeXml.LoadXml(nfoContent);
|
||||||
@@ -535,7 +444,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
if (isLockedNode != null && isLockedNode.InnerText == "true" && ignoreLocked)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is locked");
|
_logger.LogInformation("tvNfo is locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,70 +452,71 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
if (isCompletedNode != null && isCompletedNode.InnerText == "true" && ignoreCompleted)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tvNfo is completed");
|
_logger.LogInformation("tvNfo is completed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var episodeNumberNode = episodeXml.SelectSingleNode("//episode");
|
var episodeNumberNode = episodeXml.SelectSingleNode("//episode");
|
||||||
|
|
||||||
if (episodeNumberNode == null)
|
if (episodeNumberNode == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() episodeNumberNode is null");
|
_logger.LogError("episodeNumberNode is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!int.TryParse(episodeNumberNode.InnerText, out var episodeNumber))
|
if (!int.TryParse(episodeNumberNode.InnerText, out var episodeNumber))
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() episodeNumber is null");
|
_logger.LogError("episodeNumber is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctn.episodeNumber = episodeNumber;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(requestPath))
|
if (!string.IsNullOrEmpty(requestPath))
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(requestSeasonNumber))
|
if (requestSeasonNumber != null)
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(requestEpisodeNumber))
|
if (requestEpisodeNumber != null)
|
||||||
{
|
{
|
||||||
if (seasonNumber != int.Parse(requestSeasonNumber) || episodeNumber != int.Parse(requestEpisodeNumber))
|
if (episodeNumber != requestEpisodeNumber)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() episodeNumber is equal");
|
_logger.LogInformation("episodeNumber is equal");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var episodeInfo = await GetTmdbEpisode(episodeNfo, tmdbId, seasonNumber, episodeNumber);
|
var episodeInfo = await GetTmdbEpisode(ctn);
|
||||||
|
|
||||||
if (episodeInfo == null)
|
if (episodeInfo == null)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.Job() episodeInfo is null");
|
_logger.LogError("episodeInfo is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var titleNode = episodeXml.SelectSingleNode("//title");
|
var titleNode = episodeXml.SelectSingleNode("//title");
|
||||||
if (titleNode != null && episodeInfo["name"] != null)
|
if (titleNode != null && episodeInfo["name"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() episodeInfo: {episodeInfo}", episodeInfo["name"]);
|
_logger.LogInformation("episodeInfo: {episodeInfo}", episodeInfo["name"]);
|
||||||
titleNode.InnerXml = $"<![CDATA[{episodeInfo["name"]}]]>";
|
titleNode.InnerXml = $"<![CDATA[{episodeInfo["name"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var plotNode = episodeXml.SelectSingleNode("//plot");
|
var plotNode = episodeXml.SelectSingleNode("//plot");
|
||||||
if (plotNode != null && episodeInfo["overview"] != null)
|
if (plotNode != null && episodeInfo["overview"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() episodeInfo: {episodeInfo}", episodeInfo["overview"]);
|
_logger.LogInformation("episodeInfo: {episodeInfo}", episodeInfo["overview"]);
|
||||||
plotNode.InnerXml = $"<![CDATA[{episodeInfo["overview"]}]]>";
|
plotNode.InnerXml = $"<![CDATA[{episodeInfo["overview"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
var outlineNode = episodeXml.SelectSingleNode("//outline");
|
var outlineNode = episodeXml.SelectSingleNode("//outline");
|
||||||
if (outlineNode != null && episodeInfo["overview"] != null)
|
if (outlineNode != null && episodeInfo["overview"] != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() episodeInfo: {episodeInfo}", episodeInfo["overview"]);
|
_logger.LogInformation("episodeInfo: {episodeInfo}", episodeInfo["overview"]);
|
||||||
outlineNode.InnerXml = $"<![CDATA[{episodeInfo["overview"]}]]>";
|
outlineNode.InnerXml = $"<![CDATA[{episodeInfo["overview"]}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -619,7 +529,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() tmdbId: {tmdbId}, name: {name}", tmdbId, episodeInfo["name"]?.ToString());
|
_logger.LogInformation("tmdbId: {tmdbId}, name: {name}", ctn.tvId, episodeInfo["name"]?.ToString());
|
||||||
|
|
||||||
if (isLockedNode != null)
|
if (isLockedNode != null)
|
||||||
{
|
{
|
||||||
@@ -644,7 +554,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
episodeXml.Save(episodeNfo);
|
episodeXml.Save(ctn.episodeNfoPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task<string?> GetTmdbPersonName(
|
async Task<string?> GetTmdbPersonName(
|
||||||
@@ -702,7 +612,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
nameNode!.InnerXml = $"<![CDATA[{name}]]>";
|
nameNode!.InnerXml = $"<![CDATA[{name}]]>";
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ChineseNfoRegistry.Job() actor: {actor}", name);
|
_logger.LogInformation("actor: {actor}", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -896,12 +806,15 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<JObject?> GetTmdbSeason(
|
private async Task<JObject?> GetTmdbSeason(ChineseNfoContent ctn)
|
||||||
string path,
|
|
||||||
int tmdbId,
|
|
||||||
int seasonNumber)
|
|
||||||
{
|
{
|
||||||
var uniqueId = $"{tmdbId}-{seasonNumber}";
|
if (ctn.seasonNumber == 0 || string.IsNullOrEmpty(ctn.seasonNfoPath))
|
||||||
|
{
|
||||||
|
_logger.LogError("seasonNfoPath is null or empty");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var uniqueId = $"{ctn.tvId}-{ctn.seasonNumber}";
|
||||||
|
|
||||||
var record = await _freeSql.Select<TheMovieDbRecord>()
|
var record = await _freeSql.Select<TheMovieDbRecord>()
|
||||||
.Where(x => x.Type == TheMovieDbType.Season)
|
.Where(x => x.Type == TheMovieDbType.Season)
|
||||||
@@ -919,7 +832,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
UniqueId = uniqueId
|
UniqueId = uniqueId
|
||||||
};
|
};
|
||||||
|
|
||||||
var requestUrl = string.Format("/3/tv/{0}/season/{1}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN", tmdbId, seasonNumber);
|
var requestUrl = string.Format("/3/tv/{0}/season/{1}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN", ctn.tvId, ctn.seasonNumber);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -927,7 +840,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.GetTmdbSeason() 接口调用失败 {requestUrl} & {path} & {response.StatusCode}", requestUrl, path, response.StatusCode);
|
_logger.LogError("ChineseNfoRegistry.GetTmdbSeason() 接口调用失败 {requestUrl} & {path} & {response.StatusCode}", requestUrl, ctn.tvNfoPath, response.StatusCode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -943,18 +856,14 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.GetTmdbSeason() 接口调用失败 {requestUrl} & {path} \r {e}", requestUrl, path, e);
|
_logger.LogError("ChineseNfoRegistry.GetTmdbSeason() 接口调用失败 {requestUrl} & {path} \r {e}", requestUrl, ctn.tvNfoPath, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<JObject?> GetTmdbEpisode(
|
private async Task<JObject?> GetTmdbEpisode(ChineseNfoContent ctn)
|
||||||
string path,
|
|
||||||
int tmdbId,
|
|
||||||
int seasonNumber,
|
|
||||||
int episodeNumber)
|
|
||||||
{
|
{
|
||||||
var uniqueId = $"{tmdbId}-{seasonNumber}-{episodeNumber}";
|
var uniqueId = $"{ctn.tvId}-{ctn.seasonNumber}-{ctn.episodeNumber}";
|
||||||
|
|
||||||
var record = await _freeSql.Select<TheMovieDbRecord>()
|
var record = await _freeSql.Select<TheMovieDbRecord>()
|
||||||
.Where(x => x.Type == TheMovieDbType.Episode)
|
.Where(x => x.Type == TheMovieDbType.Episode)
|
||||||
@@ -972,7 +881,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
UniqueId = uniqueId
|
UniqueId = uniqueId
|
||||||
};
|
};
|
||||||
|
|
||||||
var requestUrl = string.Format("/3/tv/{0}/season/{1}/episode/{2}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN", tmdbId, seasonNumber, episodeNumber);
|
var requestUrl = string.Format("/3/tv/{0}/season/{1}/episode/{2}?api_key=e28e1bc408db7adefc8bacce225c5085&language=zh-CN", ctn.tvId, ctn.seasonNumber, ctn.episodeNumber);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -980,7 +889,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.GetTmdbEpisode() 接口调用失败 {requestUrl} & {path} & {response.StatusCode}", requestUrl, path, response.StatusCode);
|
_logger.LogError("ChineseNfoRegistry.GetTmdbEpisode() 接口调用失败 {requestUrl} & {path} & {response.StatusCode}", requestUrl, ctn.episodeNfoPath, response.StatusCode);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,7 +905,7 @@ public class ChineseNfoRegistry : Registry, IChineseNfoRegistry
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError("ChineseNfoRegistry.GetTmdbEpisode() 接口调用失败 {requestUrl} & {path} \r {e}", requestUrl, path, e);
|
_logger.LogError("ChineseNfoRegistry.GetTmdbEpisode() 接口调用失败 {requestUrl} & {path} \r {e}", requestUrl, ctn.episodeNfoPath, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1028,4 +937,19 @@ public enum TheMovieDbLanguage
|
|||||||
{
|
{
|
||||||
ZhCn = 1,
|
ZhCn = 1,
|
||||||
ZhTw = 2
|
ZhTw = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ChineseNfoContent
|
||||||
|
{
|
||||||
|
public int tvId { get; set; }
|
||||||
|
|
||||||
|
public string tvNfoPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int seasonNumber { get; set; }
|
||||||
|
|
||||||
|
public string seasonNfoPath { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int episodeNumber { get; set; }
|
||||||
|
|
||||||
|
public string episodeNfoPath { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
using Core;
|
using Core;
|
||||||
using Interface.Jobs;
|
using Interface.Jobs;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace WebApi.Controllers;
|
namespace WebApi.Controllers;
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ public class JobTriggerController : BaseController
|
|||||||
using var reader = new StreamReader(body);
|
using var reader = new StreamReader(body);
|
||||||
var text = await reader.ReadToEndAsync();
|
var text = await reader.ReadToEndAsync();
|
||||||
|
|
||||||
var json = JsonNode.Parse(text);
|
var json = JsonConvert.DeserializeObject<JObject>(text);
|
||||||
|
|
||||||
var eventType = json?["eventType"]?.ToString();
|
var eventType = json?["eventType"]?.ToString();
|
||||||
|
|
||||||
@@ -127,13 +129,13 @@ public class JobTriggerController : BaseController
|
|||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
var seasonNumber = json?["episodes"]?[0]?["seasonNumber"]?.ToString();
|
var seasonNumber = json?["episodes"]?[0]?["seasonNumber"]?.ToObject<int>();
|
||||||
var episodeNumber = json?["episodes"]?[0]?["episodeNumber"]?.ToString();
|
var episodeNumber = json?["episodes"]?[0]?["episodeNumber"]?.ToObject<int>();
|
||||||
var path = json?["series"]?["path"]?.ToString();
|
var path = json?["series"]?["path"]?.ToString();
|
||||||
|
|
||||||
_logger.LogInformation("SonarrChangedConvertChineseNfo() path: {path}, seasonNumber: {seasonNumber}, episodeNumber: {episodeNumber}", path, seasonNumber, episodeNumber);
|
_logger.LogInformation("SonarrChangedConvertChineseNfo() path: {path}, seasonNumber: {seasonNumber}, episodeNumber: {episodeNumber}", path, seasonNumber, episodeNumber);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(seasonNumber) || string.IsNullOrEmpty(episodeNumber))
|
if (string.IsNullOrEmpty(path) || seasonNumber == null || episodeNumber == null)
|
||||||
{
|
{
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
@@ -147,8 +149,8 @@ public class JobTriggerController : BaseController
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public string ConvertChineseNfoByPath(
|
public string ConvertChineseNfoByPath(
|
||||||
string path,
|
string path,
|
||||||
string? seasonNumber = null,
|
int? seasonNumber = null,
|
||||||
string? episodeNumber = null,
|
int? episodeNumber = null,
|
||||||
bool ignoreLocked = true,
|
bool ignoreLocked = true,
|
||||||
bool ignoreCompleted = true)
|
bool ignoreCompleted = true)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user