예제 #1
0
        private VideoInfoDto GetRandomVideoOfFollowingUps()
        {
            //配置的UpId
            int configUpsCount = _dailyTaskOptions.SupportUpIdList.Count;

            if (configUpsCount > 0)
            {
                VideoInfoDto video = GetRandomVideoOfUps(_dailyTaskOptions.SupportUpIdList);
                if (video != null)
                {
                    return(video);
                }
            }

            //关注列表
            var request = new GetFollowingsRequest(long.Parse(_biliBiliCookie.UserId));
            BiliApiResponse <GetFollowingsResponse> result = _relationApi.GetFollowings(request)
                                                             .GetAwaiter().GetResult();

            if (result.Data.Total > 0)
            {
                VideoInfoDto video = GetRandomVideoOfUps(result.Data.List.Select(x => x.Mid).ToList());
                if (video != null)
                {
                    return(video);
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// 模拟打开视频播放(初始上报一次进度)
        /// </summary>
        /// <param name="videoInfo"></param>
        /// <returns></returns>
        private bool OpenVideo(VideoInfoDto videoInfo)
        {
            var request = new UploadVideoHeartbeatRequest
            {
                Aid  = long.Parse(videoInfo.Aid),
                Bvid = videoInfo.Bvid,
                Cid  = videoInfo.Cid,

                Mid  = long.Parse(_biliBiliCookie.UserId),
                Csrf = _biliBiliCookie.BiliJct,
            };

            //开始上报一次
            BiliApiResponse apiResponse = _videoApi.UploadVideoHeartbeat(request)
                                          .GetAwaiter().GetResult();

            if (apiResponse.Code == 0)
            {
                _logger.LogDebug("打开视频成功");
                return(true);
            }
            else
            {
                _logger.LogError("视频打开失败,原因:{msg}", apiResponse.Message);
                return(false);
            }
        }
예제 #3
0
        /// <summary>
        /// 观看视频
        /// </summary>
        public void WatchVideo(VideoInfoDto videoInfo)
        {
            //开始上报一次
            OpenVideo(videoInfo);

            //结束上报一次
            videoInfo.Duration = videoInfo.Duration ?? 15;
            int max        = videoInfo.Duration < 15 ? videoInfo.Duration.Value : 15;
            int playedTime = new Random().Next(1, max);

            var request = new UploadVideoHeartbeatRequest
            {
                Aid  = long.Parse(videoInfo.Aid),
                Bvid = videoInfo.Bvid,
                Cid  = videoInfo.Cid,
                Mid  = long.Parse(_biliBiliCookie.UserId),
                Csrf = _biliBiliCookie.BiliJct,

                Played_time      = playedTime,
                Realtime         = playedTime,
                Real_played_time = playedTime,
            };
            BiliApiResponse apiResponse = _videoApi.UploadVideoHeartbeat(request)
                                          .GetAwaiter().GetResult();

            if (apiResponse.Code == 0)
            {
                _expDic.TryGetValue("每日观看视频", out int exp);
                _logger.LogInformation("视频播放成功,已观看到第{playedTime}秒,经验+{exp} √", playedTime, exp);
            }
            else
            {
                _logger.LogError("视频播放失败,原因:{msg}", apiResponse.Message);
            }
        }
예제 #4
0
        public void WatchAndShareVideo(DailyTaskInfo dailyTaskStatus)
        {
            VideoInfoDto targetVideo = null;

            if (!dailyTaskStatus.Watch || !dailyTaskStatus.Share)
            {
                targetVideo = GetRandomVideoForWatchAndShare();
                _logger.LogInformation("获取随机视频:{title}", targetVideo.Title);
            }

            if (!dailyTaskStatus.Watch && _dailyTaskOptions.IsWatchVideo)
            {
                WatchVideo(targetVideo);
            }
            else
            {
                _logger.LogInformation("今天已经观看过了,不需要再看啦");
            }

            if (!dailyTaskStatus.Share && _dailyTaskOptions.IsShareVideo)
            {
                ShareVideo(targetVideo);
            }
            else
            {
                _logger.LogInformation("今天已经分享过了,不用再分享啦");
            }
        }
예제 #5
0
    private void CreateItem(VideoInfoDto info)
    {
        var listItem = Instantiate <ListItem>(listItemPrefab);

        listItem.transform.SetParent(parent, false);
        listItem.InitItem(info);
        listItems.Add(listItem);
    }
예제 #6
0
        /// <summary>
        /// 分享视频
        /// </summary>
        /// <param name="aid">视频aid</param>
        public void ShareVideo(VideoInfoDto videoInfo)
        {
            BiliApiResponse apiResponse = _dailyTaskApi.ShareVideo(videoInfo.Aid, _biliBiliCookie.BiliJct)
                                          .GetAwaiter().GetResult();

            if (apiResponse.Code == 0)
            {
                _expDic.TryGetValue("每日观看视频", out int exp);
                _logger.LogInformation("视频分享成功,经验+{exp} √", exp);
            }
            else
            {
                _logger.LogError("视频分享失败,原因: {msg}", apiResponse.Message);
            }
        }
예제 #7
0
        /// <summary>
        /// 分享视频
        /// </summary>
        /// <param name="aid">视频aid</param>
        public void ShareVideo(VideoInfoDto videoInfo)
        {
            var             request     = new ShareVideoRequest(long.Parse(videoInfo.Aid), _biliBiliCookie.BiliJct);
            BiliApiResponse apiResponse = _videoApi.ShareVideo(request)
                                          .GetAwaiter().GetResult();

            if (apiResponse.Code == 0)
            {
                _expDic.TryGetValue("每日观看视频", out int exp);
                _logger.LogInformation("视频分享成功,经验+{exp} √", exp);
            }
            else
            {
                _logger.LogError("视频分享失败,原因: {msg}", apiResponse.Message);
            }
        }
예제 #8
0
        /// <summary>
        /// 观看视频
        /// </summary>
        public void WatchVideo(VideoInfoDto videoInfo)
        {
            int             playedTime  = new Random().Next(5, videoInfo.SecondsLength ?? 15);
            BiliApiResponse apiResponse = _dailyTaskApi.UploadVideoHeartbeat(videoInfo.Aid, playedTime)
                                          .GetAwaiter().GetResult();

            if (apiResponse.Code == 0)
            {
                _expDic.TryGetValue("每日观看视频", out int exp);
                _logger.LogInformation("视频播放成功,已观看到第{playedTime}秒,经验+{exp} √", playedTime, exp);
            }
            else
            {
                _logger.LogError("视频播放失败,原因:{msg}", apiResponse.Message);
            }
        }
예제 #9
0
        public void WatchAndShareVideo(DailyTaskInfo dailyTaskStatus)
        {
            VideoInfoDto targetVideo = null;

            //至少有一项未完成,获取视频
            if (!dailyTaskStatus.Watch || !dailyTaskStatus.Share)
            {
                targetVideo = GetRandomVideoForWatchAndShare();
                _logger.LogInformation("【随机视频】{title}", targetVideo.Title);
            }

            bool watched = false;

            //观看
            if (!dailyTaskStatus.Watch && _dailyTaskOptions.IsWatchVideo)
            {
                WatchVideo(targetVideo);
                watched = true;
            }
            else
            {
                _logger.LogInformation("今天已经观看过了,不需要再看啦");
            }

            //分享
            if (!dailyTaskStatus.Share && _dailyTaskOptions.IsShareVideo)
            {
                //如果没有打开观看过,则分享前先打开视频
                if (!watched)
                {
                    try
                    {
                        OpenVideo(targetVideo);
                    }
                    catch (Exception e)
                    {
                        //ignore
                        _logger.LogError("打开视频异常:{msg}", e.Message);
                    }
                }
                ShareVideo(targetVideo);
            }
            else
            {
                _logger.LogInformation("今天已经分享过了,不用再分享啦");
            }
        }
        private string GetShortInfoString(VideoInfoDto video)
        {
            string id         = "Video: ";
            string note       = video.Note != null ? video.Note + "\n" : "";
            string quality    = video.VideoQuality != null ? video.VideoQuality + " | " : "";
            string width      = video.ResolutionWidth.ToString();
            string heigth     = video.ResolutionHeigth.ToString();
            string resolution = width != null && heigth != null ? width + 'x' + heigth :
                                heigth != null && width == null ? heigth + "p " : "";
            string relation    = video.Relation != null ? " (" + video.Relation + ") | " : "";
            string videoFormat = video.VideoFormat != null ? video.VideoFormat + " | " : "";
            string bitrate     = video.Bitrate != null?video.Bitrate.ToString() + " kb/s | " : "";

            string frameRate = video.FrameRate != null?video.FrameRate.ToString() + " FPS" : "";

            return($"{id}{note}{quality}{resolution}{relation}{videoFormat}{bitrate}{frameRate}");
        }
예제 #11
0
    public void InitItem(VideoInfoDto info)
    {
        //IOS에서는 이 코드를 쓸 수 없습니다. (샘플 프로그램)
        Texture2D texture = null;

        if (System.IO.File.Exists(info.ThumbPath))
        {
            byte[] byteTexture = System.IO.File.ReadAllBytes(info.ThumbPath);
            if (byteTexture.Length > 0)
            {
                texture = new Texture2D(0, 0);
                texture.LoadImage(byteTexture);
            }
        }

        UpdateData(texture, info.Title, info.Duration, info.AddedDate, info.ModifiedDate, info.Path);
    }
        private string GetFullInfoString(VideoInfoDto video)
        {
            string id          = "Video: \n";
            string note        = video.Note != null ? video.Note + "\n" : "";
            string quality     = video.VideoQuality != null ? "\tКачество видео: " + video.VideoQuality + '\n' : "";
            string videoFormat = video.VideoFormat != null ? "\tФормат: " + video.VideoFormat + '\n' : "";
            string relation    = video.Relation != null ? "\tСоотношение: " + video.Relation + '\n' : "";
            string bitrate     = video.Bitrate != null ? "\tБитрейт: " + video.Bitrate.ToString() + " kb/s\n" : "";

            string width      = video.ResolutionWidth.ToString();
            string heigth     = video.ResolutionHeigth.ToString();
            string resolution = width != null && heigth != null ? "\tРазрешение: " + width + 'x' + heigth + '\n' :
                                heigth != null && width == null ? "\tРазрешение: " + heigth + "p\n" : "";

            string frameRate = video.FrameRate != null ? "\tЧастота: " + video.FrameRate.ToString() + " FPS\n" : "";

            return($"{id}{note}{quality}{videoFormat}{bitrate}{resolution}{relation}{frameRate}");
        }
예제 #13
0
        /// <summary>
        /// 获取一个视频用来观看并分享
        /// </summary>
        /// <returns></returns>
        private VideoInfoDto GetRandomVideoForWatchAndShare()
        {
            //先从配置的或关注的up中取
            VideoInfoDto video = GetRandomVideoOfFollowingUps();

            if (video != null)
            {
                return(video);
            }

            //然后从排行榜中取
            Tuple <string, string> t = GetRandomVideoOfRegion();

            return(new VideoInfoDto
            {
                Aid = t.Item1,
                Title = t.Item2,
            });
        }
예제 #14
0
        /// <summary>
        /// 获取一个视频用来观看并分享
        /// </summary>
        /// <returns></returns>
        private VideoInfoDto GetRandomVideoForWatchAndShare()
        {
            //先从配置的或关注的up中取
            VideoInfoDto video = GetRandomVideoOfFollowingUps();

            if (video != null)
            {
                return(video);
            }

            //然后从排行榜中取
            RankingInfo t = GetRandomVideoOfRanking();

            return(new VideoInfoDto
            {
                Aid = t.Aid.ToString(),
                Bvid = t.Bvid,
                Cid = t.Cid,
                Copyright = t.Copyright,
                Duration = t.Duration,
                Title = t.Title,
            });
        }