Files
douyin/utils/NfoContentBuilder.cs
T

73 lines
3.1 KiB
C#

using System.Xml.Linq;
using System.Xml;
using dy.net.model.dto;
using dy.net.model.entity;
using dy.net.storage;
namespace dy.net.utils
{
public static class NfoContentBuilder
{
public static IReadOnlyDictionary<string, string> Build(DouyinVideo video, string tvShowTitle = "")
{
var files = new Dictionary<string, string>();
if (video == null || video.OnlyImgOrOnlyMp3 || string.IsNullOrWhiteSpace(video.VideoSavePath)) return files;
var directory = StoragePath.DirectoryName(video.VideoSavePath);
var fileName = Path.GetFileNameWithoutExtension(video.VideoSavePath);
var isSeries = video.ViedoType == VideoTypeEnum.dy_mix || video.ViedoType == VideoTypeEnum.dy_series;
if (isSeries)
{
files[StoragePath.CombineRemote(directory, "tvshow.nfo")] = CreateXml(video, "tvshow", string.IsNullOrWhiteSpace(tvShowTitle) ? video.VideoTitle : tvShowTitle);
files[StoragePath.CombineRemote(directory, fileName + ".nfo")] = CreateXml(video, "episodedetails", video.VideoTitle);
}
else
{
files[StoragePath.CombineRemote(directory, fileName + ".nfo")] = CreateXml(video, "movie", video.VideoTitle);
}
return files;
}
private static string CreateXml(DouyinVideo video, string rootName, string title)
{
var root = new XElement(rootName,
new XElement("lockdata", true),
new XElement("title", Clean(title)),
new XElement("releasedate", video.CreateTime.ToString("yyyy-MM-dd")),
new XElement("premiered", video.CreateTime.ToString("yyyy-MM-dd")));
foreach (var genre in new[] { video.Tag1, video.Tag2, video.Tag3 }.Where(x => !string.IsNullOrWhiteSpace(x)))
root.Add(new XElement("genre", Clean(genre)));
if (!string.IsNullOrWhiteSpace(video.Author))
{
root.Add(new XElement("actor",
new XElement("name", Clean(video.Author)),
new XElement("role", "主演"),
new XElement("tmdbid", "")));
}
var poster = Path.GetFileName(video.VideoCoverSavePath);
if (!string.IsNullOrWhiteSpace(poster))
{
root.Add(new XElement("thumb", new XAttribute("aspect", "poster"), poster));
root.Add(new XElement("fanart", new XElement("thumb", poster)));
}
if (rootName == "episodedetails")
{
root.Add(new XElement("episode", Path.GetFileNameWithoutExtension(video.VideoSavePath).Replace("S01E0", "").Replace("S01E", "")));
root.Add(new XElement("season", "1"));
}
return new XDocument(new XDeclaration("1.0", "utf-8", null), root).ToString();
}
private static string Clean(string value) => string.IsNullOrWhiteSpace(value)
? string.Empty
: new string(value.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray());
}
}