78 lines
3.7 KiB
C#
Executable File
78 lines
3.7 KiB
C#
Executable File
using dy.net.model.dto;
|
|
using dy.net.model.entity;
|
|
using dy.net.model.response;
|
|
using dy.net.service;
|
|
using dy.net.utils;
|
|
using dy.net.storage;
|
|
|
|
namespace dy.net.job
|
|
{
|
|
public class DouyinFavoritSyncJob : DouyinBasicSyncJob
|
|
{
|
|
public DouyinFavoritSyncJob(DouyinCookieService douyinCookieService, DouyinHttpClientService douyinHttpClientService, DouyinVideoService douyinVideoService, DouyinCommonService douyinCommonService, DouyinFollowService douyinFollowService, DouyinMergeVideoService douyinMergeVideoService, DouyinCollectCateService douyinCollectCateService, MediaStorageRouter mediaStorageRouter, VideoTaskService videoTaskService) : base(douyinCookieService, douyinHttpClientService, douyinVideoService, douyinCommonService, douyinFollowService, douyinMergeVideoService, douyinCollectCateService, mediaStorageRouter, videoTaskService)
|
|
{
|
|
}
|
|
|
|
|
|
protected override VideoTypeEnum VideoType => VideoTypeEnum.dy_favorite;
|
|
|
|
protected override string GetAuthorAvatarBasePath(DouyinCookie cookie)
|
|
{
|
|
return CombineStoragePath(GetStorageRoot(cookie, VideoType), "author");
|
|
}
|
|
|
|
protected override async Task<List<DouyinCookie>> GetSyncCookies()
|
|
{
|
|
var cookies = await douyinCookieService.GetOpendCookiesAsync();
|
|
return cookies.Where(x => !string.IsNullOrWhiteSpace(GetStorageRoot(x, VideoType)) && !string.IsNullOrWhiteSpace(x.SecUserId)).ToList();
|
|
}
|
|
|
|
protected override async Task<DouyinVideoInfoResponse> FetchVideoData(DouyinCookie cookie, string cursor, DouyinFollowed followed, DouyinCollectCate cate)
|
|
{
|
|
return await douyinHttpClientService.SyncFavoriteVideos(count, cursor, cookie.SecUserId, cookie.Cookies);
|
|
}
|
|
|
|
//protected override bool ShouldContinueSync(DouyinCookie cookie, DouyinVideoInfoResponse data, DouyinFollowed followed, AppConfig config)
|
|
//{
|
|
// return data != null && data.HasMore == 1;
|
|
//}
|
|
|
|
|
|
//protected override async Task HandleSyncCompletion(DouyinCookie cookie, int syncCount, DouyinFollowed followed,DouyinCollectCate cate)
|
|
//{
|
|
// cookie.FavHasSyncd = 1;
|
|
// await douyinCookieService.UpdateAsync(cookie);
|
|
// await base.HandleSyncCompletion(cookie, syncCount, followed, cate);
|
|
//}
|
|
|
|
protected override string CreateSaveFolder(DouyinCookie cookie, Aweme item, AppConfig config, DouyinFollowed followed, DouyinCollectCate cate)
|
|
{
|
|
if (ActiveStorageType.IsRemote())
|
|
return BuildRemotePathPlan(cookie, item, config, followed, cate).DirectoryPath;
|
|
string authorFolder;
|
|
if (string.IsNullOrWhiteSpace(item.Author?.Nickname) && string.IsNullOrWhiteSpace(item.Author?.Uid))
|
|
{
|
|
authorFolder = "未知博主";
|
|
}
|
|
else
|
|
{
|
|
authorFolder = $"{DouyinFileNameHelper.SanitizeLinuxFileName(item.Author?.Nickname, item.Author?.Uid, true)}";
|
|
}
|
|
var root = GetStorageRoot(cookie, VideoType);
|
|
var videoFolder = DouyinFileNameHelper.SanitizeLinuxFileName(item.Desc, item.AwemeId, true);
|
|
var folder = CombineStoragePath(root, authorFolder, videoFolder);
|
|
if (!Directory.Exists(folder))
|
|
{
|
|
Directory.CreateDirectory(folder);
|
|
}
|
|
else
|
|
{
|
|
//说明文件夹存在,检查里面有没有文件,如果已经有视频文件了,说明视频标题相同,那么应该重新创建文件夹,+id
|
|
|
|
folder = CombineStoragePath(root, authorFolder, videoFolder + "_" + item.AwemeId);
|
|
}
|
|
return folder;
|
|
}
|
|
}
|
|
}
|