1、增加图片视频
2、优化代码结构 3、up主下载分类逻辑可配置
This commit is contained in:
@@ -4,12 +4,12 @@ using dy.net.repository;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class UserService
|
||||
public class AdminUserService
|
||||
{
|
||||
|
||||
private readonly UserRepository _userRepository;
|
||||
private readonly AdminUserRepository _userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository)
|
||||
public AdminUserService(AdminUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace dy.net.service
|
||||
return await _userRepository.UpdatePwd(loginUser);
|
||||
}
|
||||
|
||||
public async Task<LoginUserInfo> GetUser(string userName=null)
|
||||
public async Task<AdminUserInfo> GetUser(string userName=null)
|
||||
{
|
||||
return await _userRepository.GetUser(userName);
|
||||
}
|
||||
@@ -32,7 +32,7 @@ namespace dy.net.service
|
||||
|
||||
public (int code, string erro) InitUser()
|
||||
{
|
||||
LoginUserInfo userInfo = new LoginUserInfo
|
||||
AdminUserInfo userInfo = new AdminUserInfo
|
||||
{
|
||||
UserName = "douyin",
|
||||
Password = "douyin2025",
|
||||
@@ -7,11 +7,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class CommonService
|
||||
public class DouyinCommonService
|
||||
{
|
||||
private readonly ISqlSugarClient sqlSugarClient;
|
||||
|
||||
public CommonService(ISqlSugarClient sqlSugarClient)
|
||||
public DouyinCommonService(ISqlSugarClient sqlSugarClient)
|
||||
{
|
||||
this.sqlSugarClient = sqlSugarClient;
|
||||
}
|
||||
@@ -20,21 +20,31 @@ namespace dy.net.service
|
||||
{
|
||||
return sqlSugarClient.Queryable<AppConfig>().First();
|
||||
}
|
||||
|
||||
public AppConfig InitConfig()
|
||||
/// <summary>
|
||||
/// 初始化并返回配置
|
||||
/// </summary>
|
||||
/// <param name="downLoadImage"></param>
|
||||
/// <returns></returns>
|
||||
public AppConfig InitConfig(bool downLoadImage)
|
||||
{
|
||||
var conf = GetConfig();
|
||||
if (conf != null)
|
||||
{
|
||||
conf.DownImageVideo = downLoadImage;
|
||||
sqlSugarClient.Updateable(conf).ExecuteCommand();
|
||||
return conf;
|
||||
}
|
||||
else
|
||||
{
|
||||
AppConfig config = new AppConfig
|
||||
{
|
||||
Id = IdGener.GetLong().ToString(),
|
||||
Cron = "30",
|
||||
BatchCount = 10
|
||||
BatchCount = 10,
|
||||
DownImageVideo = downLoadImage,
|
||||
KeepLogDay = 10
|
||||
};
|
||||
sqlSugarClient.Insertable<AppConfig>(config).ExecuteCommand();
|
||||
sqlSugarClient.Insertable(config).ExecuteCommand();
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -66,7 +76,7 @@ namespace dy.net.service
|
||||
/// </summary>
|
||||
public void UpdateCollectViedoType()
|
||||
{
|
||||
var collectViedos = sqlSugarClient.Queryable<DyCollectVideo>().Where(x => string.IsNullOrWhiteSpace(x.ViedoType)).ToList();
|
||||
var collectViedos = sqlSugarClient.Queryable<DouyinVideo>().Where(x => string.IsNullOrWhiteSpace(x.ViedoType)).ToList();
|
||||
|
||||
if (collectViedos.Any())
|
||||
{
|
||||
@@ -85,7 +95,7 @@ namespace dy.net.service
|
||||
{
|
||||
//var sql = "update dy_cookie set CollHasSyncd=0,FavHasSyncd=0,UperSyncd=0";
|
||||
// sqlSugarClient.Ado.ExecuteCommand(sql) > 0;
|
||||
var cookies = sqlSugarClient.Queryable<DyUserCookies>().ToList();
|
||||
var cookies = sqlSugarClient.Queryable<DouyinUserCookie>().ToList();
|
||||
|
||||
foreach (var cookie in cookies)
|
||||
{
|
||||
@@ -95,7 +105,7 @@ namespace dy.net.service
|
||||
var upers = cookie.UpSecUserIds;
|
||||
if (!string.IsNullOrWhiteSpace(upers))
|
||||
{
|
||||
var uperList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DyUpSecUserIdDto>>(upers);
|
||||
var uperList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DouyinUpSecUserIdDto>>(upers);
|
||||
if (uperList != null && uperList.Count > 0)
|
||||
{
|
||||
foreach (var uper in uperList)
|
||||
@@ -5,28 +5,28 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class DyCookieService
|
||||
public class DouyinCookieService
|
||||
{
|
||||
|
||||
private readonly DyCookieRepository _cookieRepository;
|
||||
private readonly DouyinUserCookieRepository _cookieRepository;
|
||||
|
||||
public DyCookieService(DyCookieRepository cookieRepository)
|
||||
public DouyinCookieService(DouyinUserCookieRepository cookieRepository)
|
||||
{
|
||||
_cookieRepository = cookieRepository;
|
||||
}
|
||||
|
||||
public Task<List<DyUserCookies>> GetAllCookies()
|
||||
public Task<List<DouyinUserCookie>> GetAllCookies()
|
||||
{
|
||||
return _cookieRepository.GetAllCookies();
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> Add(DyUserCookies dyUserCookies)
|
||||
public async Task<bool> Add(DouyinUserCookie dyUserCookies)
|
||||
{
|
||||
return await _cookieRepository.InsertAsync(dyUserCookies);
|
||||
}
|
||||
|
||||
public bool Init()
|
||||
public bool InitCookie()
|
||||
{
|
||||
var initId= "2026";
|
||||
var exist = _cookieRepository.GetFirst(x => x.Id == initId);
|
||||
@@ -34,7 +34,7 @@ namespace dy.net.service
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var cookie = new DyUserCookies
|
||||
var cookie = new DouyinUserCookie
|
||||
{
|
||||
UserName = "douyin",
|
||||
Cookies = "--",
|
||||
@@ -46,25 +46,26 @@ namespace dy.net.service
|
||||
UpSavePath = "/app/uper",
|
||||
CollHasSyncd = 0,
|
||||
FavHasSyncd = 0,
|
||||
UperSyncd = 0
|
||||
UperSyncd = 0,
|
||||
ImgSavePath="/app/images",
|
||||
};
|
||||
return _cookieRepository.Insert(cookie);
|
||||
}
|
||||
|
||||
// 查询单个
|
||||
public async Task<DyUserCookies> GetByIdAsync(string id)
|
||||
public async Task<DouyinUserCookie> GetByIdAsync(string id)
|
||||
{
|
||||
return await _cookieRepository.GetByIdAsync(id);
|
||||
}
|
||||
|
||||
// 查询列表(可加条件)
|
||||
public async Task<(List<DyUserCookies> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize)
|
||||
public async Task<(List<DouyinUserCookie> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
return await _cookieRepository.GetPagedAsync(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
// 更新
|
||||
public async Task<bool> UpdateAsync(DyUserCookies dyUserCookies)
|
||||
public async Task<bool> UpdateAsync(DouyinUserCookie dyUserCookies)
|
||||
{
|
||||
return await _cookieRepository.UpdateAsync(dyUserCookies);
|
||||
}
|
||||
@@ -7,12 +7,12 @@ using System.Net.Http;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class DyHttpClientService
|
||||
public class DouyinHttpClientService
|
||||
{
|
||||
public static readonly string DouYinApi = "https://www.douyin.com/aweme/v1/web/aweme";
|
||||
// 随机数生成器(避免重复实例化,保证随机性)
|
||||
private readonly IHttpClientFactory _clientFactory;
|
||||
public DyHttpClientService(IHttpClientFactory clientFactory)
|
||||
public DouyinHttpClientService(IHttpClientFactory clientFactory)
|
||||
{
|
||||
_clientFactory = clientFactory;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ namespace dy.net.service
|
||||
/// <param name="count"></param>
|
||||
/// <param name="cookie"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<CollectVideoInfo> SyncCollectVideos(string cursor, string count, string cookie)
|
||||
public async Task<DouyinVideoInfo> SyncCollectVideos(string cursor, string count, string cookie)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace dy.net.service
|
||||
}
|
||||
httpClient.DefaultRequestHeaders.Add("Cookie", cookie);
|
||||
|
||||
var dics = DySyncBaseParamDics.CollectParams;
|
||||
var dics = DouyinBaseParamDics.CollectParams;
|
||||
dics["cursor"]=cursor;
|
||||
dics["count"] = count;
|
||||
try
|
||||
@@ -68,7 +68,7 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<CollectVideoInfo>(data);
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfo>(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,7 +92,7 @@ namespace dy.net.service
|
||||
/// <param name="cookie"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public async Task<CollectVideoInfo> SyncFavoriteVideos(string count,string cursor, string secUserId, string cookie)
|
||||
public async Task<DouyinVideoInfo> SyncFavoriteVideos(string count,string cursor, string secUserId, string cookie)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -118,7 +118,7 @@ namespace dy.net.service
|
||||
}
|
||||
httpClient.DefaultRequestHeaders.Add("Cookie", cookie);
|
||||
|
||||
var dics = DySyncBaseParamDics.FavoriteParams;
|
||||
var dics = DouyinBaseParamDics.FavoriteParams;
|
||||
{
|
||||
// 添加动态参数
|
||||
dics["max_cursor"] = cursor;
|
||||
@@ -133,7 +133,7 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<CollectVideoInfo>(data);
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfo>(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -158,7 +158,7 @@ namespace dy.net.service
|
||||
/// <param name="cookie"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public async Task<CollectVideoInfo> SyncUpderPostVideos(string count, string cursor, string secUserId, string cookie)
|
||||
public async Task<DouyinVideoInfo> SyncUpderPostVideos(string count, string cursor, string secUserId, string cookie)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -184,7 +184,7 @@ namespace dy.net.service
|
||||
}
|
||||
httpClient.DefaultRequestHeaders.Add("Cookie", cookie);
|
||||
|
||||
var parameters = DySyncBaseParamDics.UpderPostParams;
|
||||
var parameters = DouyinBaseParamDics.UpderPostParams;
|
||||
{
|
||||
// 添加动态参数
|
||||
parameters["max_cursor"] = cursor;
|
||||
@@ -204,7 +204,7 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<CollectVideoInfo>(data);
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfo>(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3,11 +3,11 @@ using dy.net.job;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class QuartzJobService
|
||||
public class DouyinQuartzJobService
|
||||
{
|
||||
private readonly ISchedulerFactory _schedulerFactory;
|
||||
|
||||
public QuartzJobService(ISchedulerFactory schedulerFactory)
|
||||
public DouyinQuartzJobService(ISchedulerFactory schedulerFactory)
|
||||
{
|
||||
_schedulerFactory = schedulerFactory;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace dy.net.service
|
||||
/// <returns></returns>
|
||||
public async Task StartJob(string expression,int delay=5000)
|
||||
{
|
||||
await StartCollectJob(expression);
|
||||
//await StartCollectJob(expression);
|
||||
|
||||
await Task.Delay(delay);
|
||||
//如果是数字则加1分钟,减少并发
|
||||
@@ -29,7 +29,7 @@ namespace dy.net.service
|
||||
cron++;
|
||||
expression = cron.ToString();
|
||||
}
|
||||
await StartFavoriteJob(expression);
|
||||
//await StartFavoriteJob(expression);
|
||||
|
||||
await Task.Delay(delay);
|
||||
if (int.TryParse(expression, out int cron2))
|
||||
@@ -55,7 +55,7 @@ namespace dy.net.service
|
||||
await __scheduler1.DeleteJob(jobKey);//删掉原来的
|
||||
}
|
||||
|
||||
IJobDetail job = JobBuilder.Create<DouYinCollectSyncJob>()
|
||||
IJobDetail job = JobBuilder.Create<DouyinCollectSyncJob>()
|
||||
.WithIdentity(jobKey)
|
||||
.Build();
|
||||
ITrigger trigger;
|
||||
@@ -108,7 +108,7 @@ namespace dy.net.service
|
||||
await __scheduler1.DeleteJob(jobKey);//删掉原来的
|
||||
}
|
||||
|
||||
IJobDetail job = JobBuilder.Create<DouYinFavoritSyncJob>()
|
||||
IJobDetail job = JobBuilder.Create<DouyinFavoritSyncJob>()
|
||||
.WithIdentity(jobKey)
|
||||
.Build();
|
||||
ITrigger trigger;
|
||||
@@ -160,7 +160,7 @@ namespace dy.net.service
|
||||
await __scheduler1.DeleteJob(jobKey);//删掉原来的
|
||||
}
|
||||
|
||||
IJobDetail job = JobBuilder.Create<DouYinUperPostSyncJob>()
|
||||
IJobDetail job = JobBuilder.Create<DouyinUperPostSyncJob>()
|
||||
.WithIdentity(jobKey)
|
||||
.Build();
|
||||
ITrigger trigger;
|
||||
@@ -7,18 +7,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
public class DyCollectVideoService
|
||||
public class DouyinVideoService
|
||||
{
|
||||
|
||||
private readonly DyCollectVideoRepository _dyCollectVideoRepository;
|
||||
private readonly DouyinVideoRepository _dyCollectVideoRepository;
|
||||
|
||||
public DyCollectVideoService(DyCollectVideoRepository dyCollectVideoRepository)
|
||||
public DouyinVideoService(DouyinVideoRepository dyCollectVideoRepository)
|
||||
{
|
||||
_dyCollectVideoRepository = dyCollectVideoRepository;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> batchInsert(List<DyCollectVideo> videos)
|
||||
public async Task<bool> batchInsert(List<DouyinVideo> videos)
|
||||
{
|
||||
|
||||
// 边界处理:如果传入的列表为空,直接返回成功(或根据业务返回false)
|
||||
@@ -56,7 +56,7 @@ namespace dy.net.service
|
||||
public async Task<VideoStaticsDto> GetStatics()
|
||||
{
|
||||
|
||||
List<DyCollectVideo> list = await this._dyCollectVideoRepository.GetAllAsync();
|
||||
List<DouyinVideo> list = await this._dyCollectVideoRepository.GetAllAsync();
|
||||
if (!list.Any())
|
||||
return new VideoStaticsDto();
|
||||
var Categories = list.GroupBy(x => x.Tag1).Select(x => new VideoStaticsItemDto { Name = x.Key, Count = x.LongCount() }).OrderByDescending(p => p.Count).ToList();
|
||||
@@ -85,7 +85,7 @@ namespace dy.net.service
|
||||
|
||||
//分页查询
|
||||
|
||||
public async Task<(List<DyCollectVideo> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize, string tag = null, string author = null, string viedoType = null, List<string>? dates = null)
|
||||
public async Task<(List<DouyinVideo> list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize, string tag = null, string author = null, string viedoType = null, List<string>? dates = null)
|
||||
{
|
||||
return await _dyCollectVideoRepository.GetPagedAsync(pageIndex, pageSize, tag, author, viedoType, dates);
|
||||
}
|
||||
Reference in New Issue
Block a user