This commit is contained in:
lijianyou
2025-10-10 13:04:29 +08:00
parent 0e826c3cfa
commit e4dedcad30
13 changed files with 86 additions and 58 deletions
+1 -1
View File
@@ -292,7 +292,7 @@ namespace dy.net
connString = CreateSqliteDBConn(); connString = CreateSqliteDBConn();
} }
if (string.IsNullOrEmpty(connString)) if (string.IsNullOrWhiteSpace(connString))
{ {
return null; return null;
} }
BIN
View File
Binary file not shown.
+19 -9
View File
@@ -56,7 +56,7 @@ namespace dy.net.job
foreach (var cookie in cookies) foreach (var cookie in cookies)
{ {
Serilog.Log.Debug($"collect-开始同步 Cookie-[{cookie.UserName}]收藏视频"); Serilog.Log.Debug($"collect-开始同步 Cookie-[{cookie.UserName}]收藏视频");
if (string.IsNullOrEmpty(cookie.Cookies)|| cookie.Cookies.Length<1000) if (string.IsNullOrWhiteSpace(cookie.Cookies)|| cookie.Cookies.Length<1000)
{ {
Serilog.Log.Debug($"collect-Cookie-[{cookie.UserName}]无效,跳过"); Serilog.Log.Debug($"collect-Cookie-[{cookie.UserName}]无效,跳过");
continue; continue;
@@ -67,7 +67,9 @@ namespace dy.net.job
int index = 0; int index = 0;
bool hasMore = true; bool hasMore = true;
string cursor = "0";
string cursor = "0";
while (hasMore) while (hasMore)
{ {
var data = await _douyinService.SyncCollectVideos(cursor, count, cookie.Cookies); var data = await _douyinService.SyncCollectVideos(cursor, count, cookie.Cookies);
@@ -78,7 +80,9 @@ namespace dy.net.job
Serilog.Log.Debug($"collect-Cookie[{cookie.UserName}]获取收藏数据失败,请检查一下Cookie"); Serilog.Log.Debug($"collect-Cookie[{cookie.UserName}]获取收藏数据失败,请检查一下Cookie");
break; break;
} }
cursor = data != null && !string.IsNullOrEmpty(data.Cursor) ? data.Cursor : "0"; cursor = data != null && !string.IsNullOrWhiteSpace(data.Cursor) ? data.Cursor : "0";
if (data.AwemeList == null || !data.AwemeList.Any()) if (data.AwemeList == null || !data.AwemeList.Any())
{ {
break; break;
@@ -98,7 +102,7 @@ namespace dy.net.job
if (v == null) continue; if (v == null) continue;
var videoUrl = v.PlayAddr.UrlList != null && v.PlayAddr.UrlList.Any() ? v.PlayAddr.UrlList[0] : null; var videoUrl = v.PlayAddr.UrlList != null && v.PlayAddr.UrlList.Any() ? v.PlayAddr.UrlList[0] : null;
if (string.IsNullOrEmpty(videoUrl)) continue; if (string.IsNullOrWhiteSpace(videoUrl)) continue;
var tag1 = tags.FirstOrDefault(x => x.Level == 1)?.TagName; var tag1 = tags.FirstOrDefault(x => x.Level == 1)?.TagName;
var tag2 = tags.FirstOrDefault(x => x.Level == 2)?.TagName; var tag2 = tags.FirstOrDefault(x => x.Level == 2)?.TagName;
@@ -115,6 +119,8 @@ namespace dy.net.job
if (!File.Exists(savePath)) if (!File.Exists(savePath))
{ {
Serilog.Log.Debug($"collect-视频[{SanitizePath(item.Desc)}]开始下载");
var downVideo = await _douyinService.DownloadAsync(videoUrl, savePath, cookie.Cookies); var downVideo = await _douyinService.DownloadAsync(videoUrl, savePath, cookie.Cookies);
Serilog.Log.Debug($"collect-视频[{SanitizePath(item.Desc)}]下载{(downVideo ? "" : "")}"); Serilog.Log.Debug($"collect-视频[{SanitizePath(item.Desc)}]下载{(downVideo ? "" : "")}");
if (downVideo) if (downVideo)
@@ -193,7 +199,7 @@ namespace dy.net.job
// 收集所有需要删除的目录(去重) // 收集所有需要删除的目录(去重)
foreach (var video in videos) foreach (var video in videos)
{ {
if (!string.IsNullOrEmpty(video.VideoSavePath) && Directory.Exists(video.VideoSavePath)) if (!string.IsNullOrWhiteSpace(video.VideoSavePath) && Directory.Exists(video.VideoSavePath))
{ {
var deletePath = Path.GetDirectoryName(video.VideoSavePath); var deletePath = Path.GetDirectoryName(video.VideoSavePath);
Directory.Delete(deletePath, recursive: true); Directory.Delete(deletePath, recursive: true);
@@ -237,7 +243,7 @@ namespace dy.net.job
{ {
var coverUrl = item.Video.Cover.UrlList != null && item.Video.Cover.UrlList.Any() var coverUrl = item.Video.Cover.UrlList != null && item.Video.Cover.UrlList.Any()
? item.Video.Cover.UrlList[0] : null; ? item.Video.Cover.UrlList[0] : null;
if (string.IsNullOrEmpty(coverUrl)) return; if (string.IsNullOrWhiteSpace(coverUrl)) return;
var coverImgName = "poster.jpg"; var coverImgName = "poster.jpg";
var coverSavePath = Path.Combine(saveFolder, coverImgName); var coverSavePath = Path.Combine(saveFolder, coverImgName);
@@ -268,7 +274,7 @@ namespace dy.net.job
var avatarUrl = item.Author.AvatarLarger?.UrlList != null && item.Author.AvatarLarger.UrlList.Any() var avatarUrl = item.Author.AvatarLarger?.UrlList != null && item.Author.AvatarLarger.UrlList.Any()
? item.Author.AvatarLarger.UrlList[0] : null; ? item.Author.AvatarLarger.UrlList[0] : null;
if (string.IsNullOrEmpty(avatarUrl)) return; if (string.IsNullOrWhiteSpace(avatarUrl)) return;
var path = Path.Combine(mainPath, "author"); var path = Path.Combine(mainPath, "author");
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
@@ -293,10 +299,10 @@ namespace dy.net.job
private static string CreateSaveFolder(DyUserCookies cookie, Aweme item, string? tag1, string? tag2) private static string CreateSaveFolder(DyUserCookies cookie, Aweme item, string? tag1, string? tag2)
{ {
// 路径中避免特殊字符,用ID替代描述 // 路径中避免特殊字符,用ID替代描述
var safeTag1 = string.IsNullOrEmpty(tag1) ? "other" : SanitizePath(tag1); var safeTag1 = string.IsNullOrWhiteSpace(tag1) ? "other" : SanitizePath(tag1);
List<string> pathParts = new List<string> { cookie.SavePath, safeTag1 }; List<string> pathParts = new List<string> { cookie.SavePath, safeTag1 };
return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId); return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId);
//if (string.IsNullOrEmpty(tag2)) //if (string.IsNullOrWhiteSpace(tag2))
// return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId); // return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId);
//else //else
// return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), tag2 + "@" + item.AwemeId); // return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), tag2 + "@" + item.AwemeId);
@@ -305,6 +311,10 @@ namespace dy.net.job
// 清理路径中的特殊字符(避免创建文件夹失败) // 清理路径中的特殊字符(避免创建文件夹失败)
private static string SanitizePath(string path) private static string SanitizePath(string path)
{ {
if (string.IsNullOrWhiteSpace(path))
{
path = "其他";
}
foreach (var c in Path.GetInvalidFileNameChars()) foreach (var c in Path.GetInvalidFileNameChars())
{ {
path = path.Replace(c, '_'); path = path.Replace(c, '_');
+18 -11
View File
@@ -51,17 +51,17 @@ namespace dy.net.job
foreach (var cookie in cookies) foreach (var cookie in cookies)
{ {
Serilog.Log.Debug($"favorite-开始同步 Cookie-[{cookie.UserName}]喜欢的视频"); Serilog.Log.Debug($"favorite-开始同步 Cookie-[{cookie.UserName}]喜欢的视频");
if (string.IsNullOrEmpty(cookie.Cookies)|| cookie.Cookies.Length<1000) if (string.IsNullOrWhiteSpace(cookie.Cookies)|| cookie.Cookies.Length<1000)
{ {
Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]无效,跳过"); Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]无效,跳过");
continue; continue;
} }
if(string.IsNullOrEmpty(cookie.FavSavePath)) if(string.IsNullOrWhiteSpace(cookie.FavSavePath))
{ {
Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]未设置保存路径,跳过"); Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]未设置保存路径,跳过");
continue; continue;
} }
if (string.IsNullOrEmpty(cookie.SecUserId)) { if (string.IsNullOrWhiteSpace(cookie.SecUserId)|| cookie.SecUserId.Length<10) {
Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]未设置SecUserId,跳过"); Serilog.Log.Debug($"favorite-Cookie-[{cookie.UserName}]未设置SecUserId,跳过");
continue; continue;
} }
@@ -82,7 +82,8 @@ namespace dy.net.job
Serilog.Log.Debug($"favorite-Cookie[{cookie.UserName}]获取喜欢的数据失败,请检查一下Cookie和sec_user_id"); Serilog.Log.Debug($"favorite-Cookie[{cookie.UserName}]获取喜欢的数据失败,请检查一下Cookie和sec_user_id");
break; break;
} }
cursor = data != null && !string.IsNullOrEmpty(data.MaxCursor) ? data.MaxCursor : "0"; cursor = data != null && !string.IsNullOrWhiteSpace(data.MaxCursor) ? data.MaxCursor : "0";
if (data.AwemeList == null || !data.AwemeList.Any()) if (data.AwemeList == null || !data.AwemeList.Any())
{ {
break; break;
@@ -102,7 +103,7 @@ namespace dy.net.job
if (v == null) continue; if (v == null) continue;
var videoUrl = v.PlayAddr.UrlList != null && v.PlayAddr.UrlList.Any() ? v.PlayAddr.UrlList[0] : null; var videoUrl = v.PlayAddr.UrlList != null && v.PlayAddr.UrlList.Any() ? v.PlayAddr.UrlList[0] : null;
if (string.IsNullOrEmpty(videoUrl)) continue; if (string.IsNullOrWhiteSpace(videoUrl)) continue;
var tag1 = tags.FirstOrDefault(x => x.Level == 1)?.TagName; var tag1 = tags.FirstOrDefault(x => x.Level == 1)?.TagName;
var tag2 = tags.FirstOrDefault(x => x.Level == 2)?.TagName; var tag2 = tags.FirstOrDefault(x => x.Level == 2)?.TagName;
@@ -119,6 +120,8 @@ namespace dy.net.job
if (!File.Exists(savePath)) if (!File.Exists(savePath))
{ {
Serilog.Log.Debug($"favorite-视频[{SanitizePath(item.Desc)}]开始下载");
var downVideo = await _douyinService.DownloadAsync(videoUrl, savePath, cookie.Cookies); var downVideo = await _douyinService.DownloadAsync(videoUrl, savePath, cookie.Cookies);
Serilog.Log.Debug($"favorite-视频[{SanitizePath(item.Desc)}]下载{(downVideo ? "" : "")}"); Serilog.Log.Debug($"favorite-视频[{SanitizePath(item.Desc)}]下载{(downVideo ? "" : "")}");
if (downVideo) if (downVideo)
@@ -197,7 +200,7 @@ namespace dy.net.job
// 收集所有需要删除的目录(去重) // 收集所有需要删除的目录(去重)
foreach (var video in videos) foreach (var video in videos)
{ {
if (!string.IsNullOrEmpty(video.VideoSavePath) && Directory.Exists(video.VideoSavePath)) if (!string.IsNullOrWhiteSpace(video.VideoSavePath) && Directory.Exists(video.VideoSavePath))
{ {
var deletePath = Path.GetDirectoryName(video.VideoSavePath); var deletePath = Path.GetDirectoryName(video.VideoSavePath);
Directory.Delete(deletePath, recursive: true); Directory.Delete(deletePath, recursive: true);
@@ -241,7 +244,7 @@ namespace dy.net.job
{ {
var coverUrl = item.Video.Cover.UrlList != null && item.Video.Cover.UrlList.Any() var coverUrl = item.Video.Cover.UrlList != null && item.Video.Cover.UrlList.Any()
? item.Video.Cover.UrlList[0] : null; ? item.Video.Cover.UrlList[0] : null;
if (string.IsNullOrEmpty(coverUrl)) return; if (string.IsNullOrWhiteSpace(coverUrl)) return;
var coverImgName = "poster.jpg"; var coverImgName = "poster.jpg";
var coverSavePath = Path.Combine(saveFolder, coverImgName); var coverSavePath = Path.Combine(saveFolder, coverImgName);
@@ -273,11 +276,11 @@ namespace dy.net.job
var avatarUrl = item.Author.AvatarLarger?.UrlList != null && item.Author.AvatarLarger.UrlList.Any() var avatarUrl = item.Author.AvatarLarger?.UrlList != null && item.Author.AvatarLarger.UrlList.Any()
? item.Author.AvatarLarger.UrlList[0] : null; ? item.Author.AvatarLarger.UrlList[0] : null;
if (string.IsNullOrEmpty(avatarUrl)) { if (string.IsNullOrWhiteSpace(avatarUrl)) {
avatarUrl = item.Author.AvatarThumb?.UrlList != null && item.Author.AvatarThumb.UrlList.Any() avatarUrl = item.Author.AvatarThumb?.UrlList != null && item.Author.AvatarThumb.UrlList.Any()
? item.Author.AvatarThumb.UrlList[0] : null; ? item.Author.AvatarThumb.UrlList[0] : null;
} }
if (string.IsNullOrEmpty(avatarUrl)) return; if (string.IsNullOrWhiteSpace(avatarUrl)) return;
var path = Path.Combine(mainPath, "author"); var path = Path.Combine(mainPath, "author");
if (!Directory.Exists(path)) if (!Directory.Exists(path))
{ {
@@ -302,10 +305,10 @@ namespace dy.net.job
private static string CreateSaveFolder(DyUserCookies cookie, Aweme item, string? tag1, string? tag2) private static string CreateSaveFolder(DyUserCookies cookie, Aweme item, string? tag1, string? tag2)
{ {
// 路径中避免特殊字符,用ID替代描述 // 路径中避免特殊字符,用ID替代描述
var safeTag1 = string.IsNullOrEmpty(tag1) ? "other" : SanitizePath(tag1); var safeTag1 = string.IsNullOrWhiteSpace(tag1) ? "other" : SanitizePath(tag1);
List<string> pathParts = new List<string> { cookie.FavSavePath, safeTag1 }; List<string> pathParts = new List<string> { cookie.FavSavePath, safeTag1 };
return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId); return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId);
//if (string.IsNullOrEmpty(tag2)) //if (string.IsNullOrWhiteSpace(tag2))
// return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId); // return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), SanitizePath(item.Desc) + "@" + item.AwemeId);
//else //else
// return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), tag2 + "@" + item.AwemeId); // return Path.Combine(pathParts[0], string.Join("-", pathParts.Skip(1)), tag2 + "@" + item.AwemeId);
@@ -314,6 +317,10 @@ namespace dy.net.job
// 清理路径中的特殊字符(避免创建文件夹失败) // 清理路径中的特殊字符(避免创建文件夹失败)
private static string SanitizePath(string path) private static string SanitizePath(string path)
{ {
if (string.IsNullOrWhiteSpace(path))
{
path = "其他";
}
foreach (var c in Path.GetInvalidFileNameChars()) foreach (var c in Path.GetInvalidFileNameChars())
{ {
path = path.Replace(c, '_'); path = path.Replace(c, '_');
+1 -1
View File
@@ -125,6 +125,6 @@ namespace dy.net.model
public string ViedoTypeStr => ViedoType == "1" ? "我喜欢的" : "我收藏的"; public string ViedoTypeStr => ViedoType == "1" ? "我喜欢的" : "我收藏的";
[SugarColumn(IsIgnore = true)] [SugarColumn(IsIgnore = true)]
public string ViedoCate =>(string.IsNullOrEmpty(Tag1) ? "" : Tag1) + "/" + (string.IsNullOrEmpty(Tag2) ? "" : Tag2); public string ViedoCate =>(string.IsNullOrWhiteSpace(Tag1) ? "" : Tag1) + "/" + (string.IsNullOrWhiteSpace(Tag2) ? "" : Tag2);
} }
} }
+11
View File
@@ -41,5 +41,16 @@ namespace dy.net.model
/// </summary> /// </summary>
[SugarColumn(Length =500,IsNullable =true)] [SugarColumn(Length =500,IsNullable =true)]
public string FavSavePath { get; set; } public string FavSavePath { get; set; }
///// <summary>
///// 最新收藏夹的分页页码
///// </summary>
//[SugarColumn(Length =500,IsNullable =true)]
//public string CollectMaxCursor { get; set; }
///// <summary>
///// 最新我喜欢的分页页码
///// </summary>
//[SugarColumn(Length = 500, IsNullable = true)]
//public string FavoriteMaxCursor { get; set; }
} }
} }
+3 -3
View File
@@ -36,11 +36,11 @@ namespace dy.net.repository
} }
var where = this.Db.Queryable<DyCollectVideo>() var where = this.Db.Queryable<DyCollectVideo>()
.WhereIF(!string.IsNullOrEmpty(tag), x => x.Tag1 == tag) .WhereIF(!string.IsNullOrWhiteSpace(tag), x => x.Tag1 == tag)
.WhereIF(!string.IsNullOrEmpty(author), x => x.Author == author) .WhereIF(!string.IsNullOrWhiteSpace(author), x => x.Author == author)
.WhereIF(start.HasValue, x => x.SyncTime >= start.Value) .WhereIF(start.HasValue, x => x.SyncTime >= start.Value)
.WhereIF(end.HasValue, x => x.SyncTime <= end.Value) .WhereIF(end.HasValue, x => x.SyncTime <= end.Value)
.WhereIF(!string.IsNullOrEmpty(viedoType) && viedoType != "*", x => x.ViedoType == viedoType); .WhereIF(!string.IsNullOrWhiteSpace(viedoType) && viedoType != "*", x => x.ViedoType == viedoType);
var totalCount = await where.CountAsync(); var totalCount = await where.CountAsync();
+3 -3
View File
@@ -20,7 +20,7 @@ namespace dy.net.repository
/// <returns></returns> /// <returns></returns>
public async Task<(int code, string erro)> UpdatePwd(UpdatePwdRequest loginUser) public async Task<(int code, string erro)> UpdatePwd(UpdatePwdRequest loginUser)
{ {
if (string.IsNullOrEmpty(loginUser.UserId)) if (string.IsNullOrWhiteSpace(loginUser.UserId))
{ {
return (-1, "用户不存在"); return (-1, "用户不存在");
} }
@@ -52,7 +52,7 @@ namespace dy.net.repository
public async Task<LoginUserInfo> GetUser() public async Task<LoginUserInfo> GetUser()
{ {
return await this.GetFirstAsync(x=>!string.IsNullOrEmpty(x.Id)); return await this.GetFirstAsync(x=>!string.IsNullOrWhiteSpace(x.Id));
} }
@@ -84,7 +84,7 @@ namespace dy.net.repository
/// <returns></returns> /// <returns></returns>
public (int code, string erro) InitUser(LoginUserInfo userInfo) public (int code, string erro) InitUser(LoginUserInfo userInfo)
{ {
var isInit = this.GetFirst(x=>!string.IsNullOrEmpty(x.Id)); var isInit = this.GetFirst(x=>!string.IsNullOrWhiteSpace(x.Id));
if (isInit!=null) if (isInit!=null)
{ {
return (-1, "系统用户已存在"); return (-1, "系统用户已存在");
+1 -1
View File
@@ -53,7 +53,7 @@ namespace dy.net.service
/// </summary> /// </summary>
public void UpdateCollectViedoType() public void UpdateCollectViedoType()
{ {
var collectViedos= sqlSugarClient.Queryable<DyCollectVideo>().Where(x=>string.IsNullOrEmpty(x.ViedoType)).ToList(); var collectViedos= sqlSugarClient.Queryable<DyCollectVideo>().Where(x=>string.IsNullOrWhiteSpace(x.ViedoType)).ToList();
if (collectViedos.Any()) if (collectViedos.Any())
{ {
+6 -6
View File
@@ -28,17 +28,17 @@ namespace dy.net.service
/// <returns></returns> /// <returns></returns>
public async Task<CollectVideoInfo> SyncCollectVideos(string cursor, string count, string cookie) public async Task<CollectVideoInfo> SyncCollectVideos(string cursor, string count, string cookie)
{ {
if (string.IsNullOrEmpty(cursor)) if (string.IsNullOrWhiteSpace(cursor))
{ {
throw new ArgumentException($"“{nameof(cursor)}”不能为 null 或空。", nameof(cursor)); throw new ArgumentException($"“{nameof(cursor)}”不能为 null 或空。", nameof(cursor));
} }
if (string.IsNullOrEmpty(count)) if (string.IsNullOrWhiteSpace(count))
{ {
throw new ArgumentException($"“{nameof(count)}”不能为 null 或空。", nameof(count)); throw new ArgumentException($"“{nameof(count)}”不能为 null 或空。", nameof(count));
} }
if (string.IsNullOrEmpty(cookie)) if (string.IsNullOrWhiteSpace(cookie))
{ {
throw new ArgumentException($"“{nameof(cookie)}”不能为 null 或空。", nameof(cookie)); throw new ArgumentException($"“{nameof(cookie)}”不能为 null 或空。", nameof(cookie));
} }
@@ -94,17 +94,17 @@ namespace dy.net.service
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public async Task<CollectVideoInfo> SyncFavoriteVideos(string cursor, string secUserId, string cookie) public async Task<CollectVideoInfo> SyncFavoriteVideos(string cursor, string secUserId, string cookie)
{ {
if (string.IsNullOrEmpty(cursor)) if (string.IsNullOrWhiteSpace(cursor))
{ {
throw new ArgumentException($"“{nameof(cursor)}”不能为 null 或空。", nameof(cursor)); throw new ArgumentException($"“{nameof(cursor)}”不能为 null 或空。", nameof(cursor));
} }
if (string.IsNullOrEmpty(secUserId)) if (string.IsNullOrWhiteSpace(secUserId))
{ {
throw new ArgumentException($"“{nameof(secUserId)}”不能为 null 或空。", nameof(secUserId)); throw new ArgumentException($"“{nameof(secUserId)}”不能为 null 或空。", nameof(secUserId));
} }
if (string.IsNullOrEmpty(cookie)) if (string.IsNullOrWhiteSpace(cookie))
{ {
throw new ArgumentException($"“{nameof(cookie)}”不能为 null 或空。", nameof(cookie)); throw new ArgumentException($"“{nameof(cookie)}”不能为 null 或空。", nameof(cookie));
} }
+1 -1
View File
@@ -81,7 +81,7 @@ namespace dy.net.utils
if (isUrl) if (isUrl)
{ {
var uri = new Uri(input); var uri = new Uri(input);
var newQuery = string.IsNullOrEmpty(uri.Query) var newQuery = string.IsNullOrWhiteSpace(uri.Query)
? $"X-Bogus={xbValue}" ? $"X-Bogus={xbValue}"
: $"{uri.Query.Substring(1)}&X-Bogus={xbValue}"; : $"{uri.Query.Substring(1)}&X-Bogus={xbValue}";
return ($"{uri.Scheme}://{uri.Host}{uri.AbsolutePath}?{newQuery}", xbValue); return ($"{uri.Scheme}://{uri.Host}{uri.AbsolutePath}?{newQuery}", xbValue);
+5 -5
View File
@@ -18,23 +18,23 @@ namespace dy.net.utils
if (videoInfo == null) if (videoInfo == null)
throw new ArgumentNullException(nameof(videoInfo)); throw new ArgumentNullException(nameof(videoInfo));
if (string.IsNullOrEmpty(filePath)) if (string.IsNullOrWhiteSpace(filePath))
throw new ArgumentException("文件路径不能为空", nameof(filePath)); throw new ArgumentException("文件路径不能为空", nameof(filePath));
// 创建根元素 // 创建根元素
XElement root = new XElement("movie"); // 对于电影使用"movie",电视剧可以使用"tvshow" XElement root = new XElement("movie"); // 对于电影使用"movie",电视剧可以使用"tvshow"
// 添加视频信息 // 添加视频信息
if (!string.IsNullOrEmpty(videoInfo.Title)) if (!string.IsNullOrWhiteSpace(videoInfo.Title))
root.Add(new XElement("title", videoInfo.Title)); root.Add(new XElement("title", videoInfo.Title));
if (!string.IsNullOrEmpty(videoInfo.Author)) if (!string.IsNullOrWhiteSpace(videoInfo.Author))
root.Add(new XElement("author", videoInfo.Author)); root.Add(new XElement("author", videoInfo.Author));
if (!string.IsNullOrEmpty(videoInfo.Thumbnail)) if (!string.IsNullOrWhiteSpace(videoInfo.Thumbnail))
root.Add(new XElement("thumb", new XAttribute("aspect", "poster"), videoInfo.Thumbnail)); root.Add(new XElement("thumb", new XAttribute("aspect", "poster"), videoInfo.Thumbnail));
if (!string.IsNullOrEmpty(videoInfo.Poster)) if (!string.IsNullOrWhiteSpace(videoInfo.Poster))
root.Add(new XElement("fanart", root.Add(new XElement("fanart",
new XElement("thumb", videoInfo.Poster) new XElement("thumb", videoInfo.Poster)
)); ));
+17 -17
View File
@@ -21,29 +21,29 @@ namespace dy.net.utils
XElement root = new XElement("movie"); XElement root = new XElement("movie");
// 添加基本信息 // 添加基本信息
if (!string.IsNullOrEmpty(videoInfo.Title)) if (!string.IsNullOrWhiteSpace(videoInfo.Title))
root.Add(new XElement("title", videoInfo.Title)); root.Add(new XElement("title", videoInfo.Title));
if (!string.IsNullOrEmpty(videoInfo.OriginalTitle)) if (!string.IsNullOrWhiteSpace(videoInfo.OriginalTitle))
root.Add(new XElement("originaltitle", videoInfo.OriginalTitle)); root.Add(new XElement("originaltitle", videoInfo.OriginalTitle));
if (!string.IsNullOrEmpty(videoInfo.SortTitle)) if (!string.IsNullOrWhiteSpace(videoInfo.SortTitle))
root.Add(new XElement("sorttitle", videoInfo.SortTitle)); root.Add(new XElement("sorttitle", videoInfo.SortTitle));
if (videoInfo.Year > 0) if (videoInfo.Year > 0)
root.Add(new XElement("year", videoInfo.Year)); root.Add(new XElement("year", videoInfo.Year));
if (!string.IsNullOrEmpty(videoInfo.Plot)) if (!string.IsNullOrWhiteSpace(videoInfo.Plot))
root.Add(new XElement("plot", videoInfo.Plot)); root.Add(new XElement("plot", videoInfo.Plot));
if (!string.IsNullOrEmpty(videoInfo.Outline)) if (!string.IsNullOrWhiteSpace(videoInfo.Outline))
root.Add(new XElement("outline", videoInfo.Outline)); root.Add(new XElement("outline", videoInfo.Outline));
if (!string.IsNullOrEmpty(videoInfo.Tagline)) if (!string.IsNullOrWhiteSpace(videoInfo.Tagline))
root.Add(new XElement("tagline", videoInfo.Tagline)); root.Add(new XElement("tagline", videoInfo.Tagline));
// 添加人员信息 // 添加人员信息
if (!string.IsNullOrEmpty(videoInfo.Director)) if (!string.IsNullOrWhiteSpace(videoInfo.Director))
root.Add(new XElement("director", videoInfo.Director)); root.Add(new XElement("director", videoInfo.Director));
// 添加演员 // 添加演员
@@ -61,7 +61,7 @@ namespace dy.net.utils
} }
// 添加媒体信息 // 添加媒体信息
if (!string.IsNullOrEmpty(videoInfo.Genre)) if (!string.IsNullOrWhiteSpace(videoInfo.Genre))
root.Add(new XElement("genre", videoInfo.Genre)); root.Add(new XElement("genre", videoInfo.Genre));
if (videoInfo.Rating > 0) if (videoInfo.Rating > 0)
@@ -70,36 +70,36 @@ namespace dy.net.utils
if (videoInfo.Votes > 0) if (videoInfo.Votes > 0)
root.Add(new XElement("votes", videoInfo.Votes)); root.Add(new XElement("votes", videoInfo.Votes));
if (!string.IsNullOrEmpty(videoInfo.Studio)) if (!string.IsNullOrWhiteSpace(videoInfo.Studio))
root.Add(new XElement("studio", videoInfo.Studio)); root.Add(new XElement("studio", videoInfo.Studio));
if (videoInfo.Premiered.HasValue) if (videoInfo.Premiered.HasValue)
root.Add(new XElement("premiered", videoInfo.Premiered.Value.ToString("yyyy-MM-dd"))); root.Add(new XElement("premiered", videoInfo.Premiered.Value.ToString("yyyy-MM-dd")));
if (!string.IsNullOrEmpty(videoInfo.Runtime)) if (!string.IsNullOrWhiteSpace(videoInfo.Runtime))
root.Add(new XElement("runtime", videoInfo.Runtime)); root.Add(new XElement("runtime", videoInfo.Runtime));
// 添加文件信息 // 添加文件信息
if (!string.IsNullOrEmpty(videoInfo.FileName)) if (!string.IsNullOrWhiteSpace(videoInfo.FileName))
root.Add(new XElement("filenameandpath", videoInfo.FileName)); root.Add(new XElement("filenameandpath", videoInfo.FileName));
if (videoInfo.FileSize > 0) if (videoInfo.FileSize > 0)
root.Add(new XElement("filesize", videoInfo.FileSize)); root.Add(new XElement("filesize", videoInfo.FileSize));
// 添加新增字段 // 添加新增字段
if (!string.IsNullOrEmpty(videoInfo.Country)) if (!string.IsNullOrWhiteSpace(videoInfo.Country))
root.Add(new XElement("country", videoInfo.Country)); root.Add(new XElement("country", videoInfo.Country));
if (!string.IsNullOrEmpty(videoInfo.Language)) if (!string.IsNullOrWhiteSpace(videoInfo.Language))
root.Add(new XElement("language", videoInfo.Language)); root.Add(new XElement("language", videoInfo.Language));
if (!string.IsNullOrEmpty(videoInfo.VideoCodec)) if (!string.IsNullOrWhiteSpace(videoInfo.VideoCodec))
root.Add(new XElement("codec", videoInfo.VideoCodec)); root.Add(new XElement("codec", videoInfo.VideoCodec));
if (!string.IsNullOrEmpty(videoInfo.AudioCodec)) if (!string.IsNullOrWhiteSpace(videoInfo.AudioCodec))
root.Add(new XElement("audiocodec", videoInfo.AudioCodec)); root.Add(new XElement("audiocodec", videoInfo.AudioCodec));
if (!string.IsNullOrEmpty(videoInfo.Resolution)) if (!string.IsNullOrWhiteSpace(videoInfo.Resolution))
root.Add(new XElement("resolution", videoInfo.Resolution)); root.Add(new XElement("resolution", videoInfo.Resolution));
// 创建文档并保存 // 创建文档并保存
@@ -110,7 +110,7 @@ namespace dy.net.utils
// 确保目录存在 // 确保目录存在
var directory = Path.GetDirectoryName(outputPath); var directory = Path.GetDirectoryName(outputPath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) if (!string.IsNullOrWhiteSpace(directory) && !Directory.Exists(directory))
{ {
Directory.CreateDirectory(directory); Directory.CreateDirectory(directory);
} }