コード例 #1
0
        /// <summary>
        /// 尝试从特别关注的Up主中随机获取一个可以投币的视频
        /// </summary>
        /// <param name="tryCount"></param>
        /// <returns></returns>
        private Tuple <string, string> TryGetCanDonateVideoBySpecialUps(int tryCount)
        {
            //获取特别关注列表
            var request = new GetSpecialFollowingsRequest(long.Parse(_biliBiliCookie.UserId));
            BiliApiResponse <List <UpInfo> > specials = _relationApi.GetSpecialFollowings(request)
                                                        .GetAwaiter().GetResult();

            if (specials.Data == null || specials.Data.Count == 0)
            {
                return(null);
            }

            return(TryCanDonateVideoByUps(specials.Data.Select(x => x.Mid).ToList(), tryCount));
        }
コード例 #2
0
        public void GetSpecialFollowings()
        {
            Program.CreateHost(new string[] { });

            using (var scope = Global.ServiceProviderRoot.CreateScope())
            {
                var api    = scope.ServiceProvider.GetRequiredService <IRelationApi>();
                var cookie = scope.ServiceProvider.GetRequiredService <BiliCookie>();

                var request = new GetSpecialFollowingsRequest(long.Parse(cookie.UserId));
                var re      = api.GetSpecialFollowings(request).Result;

                Assert.True(re.Code == 0);
            }
        }
コード例 #3
0
        /// <summary>
        /// 取关
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="count"></param>
        public void UnfollowBatched(string groupName, int count)
        {
            _logger.LogInformation("【分组名】{group}", groupName);

            //根据分组名称获取tag
            TagDto tag   = GetTag(groupName);
            int?   tagId = tag?.Tagid;
            int    total = tag?.Count ?? 0;

            if (!tagId.HasValue)
            {
                _logger.LogWarning("分组名称不存在");
                return;
            }

            if (total == 0)
            {
                _logger.LogWarning("分组下不存在up");
                return;
            }

            if (count == -1)
            {
                count = total;
            }

            _logger.LogInformation("【分组下共有】{count}人", total);
            _logger.LogInformation("【目标取关】{count}人" + Environment.NewLine, count);

            //计算共几页
            int totalPage = (int)Math.Ceiling(total / (double)20);

            //从最后一页开始获取
            var req = new GetSpecialFollowingsRequest(long.Parse(_cookie.UserId), tagId.Value)
            {
                Pn = totalPage
            };
            List <UpInfo> followings = _relationApi.GetFollowingsByTag(req)
                                       .GetAwaiter().GetResult()
                                       .Data;

            followings.Reverse();

            var targetList = new List <UpInfo>();

            if (count <= followings.Count)
            {
                targetList = followings.Take(count).ToList();
            }
            else
            {
                int pn = totalPage;
                while (targetList.Count < count)
                {
                    targetList.AddRange(followings);

                    //获取前一页
                    pn -= 1;
                    if (pn <= 0)
                    {
                        break;
                    }
                    req.Pn     = pn;
                    followings = _relationApi.GetFollowingsByTag(req)
                                 .GetAwaiter().GetResult()
                                 .Data;
                    followings.Reverse();
                }
            }

            _logger.LogInformation("开始取关..." + Environment.NewLine);
            int success = 0;

            for (int i = 1; i <= targetList.Count && i <= count; i++)
            {
                UpInfo info = targetList[i - 1];

                _logger.LogInformation("【序号】{num}", i);
                _logger.LogInformation("【UP】{up}", info.Uname);

                string modifyReferer = string.Format(RelationApiConstant.ModifyReferer, _cookie.UserId, tagId);
                var    modifyReq     = new ModifyRelationRequest(info.Mid, _cookie.BiliJct);
                var    re            = _relationApi.ModifyRelation(modifyReq, modifyReferer)
                                       .GetAwaiter().GetResult();

                if (re.Code == 0)
                {
                    _logger.LogInformation("【取关结果】成功" + Environment.NewLine);
                    success++;
                }
                else
                {
                    _logger.LogInformation("【取关结果】失败");
                    _logger.LogInformation("【原因】{msg}" + Environment.NewLine, re.Message);
                }
            }

            _logger.LogInformation("【本次共取关】{count}人", success);

            //计算剩余
            tag = GetTag(groupName);
            _logger.LogInformation("【分组下剩余】{count}人", tag?.Count ?? 0);
        }