示例#1
0
        private async Task restoreAction()
        {
            try
            {
                LiveApi liveApi;
                liveApi = new LiveApi("keepTheRhythm", null);
                liveApi.notifMessage += LiveApi_notifMessage;

                var tmpFile = await Windows.Storage.ApplicationData.Current.TemporaryFolder.CreateFileAsync("backup_KeepTheRhythm.db", CreationCollisionOption.ReplaceExisting);

                var res = await liveApi.downloadFileAsync("backup_KeepTheRhythm.db", tmpFile);

                if (res == "OK")
                {
                    DataBaseManager newDB = new DataBaseManager("backup_KeepTheRhythm", Windows.Storage.ApplicationData.Current.TemporaryFolder);
                    if (!newDB.CheckDataBase())
                    {
                        throw new Exception(resourceLoader.GetString("EmptyDatabase"));
                    }
                    DataBaseManager.instance.Close();
                    newDB.Close();

                    StorageFile file = await Windows.Storage.ApplicationData.Current.TemporaryFolder.GetFileAsync("backup_KeepTheRhythm.db");

                    await file.MoveAsync(Windows.Storage.ApplicationData.Current.LocalFolder, "ktr.db", NameCollisionOption.ReplaceExisting);

                    showNotif(resourceLoader.GetString("endRestore"), resourceLoader.GetString("attention"));
                }
            }
            catch (Exception ee)
            {
                showNotif(string.Format(resourceLoader.GetString("endKORestore"), ee.Message), resourceLoader.GetString("attention"));
                nowhereman.LittleWatson.instance.ReportException(ee, "restore");
            }
        }
示例#2
0
        /// <summary>
        /// 开启
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private static async Task <StartLiveDataInfo> StartLive(User user, LiveSetting liveSetting)
        {
            try
            {
                //先停止历史直播
                //if (await LiveApi.StopLive(user))
                //{
                //    GlobalSettings.Logger.LogInfo("尝试关闭历史直播...成功!");
                //}
                //修改直播间名称
                if (await LiveApi.UpdateLiveRoomName(user, liveSetting.LiveRoomName))
                {
                    GlobalSettings.Logger.LogInfo($"成功修改直播间名称,直播间名称:{liveSetting.LiveRoomName}");
                }
                //更新分类
                if (await LiveApi.UpdateLiveCategory(user, liveSetting.LiveCategory))
                {
                    GlobalSettings.Logger.LogInfo($"成功修改直播间分类,直播间分类ID:{liveSetting.LiveCategory}");
                }
                StartLiveDataInfo liveInfo = await LiveApi.StartLive(user, liveSetting.LiveCategory);

                if (liveInfo != null)
                {
                    GlobalSettings.Logger.LogInfo("开启直播成功!");
                    GlobalSettings.Logger.LogInfo($"我的直播间地址:http://live.bilibili.com/{liveInfo.RoomId}");
                    GlobalSettings.Logger.LogInfo($"推流地址:{liveInfo.Rtmp.Addr}{liveInfo.Rtmp.Code}");
                }
                return(liveInfo);
            }
            catch (Exception ex)
            {
                GlobalSettings.Logger.LogError($"开启直播失败!错误:{ex.Message}");
                return(null);
            }
        }
示例#3
0
 public EncodingsApi(IBitmovinApiClientFactory apiClientFactory)
 {
     _apiClient     = apiClientFactory.CreateClient <IEncodingsApiClient>();
     Live           = new LiveApi(apiClientFactory);
     Vod            = new VodApi(apiClientFactory);
     LiveStatistics = new LiveStatisticsApi(apiClientFactory);
 }
