From afb879d1af8efb0f63c5f19bd4f830d135502d43 Mon Sep 17 00:00:00 2001 From: WangRui <2271272653@qq.com> Date: Tue, 15 Dec 2020 21:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=88=86=E5=87=BA=E6=8A=95=E5=B8=81?= =?UTF-8?q?=E9=A2=86=E5=9F=9F=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DailyTaskAppService.cs | 5 +- .../Ray.BiliBiliTool.Console.csproj | 2 +- .../DonateCoinDomainService.cs | 377 ++++++++++++++++++ .../Interfaces/IDonateCoinDomainService.cs | 14 + .../Interfaces/IVideoDomainService.cs | 14 - .../VideoDomainService.cs | 255 +----------- test/DailyTaskTest/AddCoinsForVideo.cs | 4 +- test/DailyTaskTest/GetVideo.cs | 29 -- test/DailyTaskTest/IsDonatedCoinsForVideo.cs | 27 -- 9 files changed, 401 insertions(+), 326 deletions(-) create mode 100644 src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs create mode 100644 src/Ray.BiliBiliTool.DomainService/Interfaces/IDonateCoinDomainService.cs delete mode 100644 test/DailyTaskTest/GetVideo.cs delete mode 100644 test/DailyTaskTest/IsDonatedCoinsForVideo.cs diff --git a/src/Ray.BiliBiliTool.Application/DailyTaskAppService.cs b/src/Ray.BiliBiliTool.Application/DailyTaskAppService.cs index e8bca0d..68cd129 100644 --- a/src/Ray.BiliBiliTool.Application/DailyTaskAppService.cs +++ b/src/Ray.BiliBiliTool.Application/DailyTaskAppService.cs @@ -14,6 +14,7 @@ public class DailyTaskAppService : IDailyTaskAppService private readonly ILogger _logger; private readonly IAccountDomainService _loginDomainService; private readonly IVideoDomainService _videoDomainService; + private readonly IDonateCoinDomainService _donateCoinDomainService; private readonly IMangaDomainService _mangaDomainService; private readonly ILiveDomainService _liveDomainService; private readonly IVipPrivilegeDomainService _vipPrivilegeDomainService; @@ -24,6 +25,7 @@ public DailyTaskAppService( ILogger logger, IAccountDomainService loginDomainService, IVideoDomainService videoDomainService, + IDonateCoinDomainService donateCoinDomainService, IMangaDomainService mangaDomainService, ILiveDomainService liveDomainService, IVipPrivilegeDomainService vipPrivilegeDomainService, @@ -33,6 +35,7 @@ public DailyTaskAppService( _logger = logger; _loginDomainService = loginDomainService; _videoDomainService = videoDomainService; + _donateCoinDomainService = donateCoinDomainService; _mangaDomainService = mangaDomainService; _liveDomainService = liveDomainService; _vipPrivilegeDomainService = vipPrivilegeDomainService; @@ -107,7 +110,7 @@ private void WatchAndShareVideo(DailyTaskInfo dailyTaskInfo) [TaskInterceptor("投币", false)] private void AddCoinsForVideo() { - _videoDomainService.AddCoinsForVideo(); + _donateCoinDomainService.AddCoinsForVideo(); } /// diff --git a/src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj b/src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj index 1c7fc15..79b3ba3 100644 --- a/src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj +++ b/src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj @@ -4,7 +4,7 @@ Exe net5.0 Ray - 1.0.16 + 1.0.17 diff --git a/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs new file mode 100644 index 0000000..aabca16 --- /dev/null +++ b/src/Ray.BiliBiliTool.DomainService/DonateCoinDomainService.cs @@ -0,0 +1,377 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Text.Json; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Ray.BiliBiliTool.Agent; +using Ray.BiliBiliTool.Agent.BiliBiliAgent; +using Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos; +using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces; +using Ray.BiliBiliTool.Config; +using Ray.BiliBiliTool.Config.Options; +using Ray.BiliBiliTool.DomainService.Interfaces; +using Ray.BiliBiliTool.Infrastructure.Helpers; + +namespace Ray.BiliBiliTool.DomainService +{ + /// + /// 投币 + /// + public class DonateCoinDomainService : IDonateCoinDomainService + { + private readonly ILogger _logger; + private readonly IDailyTaskApi _dailyTaskApi; + private readonly BiliBiliCookieOptions _biliBiliCookieOptions; + private readonly DailyTaskOptions _dailyTaskOptions; + private readonly IAccountApi _accountApi; + private readonly ICoinDomainService _coinDomainService; + private readonly IRelationApi _relationApi; + + public DonateCoinDomainService(ILogger logger, + IDailyTaskApi dailyTaskApi, + BiliBiliCookieOptions biliBiliCookieOptions, + DailyTaskOptions dailyTaskOptions, + IAccountApi accountApi, + ICoinDomainService coinDomainService, + IRelationApi relationApi) + { + _logger = logger; + _dailyTaskApi = dailyTaskApi; + _biliBiliCookieOptions = biliBiliCookieOptions; + _dailyTaskOptions = dailyTaskOptions; + _accountApi = accountApi; + _coinDomainService = coinDomainService; + _relationApi = relationApi; + } + + /// + /// 完成投币任务 + /// + public void AddCoinsForVideo() + { + int needCoins = GetNeedDonateCoinNum(out int alreadyCoins, out int targetCoins); + _logger.LogInformation("今日已投{already}枚硬币,目标是投{target}枚硬币", alreadyCoins, targetCoins); + + if (needCoins <= 0) + { + _logger.LogInformation("已经完成投币任务,今天不需要再投啦"); + return; + } + + _logger.LogInformation("还需再投{need}枚硬币", needCoins); + + //投币前硬币余额 + decimal coinBalance = _coinDomainService.GetCoinBalance(); + _logger.LogInformation("投币前余额为 : {coinBalance}", coinBalance); + + if (coinBalance <= 0) + { + _logger.LogInformation("因硬币余额不足,今日暂不执行投币任务"); + return; + } + + //余额小于目标投币数,按余额投 + if (coinBalance < needCoins) + { + int.TryParse(decimal.Truncate(coinBalance).ToString(), out needCoins); + _logger.LogInformation("因硬币余额不足,目标投币数调整为: {needCoins}", needCoins); + } + + int successCoins = 0; + int tryCount = 0;//投币最多操作数 解决异常导致死循环的问题 + while (successCoins < needCoins) + { + tryCount++; + + Tuple video = TryGetCanDonatedVideo(); + if (video == null) + { + if (tryCount <= 10) continue; + _logger.LogInformation("尝试投币次数超过10次,投币任务终止"); + break; + } + + _logger.LogDebug("正在为视频“{title}”投币", video.Item2); + + bool isSuccess = AddCoinsForVideo(video.Item1, 1, _dailyTaskOptions.SelectLike, video.Item2); + if (isSuccess) + { + successCoins++; + } + + if (tryCount > 10) + { + _logger.LogInformation("尝试投币次数超过10次,投币任务终止"); + break; + } + } + + _logger.LogInformation("投币任务完成,余额为: {money}", _accountApi.GetCoinBalance().Result.Data.Money); + + } + + /// + /// 获取今日的目标投币数 + /// + /// + /// + /// + private int GetNeedDonateCoinNum(out int alreadyCoins, out int targetCoins) + { + int needCoins = 0; + + //获取自定义配置投币数 + int configCoins = _dailyTaskOptions.NumberOfCoins; + //已投的硬币 + alreadyCoins = _coinDomainService.GetDonatedCoins(); + //目标 + targetCoins = configCoins > Constants.MaxNumberOfDonateCoins + ? Constants.MaxNumberOfDonateCoins + : configCoins; + + if (targetCoins > alreadyCoins) + { + return targetCoins - alreadyCoins; + } + return needCoins; + } + + /// + /// 尝试获取一个没有投币过的视频 + /// + /// + public Tuple TryGetCanDonatedVideo() + { + Tuple result = null; + + //如果配置upID,则从up中随机尝试获取10次 + if (_dailyTaskOptions.SupportUpIdList.Count > 0) + { + result = TryGetCanDonatedVideoByUp(10); + if (result != null) return result; + } + + //然后从特别关注列表尝试获取10次 + result = TryGetCanDonatedVideoBySpecialUps(10); + if (result != null) return result; + + //然后从普通关注列表获取10次 + result = TryGetCanDonatedVideoByFollowingUps(10); + if (result != null) return result; + + //最后从排行榜尝试5次 + result = TryGetNotDonatedVideoByRegion(5); + + return result; + } + + /// + /// 尝试从配置的up主里随机获取一个可以投币的视频 + /// + /// + /// + public Tuple TryGetCanDonatedVideoByUp(int tryCount) + { + //是否配置了up主 + if (_dailyTaskOptions.SupportUpIdList.Count == 0) return null; + + return TryGetCanDonateVideoByUps(_dailyTaskOptions.SupportUpIdList, tryCount); ; + } + + /// + /// 尝试从特别关注的Up主中随机获取一个可以投币的视频 + /// + /// + /// + public Tuple TryGetCanDonatedVideoBySpecialUps(int tryCount) + { + //缓存每个up的视频总数 + Dictionary videoCountDic = new Dictionary(); + + //获取特别关注列表 + BiliApiResponse> specials = _relationApi.GetSpecialFollowings().Result; + if (specials.Data == null || specials.Data.Count == 0) return null; + + return TryGetCanDonateVideoByUps(specials.Data.Select(x => x.Mid).ToList(), tryCount); + } + + /// + /// 尝试从特别关注的Up主中随机获取一个可以投币的视频 + /// + /// + /// + public Tuple TryGetCanDonatedVideoByFollowingUps(int tryCount) + { + //缓存每个up的视频总数 + Dictionary videoCountDic = new Dictionary(); + + //获取特别关注列表 + BiliApiResponse result = _relationApi.GetFollowings(_biliBiliCookieOptions.UserId).Result; + if (result.Data.Total == 0) return null; + + return TryGetCanDonateVideoByUps(result.Data.List.Select(x => x.Mid).ToList(), tryCount); + } + + /// + /// 尝试从排行榜中获取一个没有看过的视频 + /// + /// + /// + public Tuple TryGetNotDonatedVideoByRegion(int tryCount) + { + if (tryCount <= 0) return null; + + for (int i = 0; i < tryCount; i++) + { + Tuple video = RegionRanking(); + if (!CanDonatedCoinsForVideo(video.Item1)) continue; + return video; + } + + return null; + } + + /// + /// 尝试从指定的up主Id集合中随机获取一个可以投币的视频 + /// + /// + /// + /// + private Tuple TryGetCanDonateVideoByUps(List upIds, int tryCount) + { + //缓存每个up的视频总数 + Dictionary videoCountDic = new Dictionary(); + + //获取特别关注列表 + if (upIds == null || upIds.Count == 0) return null; + + //尝试tryCount次 + for (int i = 0; i < tryCount; i++) + { + //获取随机Up主Id + long randomUpId = upIds[new Random().Next(0, upIds.Count)]; + if (!videoCountDic.TryGetValue(randomUpId, out int videoCount)) + { + videoCount = GetVidoeCountOfUp(randomUpId); + videoCountDic.Add(randomUpId, videoCount); + } + if (videoCount == 0) continue; + + UpVideoInfo videoInfo = GetRandomVideoOfUp(randomUpId, videoCount); + if (!CanDonatedCoinsForVideo(videoInfo.Aid.ToString())) continue; + return Tuple.Create(videoInfo.Aid.ToString(), videoInfo.Title); + } + + return null; + } + + /// + /// 获取随机视频aid + /// + /// 分区id + /// 日榜,三日榜 周榜 1,3,7 + /// 随机返回一个aid + private Tuple RegionRanking() + { + int[] arr = { 1, 3, 4, 5, 160, 22, 119 }; + int rid = arr[new Random().Next(arr.Length - 1)]; + + BiliApiResponse> apiResponse = _dailyTaskApi.GetRegionRankingVideos(rid, 3).Result; + + //_logger.LogInformation("获取分区:{rid}的{day}日top10榜单成功", rid, day); + RankingInfo data = apiResponse.Data[new Random().Next(apiResponse.Data.Count)]; + + return Tuple.Create(data.Aid, data.Title); + } + + + /// + /// 是否已为视频投币 + /// + /// av号 + /// + public bool CanDonatedCoinsForVideo(string aid) + { + int multiply = _dailyTaskApi.GetDonatedCoinsForVideo(aid).Result.Data.Multiply; + if (multiply < 2) + { + _logger.LogDebug("已为Av" + aid + "投过" + multiply + "枚硬币,可以继续投币"); + return true; + } + else + { + _logger.LogDebug("已为Av" + aid + " 投过2枚硬币,不能再投币啦"); + return false; + } + } + + /// + /// 获取UP主的视频总数量 + /// + /// + /// + private int GetVidoeCountOfUp(long upId) + { + BiliApiResponse re = _dailyTaskApi.SearchVideosByUpId(upId, 1, 1).Result; + if (re.Code != 0) + { + throw new Exception(re.Message); + } + + return re.Data.Page.Count; + } + + /// + /// 获取某up的一个随机视频 + /// + /// + /// + /// + private UpVideoInfo GetRandomVideoOfUp(long upId, int total) + { + int pageNum = new Random().Next(1, total + 1); + BiliApiResponse re = _dailyTaskApi.SearchVideosByUpId(upId, 1, pageNum).Result; + + if (re.Code != 0) + { + throw new Exception(re.Message); + } + + return re.Data.List.Vlist.First(); + } + + /// + /// 为视频投币 + /// + /// av号 + /// 投币数量 + /// 是否同时点赞 1是0否 + /// 是否投币成功 + public bool AddCoinsForVideo(string aid, int multiply, bool select_like, string title = "") + { + BiliApiResponse result = _dailyTaskApi.AddCoinForVideo(aid, multiply, select_like ? 1 : 0, _biliBiliCookieOptions.BiliJct).Result; + + if (result.Code == 0) + { + _logger.LogInformation("为“{title}”投币成功", title); + return true; + } + + if (result.Code == -111) + { + string errorMsg = $"投币异常,Cookie配置项[BiliJct]错误或已过期,请检查并更新。接口返回:{result.Message}"; + _logger.LogError(errorMsg); + throw new Exception(errorMsg); + } + else + { + _logger.LogInformation("为“{title}”投币失败,原因:{msg}", title, result.Message); + return false; + } + } + + } +} diff --git a/src/Ray.BiliBiliTool.DomainService/Interfaces/IDonateCoinDomainService.cs b/src/Ray.BiliBiliTool.DomainService/Interfaces/IDonateCoinDomainService.cs new file mode 100644 index 0000000..b6c6691 --- /dev/null +++ b/src/Ray.BiliBiliTool.DomainService/Interfaces/IDonateCoinDomainService.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Ray.BiliBiliTool.DomainService.Interfaces +{ + /// + /// 投币 + /// + public interface IDonateCoinDomainService : IDomainService + { + void AddCoinsForVideo(); + } +} diff --git a/src/Ray.BiliBiliTool.DomainService/Interfaces/IVideoDomainService.cs b/src/Ray.BiliBiliTool.DomainService/Interfaces/IVideoDomainService.cs index bdf71a7..bbca651 100644 --- a/src/Ray.BiliBiliTool.DomainService/Interfaces/IVideoDomainService.cs +++ b/src/Ray.BiliBiliTool.DomainService/Interfaces/IVideoDomainService.cs @@ -36,11 +36,6 @@ public interface IVideoDomainService : IDomainService /// void ShareVideo(string aid, string title = ""); - /// - /// 投币 - /// - void AddCoinsForVideo(); - /// /// 投币 /// @@ -50,15 +45,6 @@ public interface IVideoDomainService : IDomainService /// bool AddCoinsForVideo(string aid, int multiply, bool select_like, string title = ""); - /// - /// 是否已对某视频投币 - /// - /// - /// - bool CanDonatedCoinsForVideo(string aid); - List GetRandomVideosOfUps(); - - Tuple TryGetCanDonatedVideo(); } } diff --git a/src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs b/src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs index 2e0b0b2..65ab697 100644 --- a/src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs +++ b/src/Ray.BiliBiliTool.DomainService/VideoDomainService.cs @@ -20,25 +20,16 @@ public class VideoDomainService : IVideoDomainService private readonly IDailyTaskApi _dailyTaskApi; private readonly BiliBiliCookieOptions _biliBiliCookieOptions; private readonly DailyTaskOptions _dailyTaskOptions; - private readonly IAccountApi _accountApi; - private readonly ICoinDomainService _coinDomainService; - private readonly IRelationApi _relationApi; public VideoDomainService(ILogger logger, IDailyTaskApi dailyTaskApi, IOptionsMonitor biliBiliCookieOptions, - IOptionsMonitor dailyTaskOptions, - IAccountApi accountApi, - ICoinDomainService coinDomainService, - IRelationApi relationApi) + IOptionsMonitor dailyTaskOptions) { _logger = logger; _dailyTaskApi = dailyTaskApi; _biliBiliCookieOptions = biliBiliCookieOptions.CurrentValue; _dailyTaskOptions = dailyTaskOptions.CurrentValue; - _accountApi = accountApi; - _coinDomainService = coinDomainService; - _relationApi = relationApi; } /// @@ -107,91 +98,6 @@ public void ShareVideo(string aid, string title = "") } } - /// - /// 是否已为视频投币 - /// - /// av号 - /// - public bool CanDonatedCoinsForVideo(string aid) - { - int multiply = _dailyTaskApi.GetDonatedCoinsForVideo(aid).Result.Data.Multiply; - if (multiply < 2) - { - _logger.LogDebug("已为Av" + aid + "投过" + multiply + "枚硬币,可以继续投币"); - return true; - } - else - { - _logger.LogDebug("已为Av" + aid + " 投过2枚硬币,不能再投币啦"); - return false; - } - } - - /// - /// 投币 - /// - public void AddCoinsForVideo() - { - int needCoins = GetNeedDonateCoins(out int alreadyCoins, out int targetCoins); - _logger.LogInformation("今日已投{already}枚硬币,目标是投{target}枚硬币", alreadyCoins, targetCoins); - - if (needCoins <= 0) - { - _logger.LogInformation("已经完成投币任务,今天不需要再投啦"); - return; - } - - _logger.LogInformation("还需再投{need}枚硬币", needCoins); - - //投币前硬币余额 - decimal coinBalance = _coinDomainService.GetCoinBalance(); - _logger.LogInformation("投币前余额为 : {coinBalance}", coinBalance); - - if (coinBalance <= 0) - { - _logger.LogInformation("因硬币余额不足,今日暂不执行投币任务"); - return; - } - - //余额小于目标投币数,按余额投 - if (coinBalance < needCoins) - { - int.TryParse(decimal.Truncate(coinBalance).ToString(), out needCoins); - _logger.LogInformation("因硬币余额不足,目标投币数调整为: {needCoins}", needCoins); - } - - int successCoins = 0; - int tryCount = 0;//投币最多操作数 解决异常导致死循环的问题 - while (successCoins < needCoins) - { - tryCount++; - - Tuple video = TryGetCanDonatedVideo(); - if (video == null) - { - if (tryCount <= 10) continue; - _logger.LogInformation("尝试投币次数超过10次,投币任务终止"); - break; - } - - _logger.LogDebug("正在为视频“{title}”投币", video.Item2); - - bool isSuccess = AddCoinsForVideo(video.Item1, 1, _dailyTaskOptions.SelectLike, video.Item2); - if (isSuccess) - { - successCoins++; - } - - if (tryCount > 10) - { - _logger.LogInformation("尝试投币次数超过10次,投币任务终止"); - break; - } - } - - _logger.LogInformation("投币任务完成,余额为: {money}", _accountApi.GetCoinBalance().Result.Data.Money); - } - /// /// 为视频投币 /// @@ -222,135 +128,6 @@ public bool AddCoinsForVideo(string aid, int multiply, bool select_like, string } } - /// - /// 尝试获取一个没有投币过的视频 - /// - /// - public Tuple TryGetCanDonatedVideo() - { - Tuple result = null; - - //如果配置upID,则从up中随机尝试获取10次 - if (_dailyTaskOptions.SupportUpIdList.Count > 0) - { - result = TryGetCanDonatedVideoByUp(10); - if (result != null) return result; - } - - //然后从特别关注列表尝试获取10次 - result = TryGetCanDonatedVideoBySpecialUps(10); - if (result != null) return result; - - //然后从普通关注列表获取10次 - result = TryGetCanDonatedVideoByFollowingUps(10); - if (result != null) return result; - - //最后从排行榜尝试5次 - result = TryGetNotDonatedVideoByRegion(5); - - return result; - } - - /// - /// 尝试从配置的up主里随机获取一个可以投币的视频 - /// - /// - /// - public Tuple TryGetCanDonatedVideoByUp(int tryCount) - { - //是否配置了up主 - if (_dailyTaskOptions.SupportUpIdList.Count == 0) return null; - - return TryGetCanDonateVideoByUps(_dailyTaskOptions.SupportUpIdList, tryCount); ; - } - - /// - /// 尝试从特别关注的Up主中随机获取一个可以投币的视频 - /// - /// - /// - public Tuple TryGetCanDonatedVideoBySpecialUps(int tryCount) - { - //缓存每个up的视频总数 - Dictionary videoCountDic = new Dictionary(); - - //获取特别关注列表 - BiliApiResponse> specials = _relationApi.GetSpecialFollowings().Result; - if (specials.Data == null || specials.Data.Count == 0) return null; - - return TryGetCanDonateVideoByUps(specials.Data.Select(x => x.Mid).ToList(), tryCount); - } - - /// - /// 尝试从特别关注的Up主中随机获取一个可以投币的视频 - /// - /// - /// - public Tuple TryGetCanDonatedVideoByFollowingUps(int tryCount) - { - //缓存每个up的视频总数 - Dictionary videoCountDic = new Dictionary(); - - //获取特别关注列表 - BiliApiResponse result = _relationApi.GetFollowings(_biliBiliCookieOptions.UserId).Result; - if (result.Data.Total == 0) return null; - - return TryGetCanDonateVideoByUps(result.Data.List.Select(x => x.Mid).ToList(), tryCount); - } - - /// - /// 尝试从指定的up主Id集合中随机获取一个可以投币的视频 - /// - /// - /// - /// - private Tuple TryGetCanDonateVideoByUps(List upIds, int tryCount) - { - //缓存每个up的视频总数 - Dictionary videoCountDic = new Dictionary(); - - //获取特别关注列表 - if (upIds == null || upIds.Count == 0) return null; - - //尝试tryCount次 - for (int i = 0 ; i < tryCount ; i++) - { - //获取随机Up主Id - long randomUpId = upIds[new Random().Next(0, upIds.Count)]; - if (!videoCountDic.TryGetValue(randomUpId, out int videoCount)) - { - videoCount = GetVidoeCountOfUp(randomUpId); - videoCountDic.Add(randomUpId, videoCount); - } - if (videoCount == 0) continue; - - UpVideoInfo videoInfo = GetRandomVideoOfUp(randomUpId, videoCount); - if (!CanDonatedCoinsForVideo(videoInfo.Aid.ToString())) continue; - return Tuple.Create(videoInfo.Aid.ToString(), videoInfo.Title); - } - - return null; - } - - /// - /// 尝试从排行榜中获取一个没有看过的视频 - /// - /// - /// - public Tuple TryGetNotDonatedVideoByRegion(int tryCount) - { - if (tryCount <= 0) return null; - - for (int i = 0 ; i < tryCount ; i++) - { - Tuple video = RegionRanking(); - if (!CanDonatedCoinsForVideo(video.Item1)) continue; - return video; - } - - return null; - } - public List GetRandomVideosOfUps() { List re = new List(); @@ -363,7 +140,7 @@ public List GetRandomVideosOfUps() int targetNum = 10; if (count < 10) targetNum = count; - for (int i = 0 ; i < targetNum ; i++) + for (int i = 0; i < targetNum; i++) { UpVideoInfo videoInfo = GetRandomVideoOfUp(upId, count); if (re.Count(x => x.Aid == videoInfo.Aid) == 0) re.Add(videoInfo); @@ -422,32 +199,6 @@ private Tuple RegionRanking() return Tuple.Create(data.Aid, data.Title); } - /// - /// 获取今日的目标投币数 - /// - /// - /// - /// - private int GetNeedDonateCoins(out int alreadyCoins, out int targetCoins) - { - int needCoins = 0; - - //获取自定义配置投币数 - int configCoins = _dailyTaskOptions.NumberOfCoins; - //已投的硬币 - alreadyCoins = _coinDomainService.GetDonatedCoins(); - //目标 - targetCoins = configCoins > Constants.MaxNumberOfDonateCoins - ? Constants.MaxNumberOfDonateCoins - : configCoins; - - if (targetCoins > alreadyCoins) - { - return targetCoins - alreadyCoins; - } - return needCoins; - } - private Tuple GetRandomVideoForWatch() { List list = GetRandomVideosOfUps(); @@ -459,4 +210,4 @@ private Tuple GetRandomVideoForWatch() #endregion private } -} \ No newline at end of file +} diff --git a/test/DailyTaskTest/AddCoinsForVideo.cs b/test/DailyTaskTest/AddCoinsForVideo.cs index 35e7826..9ce8f15 100644 --- a/test/DailyTaskTest/AddCoinsForVideo.cs +++ b/test/DailyTaskTest/AddCoinsForVideo.cs @@ -16,9 +16,9 @@ public void Test1() using (var scope = RayContainer.Root.CreateScope()) { - var dailyTaskAppService = scope.ServiceProvider.GetRequiredService(); + var service = scope.ServiceProvider.GetRequiredService(); - dailyTaskAppService.AddCoinsForVideo(); + service.AddCoinsForVideo(); } Assert.True(true); diff --git a/test/DailyTaskTest/GetVideo.cs b/test/DailyTaskTest/GetVideo.cs deleted file mode 100644 index f983ac9..0000000 --- a/test/DailyTaskTest/GetVideo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Ray.BiliBiliTool.Agent.BiliBiliAgent.Interfaces; -using Ray.BiliBiliTool.Config.Options; -using Ray.BiliBiliTool.Console; -using Ray.BiliBiliTool.DomainService.Interfaces; -using Ray.BiliBiliTool.Infrastructure; -using Xunit; - -namespace WatchVideoTest -{ - public class GetVideo - { - [Fact] - public void Test1() - { - Program.PreWorks(new string[] { }); - - using (var scope = RayContainer.Root.CreateScope()) - { - var dailyTask = scope.ServiceProvider.GetRequiredService(); - - var re = dailyTask.TryGetCanDonatedVideo(); - - Assert.True(re != null); - } - } - } -} diff --git a/test/DailyTaskTest/IsDonatedCoinsForVideo.cs b/test/DailyTaskTest/IsDonatedCoinsForVideo.cs deleted file mode 100644 index ad396f1..0000000 --- a/test/DailyTaskTest/IsDonatedCoinsForVideo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using Ray.BiliBiliTool.Console; -using Ray.BiliBiliTool.DomainService.Interfaces; -using Ray.BiliBiliTool.Infrastructure; -using Xunit; - -namespace DailyTaskTest -{ - public class IsDonatedCoinsForVideo - { - [Fact] - public void Test1() - { - Program.PreWorks(new string[] { }); - - using (var scope = RayContainer.Root.CreateScope()) - { - var dailyTask = scope.ServiceProvider.GetRequiredService(); - - string aid = "500168790"; - bool result = dailyTask.CanDonatedCoinsForVideo(aid); - Assert.False(false); - } - } - } -}