优化
This commit is contained in:
+27
-15
@@ -3,6 +3,7 @@ using dy.net.model.entity;
|
||||
using dy.net.model.response;
|
||||
using dy.net.service;
|
||||
using dy.net.utils;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace dy.net.job
|
||||
{
|
||||
@@ -34,33 +35,44 @@ namespace dy.net.job
|
||||
return await douyinHttpClientService.SyncCollectVideos(cursor, count, cookie.Cookies);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected override string CreateSaveFolder(DouyinCookie cookie, Aweme item, AppConfig config, DouyinFollowed followed, DouyinCollectCate cate)
|
||||
{
|
||||
string authorFolder;
|
||||
if (string.IsNullOrWhiteSpace(item.Author?.Nickname) && string.IsNullOrWhiteSpace(item.Author?.Uid))
|
||||
// 1. 简化获取博主自定义保存路径(合并空值判断)
|
||||
string saveFolder = !string.IsNullOrWhiteSpace(item?.Author?.Uid)
|
||||
? base.douyinCommonService.GetDouyinUpSavePath(item.Author.Uid)
|
||||
: string.Empty;
|
||||
|
||||
// 2. 简化博主文件夹命名逻辑
|
||||
string authorFolder = !string.IsNullOrWhiteSpace(saveFolder)
|
||||
? saveFolder
|
||||
: (item?.Author == null || (string.IsNullOrWhiteSpace(item.Author.Nickname) && string.IsNullOrWhiteSpace(item.Author.Uid)))
|
||||
? "未知博主"
|
||||
: DouyinFileNameHelper.SanitizeLinuxFileName(item.Author.Nickname, item.Author.Uid, true);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(saveFolder)&&!string.IsNullOrEmpty(authorFolder))
|
||||
{
|
||||
authorFolder = "未知博主";
|
||||
base.douyinCommonService.SaveDouyinUpSavePath(item.Author.Uid, authorFolder);
|
||||
}
|
||||
|
||||
// 3. 提取重复的视频文件夹名(避免重复调用方法)
|
||||
string videoFolderName = DouyinFileNameHelper.SanitizeLinuxFileName(item?.Desc, item?.AwemeId, true);
|
||||
|
||||
// 4. 简化文件夹路径拼接+存在判断(核心逻辑不变)
|
||||
string folder = Path.Combine(cookie.SavePath, authorFolder, videoFolderName);
|
||||
if (Directory.Exists(folder))
|
||||
{
|
||||
// 文件夹存在则拼接AwemeId(保留你的原逻辑)
|
||||
folder = Path.Combine(cookie.SavePath, authorFolder, $"{videoFolderName}_{item.AwemeId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
authorFolder = $"{DouyinFileNameHelper.SanitizeLinuxFileName(item.Author?.Nickname, item.Author?.Uid, true)}";
|
||||
}
|
||||
var folder = Path.Combine(cookie.SavePath, authorFolder, $"{DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true)}");
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
else
|
||||
{
|
||||
//说明文件夹存在,检查里面有没有文件,如果已经有视频文件了,说明视频标题相同,那么应该重新创建文件夹,+id
|
||||
|
||||
folder = Path.Combine(cookie.SavePath, authorFolder , $"{DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true)}"+"_" + item.AwemeId);
|
||||
}
|
||||
return folder;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -534,8 +534,6 @@ namespace dy.net.job
|
||||
// continue;
|
||||
//}
|
||||
|
||||
// 1. 查询数据库中是否已存在该视频(通过 AwemeId 唯一标识)
|
||||
var exitVideo = await douyinVideoService.GetByAwemeId(item.AwemeId);
|
||||
//判断视频是否是强制删除且不再下载的视频
|
||||
var deleteVideo = await douyinCommonService.ExistDeleteVideo(item.AwemeId);
|
||||
if (deleteVideo)
|
||||
@@ -544,21 +542,46 @@ namespace dy.net.job
|
||||
continue;
|
||||
}
|
||||
|
||||
// 查询数据库中是否已存在该视频(通过 AwemeId 唯一标识)
|
||||
var exitVideo = await douyinVideoService.GetByAwemeId(item.AwemeId);
|
||||
|
||||
bool Goon = await AutoDistinct(config, exitVideo, cookie);
|
||||
if (!Goon)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (exitVideo != null && File.Exists(exitVideo.VideoSavePath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//如果存在,但是因为去重规则,选择的最高优先级变更了,需要删除原来的,重新下载。
|
||||
if (exitVideo != null)
|
||||
{
|
||||
await douyinVideoService.DeleteById(exitVideo.Id);
|
||||
//文件存在
|
||||
if (File.Exists(exitVideo.VideoSavePath))
|
||||
{
|
||||
//如果当前时正在下载关注列表的视频,但是已经存在合集下载过了,那么跳过
|
||||
if (VideoType == VideoTypeEnum.dy_follows && exitVideo.ViedoType == VideoTypeEnum.dy_mix)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//如果当前正在下载合集视频,但是发现已经存在了,但视频类型不是合集,那么删掉原来的记录以及文件,重新下载,合集优先级最高
|
||||
if (VideoType == VideoTypeEnum.dy_mix && exitVideo.ViedoType != VideoTypeEnum.dy_mix)
|
||||
{
|
||||
File.Delete(exitVideo.VideoSavePath);
|
||||
await douyinVideoService.DeleteById(exitVideo.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
await douyinVideoService.DeleteById(exitVideo.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//文件不存在,直接删掉原始记录
|
||||
await douyinVideoService.DeleteById(exitVideo.Id);
|
||||
}
|
||||
}
|
||||
|
||||
var uper = await douyinFollowService.GetByUperId(item.AuthorUserId.ToString(), cookie.MyUserId);
|
||||
if (uper != null && uper.FullSync)
|
||||
{
|
||||
@@ -1055,7 +1078,6 @@ namespace dy.net.job
|
||||
/// </summary>
|
||||
/// <param name="cookie">用户Cookie</param>
|
||||
/// <param name="item">视频信息(包含图片集)</param>
|
||||
/// <param name="data">视频信息对象</param>
|
||||
/// <param name="config">应用配置</param>
|
||||
/// <param name="followed">应用配置</param>
|
||||
/// <param name="cate"></param>
|
||||
@@ -1432,6 +1454,7 @@ namespace dy.net.job
|
||||
// 生成NFO文件,动态视频 合成后重新生成,不在这里生成nfo
|
||||
NfoFileGenerator.GenerateVideoNfoFile(video);
|
||||
}
|
||||
|
||||
return video;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user