示例#4
0
        private static async Task StartAsync(uint start, uint end)
        {
            uint[]   roomIds;
            int      count;
            TimeSpan interval;

            roomIds = await LiveApi.GetRoomIdsDynamicAsync(start, end);

            count    = (int)(end - start);
            interval = TimeSpan.FromMilliseconds(DanmuApi.HeartBeatInterval.TotalMilliseconds / count);
            for (uint i = start; i < end; i++)
            {
                DateTime     startTime;
                DanmuMonitor danmuMonitor;
                TimeSpan     span;

                startTime    = DateTime.Now;
                danmuMonitor = new DanmuMonitor(roomIds[i], (int)i, i == start);
                danmuMonitor.DanmuHandler += DanmuMonitor_DanmuHandler;
                danmuMonitor.Execute();
                span = interval - (DateTime.Now - startTime);
                if (span.Ticks > 0)
                {
                    await Task.Delay(span);
                }
            }
        }
示例#5
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);
            }
        }
示例#6
0
        void HubActiveStatusChanged(object sender, EventArgs e)
        {
            if (_hub.Active)
            {
                if (_client.Settings.Hubs == null)
                {
                    _client.Settings.Hubs = "";
                }
                else
                {
                    _client.Settings.Hubs += ";";
                }

                _client.Settings.Hubs += hubText.Text;
                _client.Settings.Save();

                if (!string.IsNullOrEmpty(_client.Settings.City))
                {
                    LiveApi.PostHubsAsync(_client.Settings.City, hubText.Text);
                }

                _client.AsyncOperation.Post(o =>
                {
                    statusLabel.Text       = "Успешное подключение. Клиент готов к работе. Если желаете, можно добавить еще.";
                    hubText.Text           = "";
                    continueButton.Enabled = true;
                    addButton.Enabled      = true;
                    hubText.Enabled        = true;
                }, null);
                CleanUpHub();
            }
        }
示例#7
0
        /// <summary>
        /// 开启
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        private static async Task <bool> StartLive(User user)
        {
            try
            {
                //加载配置文件
                LiveSetting liveSetting = LoadLiveSettingConfig();

                //先停止历史直播
                if (await LiveApi.StopLive(user))
                {
                    GlobalSettings.Logger.LogInfo("尝试关闭历史直播...成功!");
                }
                //修改直播间名称
                if (await LiveApi.UpdateLiveRoomName(user, liveSetting.LiveRoomName))
                {
                    GlobalSettings.Logger.LogInfo($"成功修改直播间名称。直播间名称:{liveSetting.LiveRoomName}");
                }
                StartLiveDataInfo liveInfo = await LiveApi.StartLive(user, liveSetting.LiveCategory);

                if (liveInfo != null)
                {
                    GlobalSettings.Logger.LogInfo("开启直播成功!");
                    GlobalSettings.Logger.LogInfo($"我的直播间地址:http://live.bilibili.com/{liveInfo.RoomId}");
                    GlobalSettings.Logger.LogInfo($"推流地址:{liveInfo.Rtmp.Addr}{liveInfo.Rtmp.Code}");
                }
                //开始使用ffmpeg推流直播
                StartPublish(liveSetting, $"{liveInfo.Rtmp.Addr}{liveInfo.Rtmp.Code}");
                return(true);
            }
            catch (Exception ex)
            {
                GlobalSettings.Logger.LogError($"开启直播失败!错误:{ex.Message}");
                return(false);
            }
        }
