Skip to content

Commit

Permalink
【一、新增功能】
Browse files Browse the repository at this point in the history
新增【恢复默认】功能
自定义 NFO 解析格式

【二、修复优化】
无
  • Loading branch information
chao committed May 7, 2023
1 parent a7947a9 commit 415fe9c
Show file tree
Hide file tree
Showing 15 changed files with 771 additions and 225 deletions.
19 changes: 14 additions & 5 deletions Jvedio-WPF/Jvedio/Core/Scan/ScanTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ private List<Video> GetExistVideos()

private void HandleImport(List<Video> import)
{
if (import == null || import.Count == 0)
{
return;
}
// 分为 2 部分,有识别码和无识别码
List<Video> noVidList = import.Where(arg => string.IsNullOrEmpty(arg.VID)).ToList();
List<Video> vidList = import.Where(arg => !string.IsNullOrEmpty(arg.VID)).ToList();
Expand Down Expand Up @@ -308,9 +312,11 @@ private void HandleImport(List<Video> import)
toInsert.AddRange(noVidList);

// 1.更新
videoMapper.UpdateBatch(toUpdate, "SubSection"); // 分段视频
if (toUpdate?.Count > 0)
videoMapper.UpdateBatch(toUpdate, "SubSection"); // 分段视频
List<MetaData> toUpdateData = toUpdate.Select(arg => arg.toMetaData()).ToList();
metaDataMapper.UpdateBatch(toUpdateData, "Path", "LastScanDate", "PathExist");
if (toUpdateData?.Count > 0)
metaDataMapper.UpdateBatch(toUpdateData, "Path", "LastScanDate", "PathExist");
AddTags(toUpdate);

// 2.导入
Expand Down Expand Up @@ -483,7 +489,8 @@ private void CopyImages(List<Video> import, ImageType type)

private void HandleImportNFO(List<Video> import)
{
if (import?.Count <= 0) return;
if (import == null || import.Count <= 0)
return;

existVideos = GetExistVideos();
existActors = actorMapper.SelectList();
Expand Down Expand Up @@ -545,9 +552,11 @@ private void HandleImportNFO(List<Video> import)

import.RemoveAll(arg => existVideos.Where(t => arg.VID.Equals(t.VID)).Any());

videoMapper.UpdateBatch(toUpdate, NFOUpdateVideoProps);
if (toUpdate?.Count > 0)
videoMapper.UpdateBatch(toUpdate, NFOUpdateVideoProps);
List<MetaData> toUpdateData = toUpdate.Select(arg => arg.toMetaData()).ToList();
metaDataMapper.UpdateBatch(toUpdateData, NFOUpdateMetaProps);
if (toUpdateData?.Count > 0)
metaDataMapper.UpdateBatch(toUpdateData, NFOUpdateMetaProps);

// 2. 剩下的都是需要导入的
InsertData(import);
Expand Down
169 changes: 67 additions & 102 deletions Jvedio-WPF/Jvedio/Entity/Common/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
using System.Runtime.CompilerServices;
using System.Windows.Media.Imaging;
using System.Xml;
using Jvedio.Entity.Common;
using System.Windows.Controls;
using SuperUtils.Values;

namespace Jvedio.Entity
{
Expand All @@ -32,7 +35,7 @@ protected void RaisePropertyChanged([CallerMemberName] string name = null)
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

private const int DEFAULT_RELEASE_YEAR = 1970;


public Movie(string id)
{
Expand Down Expand Up @@ -190,6 +193,10 @@ public string releasedate

public string genre { get; set; }


/// <summary>
/// 系列
/// </summary>
public string tag { get; set; }

public string actor { get; set; }
Expand Down Expand Up @@ -293,34 +300,9 @@ public static Movie GetInfoFromNfo(string path)
Movie movie = new Movie();
foreach (XmlNode node in rootNode.ChildNodes)
{
try
{
switch (node.Name)
{
case "id": movie.id = string.IsNullOrEmpty(node.InnerText) ? string.Empty : node.InnerText.ToUpper(); break;
case "num": movie.id = string.IsNullOrEmpty(node.InnerText) ? string.Empty : node.InnerText.ToUpper(); break;
case "title": movie.title = node.InnerText; break;
case "release": movie.releasedate = node.InnerText; break;
case "releasedate": movie.releasedate = node.InnerText; break;
case "director": movie.director = node.InnerText; break;
case "studio": movie.studio = node.InnerText; break;
case "rating": movie.rating = string.IsNullOrEmpty(node.InnerText) ? 0.0f : float.Parse(node.InnerText); break;
case "plot": movie.plot = node.InnerText; break;
case "outline": movie.outline = node.InnerText; break;
case "year": movie.year = string.IsNullOrEmpty(node.InnerText) ? DEFAULT_RELEASE_YEAR : int.Parse(node.InnerText); break;
case "runtime": movie.runtime = string.IsNullOrEmpty(node.InnerText) ? 0 : int.Parse(node.InnerText); break;
case "country": movie.country = node.InnerText; break;
case "source": movie.sourceurl = node.InnerText; break;
case "set": movie.tag = node.InnerText; break;
default: break;
}
}
catch (Exception ex)
{
Logger.Warn($"{LangManager.GetValueByKey("ParseNfoInfoFailFromFile")} => {path}");
Logger.Error(ex);
if (node == null || string.IsNullOrEmpty(node.Name))
continue;
}
NfoParse.Parse(ref movie, node.Name, node.InnerText);
}

// 对于 NFO ,只要没有 VID,就不导入
Expand All @@ -330,6 +312,34 @@ public static Movie GetInfoFromNfo(string path)
movie.vediotype = JvedioLib.Security.Identify.GetVideoType(movie.id);

// 扫描视频获得文件大小
SetFileSize(path, ref movie);

// 系列 tag
string tagString = GetTagList(doc, "tag");
if (movie.id.IndexOf("FC2") >= 0)
movie.genre = tagString;
else
movie.tag = tagString;

// 类别 genre
movie.genre = GetTagList(doc, "genre");

// 演员 actor
movie.actor = FindAndJoinData(doc, new List<string>() { "actor/name" });

// 演员头像地址
movie.actressimageurl = FindAndJoinData(doc, new List<string>() { "actor/thumb" }, RenameConfig.DEFAULT_NULL_STRING);

// fanart
movie.extraimageurl = FindAndJoinData(doc, new List<string>() { "fanart/thumb" }, RenameConfig.DEFAULT_NULL_STRING);

// 检查一下视频是否为空
if (movie.isNullMovie()) return null;
return movie;
}

public static void SetFileSize(string path, ref Movie movie)
{
if (File.Exists(path))
{
string fatherPath = new FileInfo(path).DirectoryName;
Expand All @@ -352,87 +362,42 @@ public static Movie GetInfoFromNfo(string path)
}
}
}
}

string sep = SuperUtils.Values.ConstValues.SeparatorString;

// tag
XmlNodeList tagNodes = TrySelectNode(doc, "/movie/tag");
List<string> tags = new List<string>();
if (tagNodes != null && tagNodes.Count > 0)
{
foreach (XmlNode item in tagNodes)
{
if (!string.IsNullOrEmpty(item.InnerText))
tags.Add(item.InnerText.Replace(" ", string.Empty));
}

if (movie.id.IndexOf("FC2") >= 0)
movie.genre = string.Join(sep, tags);
else
movie.tag = string.Join(sep, tags);
}

// genre
XmlNodeList genreNodes = TrySelectNode(doc, "/movie/genre");
List<string> genres = new List<string>();
if (genreNodes != null && genreNodes.Count > 0)
{
foreach (XmlNode item in genreNodes)
{
if (!string.IsNullOrEmpty(item.InnerText))
genres.Add(item.InnerText);
}

movie.genre = string.Join(sep, genres);
}

// actor
XmlNodeList actorNodes = TrySelectNode(doc, "/movie/actor/name");
List<string> actors = new List<string>();
if (actorNodes != null && actorNodes.Count > 0)
{
foreach (XmlNode item in actorNodes)
{
if (!string.IsNullOrEmpty(item.InnerText))
actors.Add(item.InnerText);
}

movie.actor = string.Join(sep, actors);
}
public static string GetTagList(XmlDocument doc, string tagName)
{
if (!NfoParse.CurrentNFOParse.ContainsKey(tagName))
return "";
NfoParse nfoParse = NfoParse.CurrentNFOParse[tagName];
List<string> list = nfoParse.ParseValues.Select(arg => arg.Value).ToList();
if (list == null || list.Count == 0)
return "";

return FindAndJoinData(doc, list);
}

// 演员头像地址
XmlNodeList thumbNodes = TrySelectNode(doc, "/movie/actor/thumb");
List<string> thumbs = new List<string>();
if (thumbNodes?.Count > 0)
public static string FindAndJoinData(XmlDocument doc, List<string> list, string addNull = "")
{
List<string> result = new List<string>();
string value = "";
foreach (string name in list)
{
foreach (XmlNode item in thumbNodes)
XmlNodeList nodes = TrySelectNode(doc, $"/movie/{name}");
if (nodes != null && nodes.Count > 0)
{
if (!string.IsNullOrEmpty(item.InnerText))
thumbs.Add(item.InnerText);
else
thumbs.Add(RenameConfig.DEFAULT_NULL_STRING);
}

movie.actressimageurl = string.Join(sep, thumbs);
}
foreach (XmlNode node in nodes)
{
value = node.InnerText.Trim();

// fanart
XmlNodeList fanartNodes = TrySelectNode(doc, "/movie/fanart/thumb");
List<string> extraImageUrls = new List<string>();
if (fanartNodes != null && fanartNodes.Count > 0)
{
foreach (XmlNode item in fanartNodes)
{
if (!string.IsNullOrEmpty(item.InnerText))
extraImageUrls.Add(item.InnerText);
if (!string.IsNullOrEmpty(addNull) && string.IsNullOrEmpty(value))
value = addNull;
if (string.IsNullOrEmpty(value))
continue;
result.Add(value);
}
}

movie.extraimageurl = string.Join(sep, extraImageUrls);
}

// 检查一下视频是否为空
if (movie.isNullMovie()) return null;
return movie;
return string.Join(ConstValues.SeparatorString, result);
}

public MetaData toMetaData()
Expand Down
24 changes: 7 additions & 17 deletions Jvedio-WPF/Jvedio/Entity/Common/NFO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Collections.ObjectModel;
using SuperUtils.WPF.Entity;
using SuperUtils.Common;
using Newtonsoft.Json.Linq;
using SuperControls.Style;

namespace Jvedio.Entity
{
Expand Down Expand Up @@ -129,21 +136,4 @@ public void SetNodeText(string nodeName, string nodeText)

}

public class NfoParse
{
public NfoParse()
{
}
public NfoParse(string name, string prop, List<string> values)
{
this.Name = name;
this.Prop = prop;
this.ParseValues = new List<string>();
if (values != null)
this.ParseValues.AddRange(values);
}
public string Name { get; set; }
public string Prop { get; set; }
public List<string> ParseValues { get; set; }
}
}
Loading

0 comments on commit 415fe9c

Please sign in to comment.