Example #1
0
        /// <summary>
        /// 直播间状态检查
        /// </summary>
        /// <returns></returns>
        private static async Task <bool> LiveRoomStateCheck(User user)
        {
            try
            {
                string info = await LoginApi.GetInfoAsync(user);

                if (string.IsNullOrEmpty(info))
                {
                    if (!await user.Login())
                    {
                        throw new Exception("User login failed. exit.");
                    }
                }
                LiveRoomStreamDataInfo roomInfo = await LiveApi.GetRoomInfo(user);

                if (roomInfo == null)
                {
                    return(false);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #2
0
        public async Task Run(params string[] args)
        {
            try
            {
                //登录
                await LoginToBilibili();

                _logger.LogInformation($"登录成功,登录账号为:{_config.UserSetting.Account}");
                //获取直播间房间信息
                LiveRoomStreamDataInfo liveRoomInfo = await _liveApi.GetRoomInfo(this._account);

                if (liveRoomInfo == null)
                {
                    _logger.LogError($"开启直播失败,无法获取直播间信息!");
                    return;
                }
                //测试FFmpeg
                if (!await FFmpegTest())
                {
                    _logger.LogError($"开启推流失败,未找到FFmpeg,请确认已经安装FFmpeg!");
                    return;
                }
                //开始执行ffmpeg推流
                await UseFFmpegLive(liveRoomInfo.Rtmp.Addr + liveRoomInfo.Rtmp.Code);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, ex);
            }
        }
Example #3
0
        static async Task Main(string[] args)
        {
            GlobalSettings.Logger = Logger.Instance;
            if (!BitConverter.IsLittleEndian)
            {
                GlobalSettings.Logger.LogWarning("在BigEndian模式的CPU下工作可能导致程序出错");
                GlobalSettings.Logger.LogWarning("如果出现错误,请创建issue");
            }
            string usersConfigPath = Path.Combine(Environment.CurrentDirectory, "Settings", "Users.json");

            try
            {
                GlobalSettings.LoadAll();
                _users = Users.FromJson(File.ReadAllText(usersConfigPath));
                if (_users == null || _users.Count == 0)
                {
                    throw new Exception("Load user info failed.");
                }
            }
            catch (Exception ex)
            {
                GlobalSettings.Logger.LogException(ex);
                GlobalSettings.Logger.LogError($"缺失或无效配置文件,请检查是否添加\"{usersConfigPath}\"");
                return;
            }
            LoginApiExtensions.LoginDataUpdated += (sender, e) => File.WriteAllText(usersConfigPath, _users.ToJson());
            User user = _users[0];

            if (!await user.Login())
            {
                GlobalSettings.Logger.LogError($"账号{user.Account}登录失败!");
                return;
            }
            //加载配置文件
            LiveSetting liveSetting = LoadLiveSettingConfig();

            if (liveSetting == null)
            {
                GlobalSettings.Logger.LogError($"加载直播设置配置文件失败!");
                return;
            }
            //获取直播间信息
            LiveRoomStreamDataInfo roomInfo = await LiveApi.GetRoomInfo(user);

            if (roomInfo == null)
            {
                GlobalSettings.Logger.LogError($"开启直播失败,无法获取直播间信息!");
                return;
            }

            //开始使用ffmpeg推流直播
            await StartPublish(user, liveSetting, $"{roomInfo.Rtmp.Addr}{roomInfo.Rtmp.Code}");

            if (Console.IsInputRedirected || Console.IsOutputRedirected)
            {
                while (true)
                {
                    Thread.Sleep(300);
                }
            }
            else
            {
                Console.ReadKey(true);
            }
        }