短剧、合集
This commit is contained in:
@@ -24,6 +24,8 @@ namespace dy.net.service
|
||||
{
|
||||
return await douyinCollectCateRepository.InsertAsync(cate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -43,7 +45,7 @@ namespace dy.net.service
|
||||
/// <param name="ckId"></param>
|
||||
/// <param name="cateType"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<(int add, int update,int delete, bool succ)> Sync(List<DouyinCollectCate> cates, string ckId,int cateType)
|
||||
public async Task<(int add, int update,int delete, bool succ)> Sync(List<DouyinCollectCate> cates, string ckId,VideoTypeEnum cateType)
|
||||
{
|
||||
return await douyinCollectCateRepository.Sync(cates, ckId, cateType);
|
||||
}
|
||||
@@ -66,7 +68,7 @@ namespace dy.net.service
|
||||
/// 获取需要同步的合集、短剧、收藏夹
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<DouyinCollectCate>> GetSyncCates(string cookieId,int cateType)
|
||||
public async Task<List<DouyinCollectCate>> GetSyncCates(string cookieId, VideoTypeEnum cateType)
|
||||
{
|
||||
return await douyinCollectCateRepository.GetListAsync(x => x.CookieId == cookieId && x.CateType == cateType);
|
||||
}
|
||||
|
||||
@@ -108,75 +108,6 @@ namespace dy.net.service
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化一些数据,兼容旧版数据结构。
|
||||
/// </summary>
|
||||
public void UpdateCollectViedoType()
|
||||
{
|
||||
//更新视频类型字段-兼容老版本
|
||||
string sql = @"UPDATE dy_collect_video
|
||||
SET ViedoType = CASE
|
||||
WHEN ViedoType = '0' THEN 0
|
||||
WHEN ViedoType = '1' THEN 1
|
||||
WHEN ViedoType = '2' THEN 2
|
||||
WHEN ViedoType = '3' THEN 3
|
||||
WHEN ViedoType = '4' THEN 4
|
||||
ELSE NULL
|
||||
END;";
|
||||
|
||||
sqlSugarClient.Ado.ExecuteCommand(sql);
|
||||
|
||||
//更新关注表的IsNoFollowed字段为空的数据为0--兼容老版本-新加的字段
|
||||
string followUpdateSql = @"Update dy_follow SET IsNoFollowed=0 WHERE IsNoFollowed is NULL";
|
||||
sqlSugarClient.Ado.ExecuteCommand(followUpdateSql);
|
||||
|
||||
//更新图片视频的合并状态
|
||||
string updateIsMergeVideoSql = @"UPDATE dy_collect_video SET IsMergeVideo = 1 WHERE IsMergeVideo IS NULL and ViedoType='4';";
|
||||
sqlSugarClient.Ado.ExecuteCommand(updateIsMergeVideoSql);
|
||||
|
||||
//更新非图片视频的合并状态
|
||||
string updateNoIsMergeVideoSql = @"UPDATE dy_collect_video SET IsMergeVideo = 0 WHERE IsMergeVideo IS NULL and ViedoType<>'4';";
|
||||
sqlSugarClient.Ado.ExecuteCommand(updateNoIsMergeVideoSql);
|
||||
|
||||
//强制开启去重
|
||||
sqlSugarClient.Updateable<AppConfig>().SetColumns(x => new AppConfig { AutoDistinct = true }).Where(x => !string.IsNullOrWhiteSpace(x.Id)).ExecuteCommand();
|
||||
//重新根据保存路径更新图片视频的类型为喜欢,收藏或关注
|
||||
var collectViedos = sqlSugarClient.Queryable<DouyinVideo>().Where(x => x.ViedoType == VideoTypeEnum.ImageVideo).ToList();
|
||||
if (collectViedos != null && collectViedos.Any())
|
||||
{
|
||||
var cookies = sqlSugarClient.Queryable<DouyinCookie>().ToList();
|
||||
collectViedos.ForEach(x =>
|
||||
{
|
||||
var ck = cookies.FirstOrDefault(c => c.Id == x.CookieId);
|
||||
if (ck != null)
|
||||
{
|
||||
|
||||
var savePath = x.VideoSavePath;
|
||||
if (savePath != null)
|
||||
{
|
||||
if (savePath.StartsWith(ck.SavePath))
|
||||
{
|
||||
x.ViedoType = VideoTypeEnum.dy_collects;
|
||||
}
|
||||
else if (savePath.StartsWith(ck.UpSavePath))
|
||||
{
|
||||
x.ViedoType = VideoTypeEnum.dy_follows;
|
||||
}
|
||||
else if (savePath.StartsWith(ck.FavSavePath))
|
||||
{
|
||||
x.ViedoType = VideoTypeEnum.dy_favorite;
|
||||
}
|
||||
else
|
||||
{
|
||||
x.ViedoType = VideoTypeEnum.dy_collects;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//只更新图片视频的类型
|
||||
sqlSugarClient.Updateable(collectViedos).UpdateColumns(x => new DouyinVideo { ViedoType = x.ViedoType }).IgnoreColumns(true).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 重置所有Cookie的同步状态为0
|
||||
/// </summary>
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace dy.net.service
|
||||
_cookieRepository = cookieRepository;
|
||||
}
|
||||
|
||||
public Task<List<DouyinCookie>> GetAllOpendAsync(Expression<Func<DouyinCookie, bool>> whereExpression = null)
|
||||
public Task<List<DouyinCookie>> GetOpendCookiesAsync(Expression<Func<DouyinCookie, bool>> whereExpression = null)
|
||||
{
|
||||
return _cookieRepository.GetAllCookies(whereExpression);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model= JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncCollectVideos fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -160,6 +163,8 @@ namespace dy.net.service
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
var model = JsonConvert.DeserializeObject<DouyinCollectListResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncCollectFolderList fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
@@ -181,15 +186,15 @@ namespace dy.net.service
|
||||
/// <param name="cursor"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="cookie"></param>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="collectsId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public async Task<DouyinVideoInfoResponse> SyncCollectVideosByCollectId(string cursor, string count, string cookie, DouyinCollectItem collect)
|
||||
public async Task<DouyinVideoInfoResponse> SyncCollectVideosByCollectId(string cursor, string count, string cookie, string collectsId)
|
||||
{
|
||||
#region 检查参数
|
||||
if (collect is null || string.IsNullOrWhiteSpace(collect.CollectsId))
|
||||
if (string.IsNullOrWhiteSpace(collectsId))
|
||||
{
|
||||
throw new ArgumentException($"“{nameof(collect)}”不能为 null 或空。", nameof(collect));
|
||||
throw new ArgumentException($"“{nameof(collectsId)}”不能为 null 或空。", nameof(collectsId));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -217,7 +222,7 @@ namespace dy.net.service
|
||||
{
|
||||
requestParameters["cursor"] = cursor;
|
||||
requestParameters["count"] = count;
|
||||
requestParameters["collects_id"] = collect.CollectsId;
|
||||
requestParameters["collects_id"] = collectsId;
|
||||
}
|
||||
|
||||
var respose = await GetHttpResponseMessage(HttpMethod.Post, requestUrl, requestParameters, refererValue, cookie);
|
||||
@@ -225,7 +230,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model= JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncCollectVideosByCollectId fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -266,7 +274,7 @@ namespace dy.net.service
|
||||
var requestParameters = DouyinRequestParamManager.DouyinMixListParams;
|
||||
{
|
||||
// 添加动态参数
|
||||
requestParameters["count"] = "20";
|
||||
requestParameters["count"] = "100";
|
||||
requestParameters["cursor"] = cursor; //页码
|
||||
}
|
||||
|
||||
@@ -275,6 +283,8 @@ namespace dy.net.service
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
var model = JsonConvert.DeserializeObject<DouyinMixListResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncMixList fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
@@ -300,12 +310,12 @@ namespace dy.net.service
|
||||
/// <param name="mix"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public async Task<DouyinVideoInfoResponse> SyncMixViedosByMixId(string cursor, string count, string cookie, DouyinMixInfo mix)
|
||||
public async Task<DouyinVideoInfoResponse> SyncMixViedosByMixId(string cursor, string count, string cookie, string mixId)
|
||||
{
|
||||
#region 检查参数
|
||||
if (mix is null ||string.IsNullOrWhiteSpace(mix.MixId))
|
||||
if (string.IsNullOrWhiteSpace(mixId))
|
||||
{
|
||||
throw new ArgumentException($"“{nameof(mix)}”不能为 null 或空。", nameof(mix));
|
||||
throw new ArgumentException($"“{nameof(mixId)}”不能为 null 或空。", nameof(mixId));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -333,7 +343,7 @@ namespace dy.net.service
|
||||
{
|
||||
requestParameters["cursor"] = cursor;
|
||||
requestParameters["count"] = count;
|
||||
requestParameters["mix_id"] = mix.MixId;
|
||||
requestParameters["mix_id"] = mixId;
|
||||
}
|
||||
|
||||
var respose = await GetHttpResponseMessage(HttpMethod.Post, requestUrl, requestParameters, refererValue, cookie);
|
||||
@@ -341,7 +351,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model = JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncMixViedosByMixId fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -365,7 +378,7 @@ namespace dy.net.service
|
||||
/// <param name="cookie"></param>
|
||||
/// <param name="cursor"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<DouyinSeriesListResponse> SyncShortList(string cookie, string cursor)
|
||||
public async Task<DouyinSeriesListResponse> SyncSeriesList(string cookie, string cursor)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cookie))
|
||||
{
|
||||
@@ -381,7 +394,7 @@ namespace dy.net.service
|
||||
var requestParameters = DouyinRequestParamManager.DouyinSeriesListParams;
|
||||
{
|
||||
// 添加动态参数
|
||||
requestParameters["count"] = "20";
|
||||
requestParameters["count"] = "100";
|
||||
requestParameters["cursor"] = cursor; //页码
|
||||
}
|
||||
|
||||
@@ -390,6 +403,8 @@ namespace dy.net.service
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
var model = JsonConvert.DeserializeObject<DouyinSeriesListResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncShortList fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
@@ -412,15 +427,15 @@ namespace dy.net.service
|
||||
/// <param name="cursor"></param>
|
||||
/// <param name="count"></param>
|
||||
/// <param name="cookie"></param>
|
||||
/// <param name="series"></param>
|
||||
/// <param name="seriesId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public async Task<DouyinVideoInfoResponse> SyncSeriesViedosByMSeriesId(string cursor, string count, string cookie, DouyinShortDramaInfo series)
|
||||
public async Task<DouyinVideoInfoResponse> SyncSeriesViedosByMSeriesId(string cursor, string count, string cookie, string seriesId)
|
||||
{
|
||||
#region 检查参数
|
||||
if (series is null || string.IsNullOrWhiteSpace(series.DramaId))
|
||||
if (string.IsNullOrWhiteSpace(seriesId))
|
||||
{
|
||||
throw new ArgumentException($"“{nameof(series)}”不能为 null 或空。", nameof(series));
|
||||
throw new ArgumentException($"“{nameof(seriesId)}”不能为 null 或空。", nameof(seriesId));
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cursor))
|
||||
{
|
||||
@@ -448,7 +463,7 @@ namespace dy.net.service
|
||||
{
|
||||
requestParameters["cursor"] = cursor;
|
||||
requestParameters["count"] = count;
|
||||
requestParameters["series_id"] = series.DramaId;
|
||||
requestParameters["series_id"] = seriesId;
|
||||
}
|
||||
|
||||
var respose = await GetHttpResponseMessage(HttpMethod.Post, requestUrl, requestParameters, refererValue, cookie);
|
||||
@@ -456,7 +471,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model= JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncSeriesViedosByMSeriesId fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -525,7 +543,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model= JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncFavoriteVideos fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -594,7 +615,10 @@ namespace dy.net.service
|
||||
if (respose.IsSuccessStatusCode)
|
||||
{
|
||||
var data = await respose.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
var model= JsonConvert.DeserializeObject<DouyinVideoInfoResponse>(data);
|
||||
if (model == null)
|
||||
Serilog.Log.Error($"SyncUpderPostVideos fail: {data}");
|
||||
return model;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace dy.net.service
|
||||
{
|
||||
"follow_user",
|
||||
new JobConfig(
|
||||
typeof(DouyinFollowedUsersSyncJob),
|
||||
typeof(DouyinFollowsAndCollnectsSyncJob),
|
||||
"dy.job.key.follow_user",
|
||||
"dy.trigger.key.follow_user",
|
||||
"抖音关注同步任务")
|
||||
@@ -65,7 +65,7 @@ namespace dy.net.service
|
||||
{
|
||||
"follow_user_once",
|
||||
new JobConfig(
|
||||
typeof(DouyinFollowedUsersSyncJob),
|
||||
typeof(DouyinFollowsAndCollnectsSyncJob),
|
||||
"dy.job.key.follow_user_once",
|
||||
"dy.trigger.key.follow_user_once",
|
||||
"抖音关注同步任务(单次执行)")
|
||||
|
||||
Reference in New Issue
Block a user