public SettingsWindow(MainWindow mainWindow, ConfigV1 config)
 {
     Owner = mainWindow;
     config.CopyPropertiesTo(Config);
     DataContext = Config;
     InitializeComponent();
 }
Exemple #2
0
        public BililiveAPI(ConfigV1 config)
        {
            Config = config;
            Config.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == nameof(Config.Cookie))
                {
                    ApplyCookieSettings(Config.Cookie);
                }
            };

            httpclient = new HttpClient {
                Timeout = TimeSpan.FromSeconds(10)
            };
            httpclient.DefaultRequestHeaders.Add("Accept", HTTP_HEADER_ACCEPT);
            httpclient.DefaultRequestHeaders.Add("Referer", HTTP_HEADER_REFERER);
            httpclient.DefaultRequestHeaders.Add("User-Agent", Utils.UserAgent);

            danmakuhttpclient = new HttpClient {
                Timeout = TimeSpan.FromSeconds(10)
            };
            danmakuhttpclient.DefaultRequestHeaders.Add("Accept", HTTP_HEADER_ACCEPT);
            danmakuhttpclient.DefaultRequestHeaders.Add("Referer", HTTP_HEADER_REFERER);
            danmakuhttpclient.DefaultRequestHeaders.Add("User-Agent", Utils.UserAgent);
        }
Exemple #3
0
        public StreamMonitor(int roomid, Func <TcpClient> funcTcpClient, ConfigV1 config, BililiveAPI bililiveAPI)
        {
            this.funcTcpClient = funcTcpClient;
            this.config        = config;
            this.bililiveAPI   = bililiveAPI;

            Roomid = roomid;

            ReceivedDanmaku += Receiver_ReceivedDanmaku;
            RoomInfoUpdated += StreamMonitor_RoomInfoUpdated;

            dmTokenSource = new CancellationTokenSource();
            Repeat.Interval(TimeSpan.FromSeconds(30), () =>
            {
                if (dmNetStream != null && dmNetStream.CanWrite)
                {
                    try
                    {
                        SendSocketData(2);
                    }
                    catch (Exception) { }
                }
            }, dmTokenSource.Token);

            httpTimer = new Timer(config.TimingCheckInterval * 1000)
            {
                Enabled             = false,
                AutoReset           = true,
                SynchronizingObject = null,
                Site = null
            };
            httpTimer.Elapsed += (sender, e) =>
            {
                try
                {
                    Check(TriggerType.HttpApi);
                }
                catch (Exception ex)
                {
                    logger.Log(Roomid, LogLevel.Warn, "获取直播间开播状态出错", ex);
                }
            };

            config.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName.Equals(nameof(config.TimingCheckInterval)))
                {
                    httpTimer.Interval = config.TimingCheckInterval * 1000;
                }
            };
        }
Exemple #4
0
        public Recorder(ConfigV1 config, Func <int, IRecordedRoom> iRecordedRoom)
        {
            Config           = config;
            newIRecordedRoom = iRecordedRoom;

            tokenSource = new CancellationTokenSource();
            Repeat.Interval(TimeSpan.FromSeconds(3), DownloadWatchdog, tokenSource.Token);

            Rooms.CollectionChanged += (sender, e) =>
            {
                logger.Debug($"Rooms.CollectionChanged;{e.Action};" +
                             $"O:{e.OldItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RealRoomid.ToString())?.Aggregate((current, next) => current + "," + next)};" +
                             $"N:{e.NewItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RealRoomid.ToString())?.Aggregate((current, next) => current + "," + next)}");
            };
        }
Exemple #5
0
        public Recorder(ConfigV1 config, Func <int, IRecordedRoom> iRecordedRoom)
        {
            Config           = config;
            newIRecordedRoom = iRecordedRoom;

            tokenSource = new CancellationTokenSource();
            Repeat.Interval(TimeSpan.FromSeconds(3), DownloadWatchdog, tokenSource.Token);

            Rooms.CollectionChanged += (sender, e) =>
            {
                logger.Debug($"Rooms.CollectionChanged;{e.Action};" +
                             $"O:{e.OldItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RoomId.ToString())?.Aggregate((current, next) => current + "," + next)};" +
                             $"N:{e.NewItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RoomId.ToString())?.Aggregate((current, next) => current + "," + next)}");
            };

            var debouncing = new SemaphoreSlim(1, 1);

            Config.PropertyChanged += async(sender, e) =>
            {
                if (e.PropertyName == nameof(Config.UseProxyForApi) ||
                    e.PropertyName == nameof(Config.ProxyAddress) ||
                    e.PropertyName == nameof(Config.ProxyRequireCredentials) ||
                    e.PropertyName == nameof(Config.ProxyUsername) ||
                    e.PropertyName == nameof(Config.ProxyPassword)
                    )
                {
                    if (await debouncing.WaitAsync(0))
                    {
                        try
                        {
                            logger.Debug("设置代理等待...");
                            await Task.Delay(50);

                            logger.Debug("设置代理信息...");
                            await BililiveAPI.ApplyProxySettings(
                                Config.UseProxyForApi, Config.ProxyAddress,
                                Config.ProxyRequireCredentials, Config.ProxyUsername, Config.ProxyPassword);

                            logger.Debug("设置成功");
                        }
                        finally
                        {
                            debouncing.Release();
                        }
                    }
                }
            };
        }
        public Recorder(ConfigV1 config, BasicWebhook webhook, Func <int, IRecordedRoom> iRecordedRoom)
        {
            newIRecordedRoom = iRecordedRoom ?? throw new ArgumentNullException(nameof(iRecordedRoom));
            Config           = config ?? throw new ArgumentNullException(nameof(config));
            Webhook          = webhook ?? throw new ArgumentNullException(nameof(webhook));

            tokenSource = new CancellationTokenSource();
            Repeat.Interval(TimeSpan.FromSeconds(3), DownloadWatchdog, tokenSource.Token);

            Rooms.CollectionChanged += (sender, e) =>
            {
                logger.Trace($"Rooms.CollectionChanged;{e.Action};" +
                             $"O:{e.OldItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RoomId.ToString())?.Aggregate((current, next) => current + "," + next)};" +
                             $"N:{e.NewItems?.Cast<IRecordedRoom>()?.Select(rr => rr.RoomId.ToString())?.Aggregate((current, next) => current + "," + next)}");
            };
        }
Exemple #7
0
        private static void Run(ConfigV1 option)
        {
            foreach (var room in option.RoomList)
            {
                if (Recorder.Where(r => r.RoomId == room.Roomid).Count() == 0)
                {
                    Recorder.AddRoom(room.Roomid);
                }
            }

            logger.Info("开始录播");
            Task.WhenAll(Recorder.Select(x => Task.Run(() => x.Start()))).Wait();
            Console.CancelKeyPress += (sender, e) =>
            {
                Task.WhenAll(Recorder.Select(x => Task.Run(() => x.StopRecord()))).Wait();
                logger.Info("停止录播");
            };
            while (true)
            {
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
        }
 public BasicWebhook(ConfigV1 config)
 {
     this.Config = config ?? throw new ArgumentNullException(nameof(config));
 }
 public BasicDanmakuWriter(ConfigV1 config)
 {
     this.config = config ?? throw new ArgumentNullException(nameof(config));
 }