Ejemplo n.º 1
0
        /// <summary>
        /// 从up集合中获取一个随机视频
        /// </summary>
        /// <param name="upIds"></param>
        /// <returns></returns>
        private VideoInfoDto GetRandomVideoOfUps(List <long> upIds)
        {
            long upId = upIds[new Random().Next(0, upIds.Count)];

            if (upId == 0 || upId == long.MinValue)
            {
                return(null);
            }

            int count = GetVideoCountOfUp(upId);

            if (count > 0)
            {
                UpVideoInfo video = GetRandomVideoOfUp(upId, count);
                return(new VideoInfoDto
                {
                    Aid = video.Aid.ToString(),
                    Bvid = video.Bvid,
                    //Cid=,
                    //Copyright=
                    Title = video.Title,
                    Duration = video.Duration
                });
            }

            return(null);
        }
Ejemplo n.º 2
0
        public List <UpVideoInfo> GetRandomVideosOfUps()
        {
            var re = new List <UpVideoInfo>();

            int configUpsCount = _dailyTaskOptions.SupportUpIdList.Count;

            if (configUpsCount == 0)
            {
                return(re);
            }

            long upId  = _dailyTaskOptions.SupportUpIdList[new Random().Next(0, configUpsCount)];
            int  count = GetVidoeCountOfUp(upId);

            var targetNum = 10;

            if (count < 10)
            {
                targetNum = count;
            }
            for (int i = 0; i < targetNum; i++)
            {
                UpVideoInfo videoInfo = GetRandomVideoOfUp(upId, count);
                if (re.Count(x => x.Aid == videoInfo.Aid) == 0)
                {
                    re.Add(videoInfo);
                }
            }

            return(re);
        }
        /// <summary>
        /// 尝试从指定的up主集合中随机获取一个可以尝试投币的视频
        /// </summary>
        /// <param name="upIds"></param>
        /// <param name="tryCount"></param>
        /// <returns></returns>
        private Tuple <string, string> TryCanDonateVideoByUps(List <long> upIds, int tryCount)
        {
            if (upIds == null || upIds.Count == 0)
            {
                return(null);
            }

            try
            {
                //尝试tryCount次
                for (int i = 1; i <= tryCount; i++)
                {
                    //获取随机Up主Id
                    long randomUpId = upIds[new Random().Next(0, upIds.Count)];

                    if (randomUpId == 0 || randomUpId == long.MinValue)
                    {
                        continue;
                    }

                    if (randomUpId.ToString() == _biliBiliCookie.UserId)
                    {
                        _logger.LogDebug("不能为自己投币");
                        continue;
                    }

                    //该up的视频总数
                    if (!_upVideoCountDicCatch.TryGetValue(randomUpId, out int videoCount))
                    {
                        videoCount = _videoDomainService.GetVideoCountOfUp(randomUpId);
                        _upVideoCountDicCatch.Add(randomUpId, videoCount);
                    }
                    if (videoCount == 0)
                    {
                        continue;
                    }

                    UpVideoInfo videoInfo = _videoDomainService.GetRandomVideoOfUp(randomUpId, videoCount);
                    _logger.LogDebug("获取到视频{aid}({title})", videoInfo.Aid, videoInfo.Title);

                    //检查是否可以投
                    if (!IsCanDonate(videoInfo.Aid.ToString()))
                    {
                        continue;
                    }

                    return(Tuple.Create(videoInfo.Aid.ToString(), videoInfo.Title));
                }
            }
            catch (Exception e)
            {
                //ignore
                _logger.LogWarning("异常:{msg}", e);
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从up集合中获取一个随机视频
        /// </summary>
        /// <param name="upIds"></param>
        /// <returns></returns>
        private Tuple <string, string> GetRandomVideoOfUps(List <long> upIds)
        {
            long upId = upIds[new Random().Next(0, upIds.Count)];

            int count = GetVideoCountOfUp(upId);

            if (count > 0)
            {
                UpVideoInfo video = GetRandomVideoOfUp(upId, count);
                return(Tuple.Create <string, string>(video.Aid.ToString(), video.Title));
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 从up集合中获取一个随机视频
        /// </summary>
        /// <param name="upIds"></param>
        /// <returns></returns>
        private VideoInfoDto GetRandomVideoOfUps(List <long> upIds)
        {
            long upId = upIds[new Random().Next(0, upIds.Count)];

            int count = GetVideoCountOfUp(upId);

            if (count > 0)
            {
                UpVideoInfo video = GetRandomVideoOfUp(upId, count);
                return(new VideoInfoDto
                {
                    Aid = video.Aid.ToString(),
                    Title = video.Title,
                    SecondsLength = video.SecondsLength
                });
            }

            return(null);
        }
        /// <summary>
        /// 尝试从指定的up主Id集合中随机获取一个可以投币的视频
        /// </summary>
        /// <param name="upIds"></param>
        /// <param name="tryCount"></param>
        /// <returns></returns>
        private Tuple <string, string> TryGetCanDonateVideoByUps(List <long> upIds, int tryCount)
        {
            //缓存每个up的视频总数
            Dictionary <long, int> videoCountDic = new Dictionary <long, int>();

            //获取特别关注列表
            if (upIds == null || upIds.Count == 0)
            {
                return(null);
            }

            //尝试tryCount次
            for (int i = 1; i <= tryCount; i++)
            {
                //获取随机Up主Id
                long randomUpId = upIds[new Random().Next(0, upIds.Count)];

                //该up的视频总数
                if (!videoCountDic.TryGetValue(randomUpId, out int videoCount))
                {
                    videoCount = _videoDomainService.GetVideoCountOfUp(randomUpId);
                    videoCountDic.Add(randomUpId, videoCount);
                }
                if (videoCount == 0 | videoCount < i)
                {
                    continue;
                }

                UpVideoInfo videoInfo = _videoDomainService.GetRandomVideoOfUp(randomUpId, videoCount);

                if (!CanDonatedCoinsForVideo(videoInfo.Aid.ToString()))
                {
                    continue;
                }
                return(Tuple.Create(videoInfo.Aid.ToString(), videoInfo.Title));
            }

            return(null);
        }
Ejemplo n.º 7
0
        public Tuple <string, string> TryGetNotDonatedVideoByUp(int tryCount)
        {
            if (_dailyTaskOptions.SupportUpIdList.Count == 0)
            {
                return(null);
            }

            //获取每个up的视频总数
            Dictionary <long, int> videoCountDic = new Dictionary <long, int>();

            foreach (var item in _dailyTaskOptions.SupportUpIdList)
            {
                var count = GetVidoeCountOfUp(item);
                if (count > 0)
                {
                    videoCountDic.Add(item, count);
                }
            }
            if (videoCountDic.Count == 0)
            {
                return(null);
            }

            //尝试tryCount次
            for (int i = 0; i < tryCount; i++)
            {
                long randomUpId = videoCountDic.Keys.ToList()[new Random().Next(0, videoCountDic.Count)];
                int  videoCount = videoCountDic[randomUpId];

                UpVideoInfo videoInfo = GetRandomVideoOfUp(randomUpId, videoCount);
                if (IsDonatedCoinsForVideo(videoInfo.Aid.ToString()))
                {
                    continue;
                }
                return(Tuple.Create(videoInfo.Aid.ToString(), videoInfo.Title));
            }

            return(null);
        }