代码整理
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
using ClockSnowFlake;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace dy.net.utils
|
||||
@@ -22,7 +20,7 @@ namespace dy.net.utils
|
||||
string result = string.Empty;
|
||||
// 1. 空值处理:直接返回默认名
|
||||
if (string.IsNullOrWhiteSpace(originalName))
|
||||
result= defaultName.Replace(" ","");
|
||||
result = defaultName.Replace(" ", "");
|
||||
else
|
||||
{
|
||||
// 2. 过滤 Linux 非法字符:
|
||||
@@ -44,7 +42,7 @@ namespace dy.net.utils
|
||||
// 3. 计算 UTF-8 字节数,若未超 255 字节,直接返回
|
||||
byte[] utf8Bytes = Encoding.UTF8.GetBytes(sanitizedName);
|
||||
if (utf8Bytes.Length <= 100)
|
||||
result= sanitizedName.Replace(" ", "");
|
||||
result = sanitizedName.Replace(" ", "");
|
||||
else
|
||||
{
|
||||
// 4. 超过 255 字节,截取前 255 字节(避免破坏 UTF-8 字符)
|
||||
@@ -55,14 +53,14 @@ namespace dy.net.utils
|
||||
string truncatedName = Encoding.UTF8.GetString(truncatedBytes).TrimEnd('\0').Replace(" ", ""); // 移除可能的空字符
|
||||
|
||||
// 6. 极端情况:截取后为空(如全是非法字符替换后无有效内容),返回默认名
|
||||
result= string.IsNullOrWhiteSpace(truncatedName) ? defaultName : truncatedName;
|
||||
result = string.IsNullOrWhiteSpace(truncatedName) ? defaultName : truncatedName;
|
||||
}
|
||||
if (isfolder)
|
||||
{
|
||||
result = KeepChineseLettersAndNumbers(result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using dy.net.model.dto;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace dy.net.utils
|
||||
{
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
using dy.net.model.dto;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace dy.net.utils
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
/// </summary>
|
||||
/// <param name="logDirectory">日志文件所在目录</param>
|
||||
/// <param name="n">清除N天之前的日志文件</param>
|
||||
public static void CleanOldLogFiles(string logDirectory,int n)
|
||||
public static void CleanOldLogFiles(string logDirectory, int n)
|
||||
{
|
||||
// 计算n天前的时间点
|
||||
DateTime threeDaysAgo = DateTime.Now.AddDays(-n);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using dy.net.model.dto;
|
||||
using dy.net.model.entity;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -19,7 +18,7 @@ namespace dy.net.utils
|
||||
/// </summary>
|
||||
/// <param name="video">视频信息</param>
|
||||
/// <returns>一个表示异步操作的任务</returns>
|
||||
public static void GenerateVideoNfoFile(DouyinVideo video)
|
||||
public static void GenerateVideoNfoFile(DouyinVideo video)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -39,7 +38,7 @@ namespace dy.net.utils
|
||||
{
|
||||
var fileExt = Path.GetExtension(video.AuthorAvatar);
|
||||
var actorsDir = Path.Combine(videoDirectory, ".actors");
|
||||
if(!Directory.Exists(actorsDir))
|
||||
if (!Directory.Exists(actorsDir))
|
||||
{
|
||||
Directory.CreateDirectory(actorsDir);
|
||||
}
|
||||
@@ -55,7 +54,7 @@ namespace dy.net.utils
|
||||
}
|
||||
|
||||
|
||||
var nfoInfo= new DouyinVideoNfo
|
||||
var nfoInfo = new DouyinVideoNfo
|
||||
{
|
||||
Actors = new List<Actor>
|
||||
{
|
||||
@@ -82,7 +81,7 @@ namespace dy.net.utils
|
||||
{
|
||||
GenerateNfoFile(nfoInfo, nfoFullPath);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,7 +89,7 @@ namespace dy.net.utils
|
||||
}
|
||||
}
|
||||
|
||||
private static void GenerateNfoFile(DouyinVideoNfo videoInfo, string filePath,string xmlRoot= "movie")
|
||||
private static void GenerateNfoFile(DouyinVideoNfo videoInfo, string filePath, string xmlRoot = "movie")
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -143,7 +142,7 @@ namespace dy.net.utils
|
||||
if (!string.IsNullOrWhiteSpace(actor.Role))
|
||||
actorElement.Add(new XElement("role", CleanInvalidXmlChars(actor.Role)));
|
||||
|
||||
actorElement.Add(new XElement("tmdbid", ""));
|
||||
actorElement.Add(new XElement("tmdbid", ""));
|
||||
|
||||
root.Add(actorElement);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace dy.net.utils
|
||||
return placeholderMap.TryGetValue(placeholderKey, out var value) ? value : match.Value;
|
||||
});
|
||||
|
||||
var fullName= finalTitle.Replace("--","-");
|
||||
var fullName = finalTitle.Replace("--", "-");
|
||||
|
||||
if (fullName.Length > 60)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user