quartz数据库持久化

This commit is contained in:
jianzhichu
2026-01-26 18:29:19 +08:00
parent f13d73e023
commit 85986cdaa3
16 changed files with 514 additions and 131 deletions
+41 -33
View File
@@ -213,7 +213,8 @@ namespace dy.net.job
/// <returns>创建的视频保存文件夹路径</returns>
protected virtual string CreateSaveFolder(DouyinCookie cookie, Aweme item, AppConfig config, DouyinFollowed followed, DouyinCollectCate cate)
{
var folder = Path.Combine(cookie.SavePath, DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true));
var subFolder = DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true);
var folder = Path.Combine(cookie.SavePath, subFolder);
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
return folder;
@@ -289,7 +290,7 @@ namespace dy.net.job
/// <returns>封面图片的文件名</returns>
protected virtual string GetNfoFileName(DouyinCookie cookie, Aweme item, AppConfig config, string fileName, DouyinCollectCate cate)
{
return fileName;
return $"{item.AwemeId}_{fileName}";
}
/// <summary>
@@ -314,7 +315,6 @@ namespace dy.net.job
var follows = await douyinFollowService.GetSyncFollows(cookie.MyUserId);
if (follows != null && follows.Any())
{
//int totalSyncCount = 0;
foreach (var followed in follows)
{
int syncCount = 0; // 本次同步成功的视频数量
@@ -322,12 +322,6 @@ namespace dy.net.job
bool hasMore = true;
(syncCount, cursor, hasMore) = await GetAndSaveViedos(cookie, config, syncCount, cursor, hasMore, followed);
await HandleSyncCompletion(cookie, syncCount, followed);
//totalSyncCount += syncCount;
//if (totalSyncCount >= config.BatchCount)
//{
// Log.Debug($"[{VideoType.GetVideoTypeDesc()}][{cookie.UserName}]:本次同步数量{totalSyncCount},已达配置上限,等下次任务继续同步");
// break;
//}
}
}
}
@@ -336,7 +330,7 @@ namespace dy.net.job
case VideoTypeEnum.dy_collects:
if (VideoType == VideoTypeEnum.dy_collects && cookie.UseCollectFolder)
{
Serilog.Log.Debug($"[{VideoType.GetDesc()}]-已开启自定义收藏夹同步...break;");
Log.Debug($"[{VideoType.GetDesc()}]-已开启自定义收藏夹同步...break;");
break;
}
else
@@ -350,28 +344,16 @@ namespace dy.net.job
break;
case VideoTypeEnum.dy_mix:
if (cookie.DownMix)
await SyncCustomListVideos(cookie, config);
break;
case VideoTypeEnum.dy_series:
if (cookie.DownSeries)
await SyncCustomListVideos(cookie, config);
break;
case VideoTypeEnum.dy_custom_collect:
{
var cates = await douyinCollectCateService.GetSyncCates(cookie.Id, VideoType);
if (cates != null && cates.Any())
{
foreach (var cate in cates)
{
int syncCount = 0; // 本次同步成功的视频数量
string cursor = "0";
bool hasMore = true;
(syncCount, cursor, hasMore) = await GetAndSaveViedos(cookie, config, syncCount, cursor, hasMore, null, cate);
await HandleSyncCompletion(cookie, syncCount, null);
}
}
else
{
Serilog.Log.Debug($"[{VideoType.GetDesc()}]没有查询到已开启的对象");
}
}
if (cookie.UseCollectFolder)
await SyncCustomListVideos(cookie, config);
break;
case VideoTypeEnum.ImageVideo:
default:
@@ -385,6 +367,32 @@ namespace dy.net.job
Log.Error(ex, $"[{VideoType.GetDesc()}][{cookie.UserName}]同步出错!!!,{ex.StackTrace}");
}
}
/// <summary>
/// 同步下载自定义收藏夹、合集、短剧
/// </summary>
/// <param name="cookie"></param>
/// <param name="config"></param>
/// <returns></returns>
private async Task SyncCustomListVideos(DouyinCookie cookie, AppConfig config)
{
var cates = await douyinCollectCateService.GetSyncCates(cookie.Id, VideoType);
if (cates != null && cates.Any())
{
foreach (var cate in cates)
{
int syncCount = 0; // 本次同步成功的视频数量
string cursor = "0";
bool hasMore = true;
(syncCount, cursor, hasMore) = await GetAndSaveViedos(cookie, config, syncCount, cursor, hasMore, null, cate);
await HandleSyncCompletion(cookie, syncCount, null);
}
}
else
{
Serilog.Log.Debug($"[{VideoType.GetDesc()}]没有查询到已开启的对象");
}
}
private async Task<(int syncCount, string cursor, bool hasMore)> GetAndSaveViedos(DouyinCookie cookie, AppConfig config, int syncCount, string cursor, bool hasMore, DouyinFollowed followed = null, DouyinCollectCate cate = null)
{
@@ -711,7 +719,7 @@ namespace dy.net.job
try
{
//File.Delete(exitVideo.VideoSavePath);
DeleteOldViedo( exitVideo);
DeleteOldViedo(exitVideo);
//Log.Debug($"已删除旧文件:{exitVideo.VideoSavePath}");
}
catch (Exception ex)
@@ -812,7 +820,7 @@ namespace dy.net.job
if (!IsAwemeValid(item)) return null;
// 获取视频最佳下载地址
var v = GetBestMatchedVideoUrl(item, config);
if (v == null)
{
Serilog.Log.Error($"[{VideoType}][{cookie.UserName}][{item.Desc}]未获取到下载地址");
@@ -869,7 +877,7 @@ namespace dy.net.job
return await CreateVideoEntity(config, cookie, item, v, savePath, saveFolder, avatarSavePath, null, cate);
}
private static VideoBitRate GetBestMatchedVideoUrl(Aweme item, AppConfig config)
private static VideoBitRate GetBestMatchedVideoUrl(Aweme item, AppConfig config)
{
VideoBitRate v;
if (config.VideoEncoder.HasValue && config.VideoEncoder.Value == 265)
+3 -24
View File
@@ -53,15 +53,15 @@ namespace dy.net.job
: DouyinFileNameHelper.SanitizeLinuxFileName(rawAuthorName, "", true);
// 2. 确定最终文件夹路径(遵循原有优先级:followed.SavePath > authorName > 基础路径)
var targetFolderName = !string.IsNullOrWhiteSpace(followed?.SavePath) ? followed.SavePath : authorName;
var folder = Path.Combine(cookie.UpSavePath, targetFolderName);
var rootFolder = Path.Combine(cookie.UpSavePath, targetFolderName);
if (!Directory.Exists(folder)) Directory.CreateDirectory(folder);
if (!Directory.Exists(rootFolder)) Directory.CreateDirectory(rootFolder);
#endregion
var sampleName = DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true);
var (existingName, _) = douyinVideoService.GetUperLastViedoFileName(item.Author.Uid, sampleName);
var fileNameFolder = string.IsNullOrWhiteSpace(existingName) ? sampleName : existingName;
return Path.Combine(folder, fileNameFolder);
return Path.Combine(rootFolder, fileNameFolder);
}
/// <summary>
/// 关注的视频,生成文件名称
@@ -134,27 +134,6 @@ namespace dy.net.job
}
/// <summary>
///
/// </summary>
/// <param name="cookie"></param>
/// <param name="item"></param>
/// <param name="config"></param>
/// <param name="imageType"></param>
/// <param name="cate"></param>
/// <returns></returns>
protected override string GetNfoFileName(DouyinCookie cookie, Aweme item, AppConfig config, string imageType, DouyinCollectCate cate)
{
return base.GetNfoFileName(cookie, item, config, imageType, cate);
}
//protected override async Task HandleSyncCompletion(DouyinCookie cookie, int syncCount, DouyinFollowed followed, DouyinCollectCate cate)
//{
// cookie.UperSyncd = 1;
// await douyinCookieService.UpdateAsync(cookie);
// await base.HandleSyncCompletion(cookie, syncCount, followed, cate);
//}
}
}
+2 -1
View File
@@ -53,6 +53,8 @@ namespace dy.net.job
foreach (var ck in cookies)
{
//同步关注列表
await SyncFollowListAsync(ck, conf);
if (ck.UseCollectFolder)
{
@@ -113,7 +115,6 @@ namespace dy.net.job
LOG_TAG_SERIES);
}
await SyncFollowListAsync(ck, conf);
Log.Debug($"[{ck.UserName}]所有[基础数据(list)]同步完成,包括 [收藏列表、关注列表、合集列表、短剧列表] ");
}