示例#8
0
        /// <summary>
        /// Check that we do not have duplicate hubs and submit them to the server
        /// </summary>
        private void VerifyHubs()
        {
            // step 1: normalize all hub addresses
            for (int i = 0; i < _allHubs.Count; i++)
            {
                _allHubs[i] = NormalizeHubAddress(_allHubs[i]);
            }

            // step 2: remove obvius duplicates
            _allHubs = _allHubs.Distinct().ToList();

            // step 3: find ip addresses of domain names to exclude situation when we have 2 instance of the same hub (ip and dns)
            var ipList = new List <string>(_allHubs);

            for (int i = 0; i < ipList.Count; i++)
            {
                if (!isIp(ipList[i]))
                {
                    string port;
                    var    ip = extractIp(ipList[i], out port);
                    try
                    {
                        ipList[i] = Dns.GetHostEntry(ip).AddressList[0] + (port == null ? "" : ":" + port);
                    }
                    catch (Exception x)
                    {
                        logger.Error("unable to resolve hub {0} : {1}", ipList[i], x.Message);
                        ipList[i] = null;
                    }
                }
            }

            // remove hubs with invalid dns responses
            for (int i = _allHubs.Count - 1; i >= 0; i--)
            {
                if (ipList[i] == null)
                {
                    _allHubs.RemoveAt(i);
                    ipList.RemoveAt(i);
                }
            }

            // exclude duplicates
            var list = _allHubs.Select((h, i) => new { dns = h, ip = ipList[i] }).GroupBy(t => t.ip).Select(t => t.First().dns).ToList();

            Settings.Hubs         = string.Join(";", list);
            Settings.LastHubCheck = DateTime.Now;
            Settings.Save();

            foreach (var hub in list)
            {
                AddHub(hub);
            }

            if (!string.IsNullOrEmpty(Settings.Hubs) && !string.IsNullOrEmpty(Settings.City))
            {
                LiveApi.PostHubsAsync(Settings.City, Settings.Hubs);
            }
        }
示例#9
0
 public App(ILogger <App> logger
            , ConfigManager config
            , LiveApi liveApi)
 {
     _logger  = logger;
     _config  = config;
     _liveApi = liveApi ?? throw new ArgumentNullException(nameof(LiveApi));
 }
        public void MovieIdApiTest()
        {
            var userId = "fox_uver";
            var actual = LiveApi.GetMovieIdApi(userId);
            var expect = $"https://frontendapi.twitcasting.tv/users/{userId}/latest-movie";

            Assert.AreEqual(expect, actual);
        }
示例#11
0
        /// <summary>
        /// 获取全部分类
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static async Task Main(string[] args)
        {
            try
            {
                GlobalSettings.LoadAll();
                LiveCategoryDataInfo info = await LiveApi.GetLiveCategoryInfo();

                if (info != null && info.Code == 0)
                {
                    Console.WriteLine("-------------------------");
                    Console.WriteLine(" ID          名称    ");
                    foreach (var bigCate in info.Data)
                    {
                        Console.WriteLine("-------------------------");
                        Console.WriteLine(bigCate.Name);
                        Console.WriteLine("-------------------------");
                        foreach (var item in bigCate.List)
                        {
                            Console.WriteLine(String.Format("{0,-6} | {1,-20} ", item.id, item.name));
                        }
                    }

                    if (args != null && args.Length > 1)
                    {
                        string path = null;
                        for (int i = 0; i < args.Length; i++)
                        {
                            if (args[i].ToLower() == "-md" && i < args.Length - 1)
                            {
                                path = args[i + 1];
                                (bool, string)result = OutputToMarkdownFile(info.Data, path);
                                if (result.Item1)
                                {
                                    Console.WriteLine("\n写入到文件成功。");
                                }
                                else
                                {
                                    Console.WriteLine($"\n写入到文件失败。{result.Item2}");
                                }
                            }
                        }
                    }

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.ReadKey(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#12
0
        private async Task <int> FetchMovieId()
        {
            var wrapHttpClient = HTTPCLIENT.INSTANCE;
            var response       = await wrapHttpClient.GetWrapAsync(LiveApi.GetMovieIdApi(this._userId));

            var model = new JsonParser(response).ConvertToUserMovieInfoModel();

            return(model.movie.id);
        }
示例#13
0
        public void AutoConfiguration()
        {
            logger.Info("Autoconfiguration started...");

            using (var wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;

                var config = new ProviderConfiguration();
                _providerConfiguration = false;

                try
                {
                    logger.Info("Loading provider specific data http://dc.local/ISP_favorites.xml");
                    var xmlData = wc.DownloadString("http://dc.local/ISP_favorites.xml");
                    var xml     = new XmlSerializer(typeof(ProviderConfiguration));
                    logger.Info("Deserialization...");
                    config = (ProviderConfiguration)xml.Deserialize(new StringReader(xmlData));
                    _providerConfiguration = true;
                    logger.Info("Provider configuration sucessfully loaded");
                }
                catch (Exception e)
                {
                    logger.Error("Unable to load provider configuration: {0}", e.Message);
                }

                if (_providerConfiguration)
                {
                    if (!string.IsNullOrEmpty(config.LiveDcConfig.PortCheckUrl))
                    {
                        logger.Info("Using new port check url: {0}", config.LiveDcConfig.PortCheckUrl);
                        LiveApi.PortCheckUri  = config.LiveDcConfig.PortCheckUrl;
                        Settings.PortCheckUrl = config.LiveDcConfig.PortCheckUrl;
                        Settings.Save();
                    }

                    if (config.Hubs != null && config.Hubs.Count > 0)
                    {
                        logger.Info("Using provider hubs...");
                        Engine.Hubs.Clear();

                        foreach (var hubInfo in config.Hubs)
                        {
                            _hubManager.AddHub(hubInfo.Address);
                        }

                        Settings.Hubs = string.Join(";", config.Hubs.Select(h => DcHubManager.NormalizeHubAddress(h.Address)));
                        Settings.Save();
                    }
                }
            }

            LiveApi.CheckPortAsync(Settings.TCPPort, PortCheckComplete);
        }
 public EncodingsApi(IBitmovinApiClientFactory apiClientFactory)
 {
     _apiClient      = apiClientFactory.CreateClient <IEncodingsApiClient>();
     Live            = new LiveApi(apiClientFactory);
     MachineLearning = new MachineLearningApi(apiClientFactory);
     Customdata      = new CustomdataApi(apiClientFactory);
     Streams         = new StreamsApi(apiClientFactory);
     InputStreams    = new InputStreamsApi(apiClientFactory);
     Muxings         = new MuxingsApi(apiClientFactory);
     TransferRetries = new TransferRetriesApi(apiClientFactory);
     Captions        = new CaptionsApi(apiClientFactory);
     Sidecars        = new SidecarsApi(apiClientFactory);
     Keyframes       = new KeyframesApi(apiClientFactory);
 }
示例#15
0
        /// <summary>
        /// 获取全部分类
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static async Task Main(string[] args)
        {
            try
            {
                GlobalSettings.LoadAll();
                LiveCategoryDataInfo info = await LiveApi.GetLiveCategoryInfo();

                if (info != null && info.Code == 0)
                {
                    Console.WriteLine("-------------------------");
                    Console.WriteLine(" ID          名称    ");
                    foreach (var bigCate in info.Data)
                    {
                        Console.WriteLine("-------------------------");
                        Console.WriteLine(bigCate.Name);
                        Console.WriteLine("-------------------------");
                        foreach (var item in bigCate.List)
                        {
                            Console.WriteLine(String.Format("{0,-6} | {1,-20} ", item.id, item.name));
                        }
                    }

                    //生成GITHUB中表格
                    //foreach (var bigCate in info.Data)
                    //{
                    //    foreach (var item in bigCate.List)
                    //    {
                    //        Console.WriteLine($" | {item.id} | {item.name} | {item.parent_name} | ");
                    //    }
                    //}

                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.ReadKey(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#16
0
        private void CityReceived(IpGeoBaseResponse e)
        {
#if DEBUG
            e.City = "Кемерово";
#endif

            logger.Info("It seems we are in {0}", e.City);

            Settings.City = e.City;

            if (e.City != null && Settings.UpdateHubs)
            {
                LiveApi.GetHubsAsync(e.City, HubsListReceived);
            }
            else if (_allHubs.Count == 0 && _provider.Engine.Hubs.Count == 0)
            {
                ShowHubEditDialog("Не удалось найти хабы. Нажмите, чтобы добавить хаб.");
            }
            else
            {
                VerifyHubs();
            }
        }
示例#17
0
 private void LiveApi_notifMessage(LiveApi sender, string msg, Exception ex)
 {
 }
示例#18
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);
            }
        }
示例#19
0
 public void CheckUpdate()
 {
     Logger.Info("Checking for update...");
     LiveApi.GetLastProgramVersion(VersionReceived);
 }