/// <summary> /// 提供者を文字列から解析します。 /// </summary> public static ProviderData ParseProvider(string providerStr) { if (string.IsNullOrEmpty(providerStr)) { return(null); } // 提供者を取得します。 if (providerStr.StartsWith("co", StringComparison.InvariantCultureIgnoreCase)) { return(new ProviderData( ProviderType.Community, StrUtil.ToInt(providerStr.Substring(2), -1))); } else if (providerStr.StartsWith("ch", StringComparison.InvariantCultureIgnoreCase)) { return(new ProviderData( ProviderType.Channel, StrUtil.ToInt(providerStr.Substring(2), -1))); } else if (providerStr.Equals("official", StringComparison.InvariantCultureIgnoreCase)) { return(new ProviderData( ProviderType.Official, -1)); } return(null); }
internal ContentType(XmlNode node) { foreach (var attrObj in node.Attributes) { var attr = (XmlAttribute)attrObj; var text = attr.Value; switch (attr.Name) { case "id": this.Id = attr.Value; break; case "disableVideo": this.EnableVideo = !StrUtil.ToBool(text, true); break; case "disableAudio": this.EnableAudio = !StrUtil.ToBool(text, true); break; case "start_time": this.StartTime = StrUtil.ToDateTime(text); break; case "duration": this.Duration = TimeSpan.FromSeconds( StrUtil.ToInt(text, 0)); break; } } this.Content = node.InnerText; }
/// <summary> /// アラートメッセージを処理します。 /// </summary> private void HandleMessage(string message) { var doc = new XmlDocument(); doc.LoadXml(message); var node = doc.DocumentElement; if (node.Name != "chat") { return; } Log.Trace("Alert {0}", node.InnerText); // 内部テキストは // [放送ID],[チャンネル/コミュニティID/official],[ユーザーID] // となっています。 var values = node.InnerText.Split(','); if (values.Length < 3) { return; } // 放送IDを取得します。 var liveId = StrUtil.ToInt(values[0], 0); if (liveId <= 0) { return; } // 提供者を取得します。 var providerData = NicoUtil.ParseProvider(values[1]); if (providerData == null) { return; } // ユーザー情報を取得します。 var userId = StrUtil.ToInt(values[2], -1); // IDが重複して送られてくることがあるので、 // すでに受信した放送IDならば無視します。 if (!IsContainsLiveId(liveId)) { var e = new LiveAlertedEventArgs( liveId, providerData, userId); OnLiveAlerted(e); AddLiveIdToHistoryBuffer(liveId); } }
/// <summary> /// 文字列から<see cref="ChatResultStatus"/>の値を取得します。 /// </summary> public static ChatResultStatus GetStatus(string text) { var value = StrUtil.ToInt(text, -1); foreach (var enumValue in EnumEx.GetValues <ChatResultStatus>()) { if ((int)enumValue == value) { return(enumValue); } } return(ChatResultStatus.Unknown); }
internal TwitterInfoType(XmlNode node) { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "status": this.Status = text; break; case "after_auth": this.AfterAuth = text; break; case "screen_name": this.Name = text; break; case "followers_count": this.FollowersCount = StrUtil.ToInt(text, 0); break; case "is_vip": this.IsVip = StrUtil.ToBool(text, false); break; case "profile_image_url": this.ImageUrl = text; break; case "tweet_token": this.TweetToken = text; break; } } }
internal TwitterType(XmlNode node) { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "live_enabled": this.IsEnabled = StrUtil.ToBool(text, false); break; case "vip_mode_count": this.VipModeCount = StrUtil.ToInt(text, -1); break; case "live_api_url": this.LiveApiUrl = text; break; } } }
internal MSType(XmlNode node) { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "addr": this.Address = text; break; case "port": this.Port = StrUtil.ToInt(text, 0); break; case "thread": this.Thread = StrUtil.ToInt(text, 0); break; } } }
internal Alert_MS(XmlNode node) : this() { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var value = child.InnerText; switch (child.Name) { case "addr": Address = value; break; case "port": Port = StrUtil.ToInt(value, -1); break; case "thread": ThreadId = StrUtil.ToInt(value, -1); break; } } }
internal RTMPType(XmlNode node) { foreach (var attrObj in node.Attributes) { var attr = (XmlAttribute)attrObj; var text = attr.Value; switch (attr.Name) { case "is_fms": this.IsFms = StrUtil.ToBool(text, false); break; case "rtmpt_port": this.Port = StrUtil.ToInt(text, 0); break; } } foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "url": this.Url = text; break; case "ticket": this.Ticket = text; break; } } }
internal UserType(XmlNode node) : this() { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "nickname": this.NickName = text; break; case "is_premium": this.IsPremium = StrUtil.ToBool(text, true); break; case "user_id": this.UserId = StrUtil.ToInt(text, -1); break; } } }
/// <summary> /// コンストラクタ /// </summary> private Heartbeat(long liveId, XmlNode node) : base(node, "heartbeat", NicoString.LiveIdString(liveId)) { foreach (var childObj in RootNode.ChildNodes) { var child = (XmlNode)childObj; var value = child.InnerText; switch (child.Name) { case "watchCount": this.WatchCount = StrUtil.ToInt(value, -1); break; case "commentCount": this.CommentCount = StrUtil.ToInt(value, -1); break; case "ticket": this.Ticket = value; break; } } }
internal UserType(XmlNode node) : this() { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "room_label": this.RoomLabel = text; break; case "room_seetno": this.RoomSeetNo = StrUtil.ToInt(text, 0); break; case "userAge": this.UserAge = StrUtil.ToInt(text, 0); break; case "userSex": this.UserGender = StrUtil.ToGender(text); break; case "userPrefecture": this.UserPrefecture = text; break; case "nickname": this.NickName = text; break; case "is_premium": this.IsPremium = StrUtil.ToBool(text, false); break; case "user_id": this.UserId = int.Parse(text); break; case "hkey": this.HKey = text; break; case "is_join": this.IsJoin = StrUtil.ToBool(text, false); break; case "immu_comment": this.ImmuComment = text; break; case "can_broadcast": this.CanBroadcast = text; break; case "can_forcelogin": this.CanForceLogin = text; break; case "twitter_info": this.TwitterInfo = new TwitterInfoType(child); break; } } }
internal StreamType(XmlNode node) : this() { foreach (var childObj in node.ChildNodes) { var child = (XmlNode)childObj; var text = child.InnerText; switch (child.Name) { case "id": this.Id = int.Parse(text.Substring(2)); break; case "title": this.Title = text; break; case "description": this.Description = text; break; case "comment_count": this.CommentCount = StrUtil.ToInt(text, 0); break; case "watch_count": this.WatchCount = StrUtil.ToInt(text, 0); break; case "danjo_comment_mode": this.DanjoCommentMode = StrUtil.ToBool(text, false); break; case "nicoden": this.IsNicoDen = StrUtil.ToBool(text, false); break; case "allow_netduetto": this.AllowNetduetto = StrUtil.ToBool(text, false); break; case "relay_comment": this.RelayComment = text; break; case "park": this.IsPark = StrUtil.ToBool(text, false); break; case "nd_token": this.NdToken = text; break; case "bourbon_url": this.BourbonUrl = text; break; case "full_video": this.FullVideo = text; break; case "after_video": this.AfterVideo = text; break; case "before_video": this.BeforeVideo = text; break; case "kickout_video": this.KickoutVideo = text; break; case "header_comment": this.HeaderComment = text; break; case "footer_comment": this.FooterComment = text; break; case "plugin_delay": this.PluginDelay = text; break; case "plugin_url": this.PluginUrl = text; break; case "provider_type": this.ProviderType = StrUtil.ToProvider(text); break; case "default_community": this.DefaultCommunity = text; break; case "archive": this.IsArchive = StrUtil.ToBool(text, false); break; case "is_dj_stream": this.IsDjStream = StrUtil.ToBool(text, false); break; case "twitter_tag": this.TwitterTag = text; break; case "is_owner": this.IsOwner = StrUtil.ToBool(text, false); break; case "owner_id": this.OwnerId = StrUtil.ToInt(text, -1); break; case "owner_name": this.OwnerName = text; break; case "is_reserved": this.IsReserved = StrUtil.ToBool(text, false); break; case "base_time": this.BaseTime = StrUtil.ToDateTime(text); break; case "open_time": this.OpenTime = StrUtil.ToDateTime(text); break; case "start_time": this.StartTime = StrUtil.ToDateTime(text); break; case "end_time": this.EndTime = StrUtil.ToDateTime(text); break; case "ichiba_notice_enable": this.IsIchibaNoticeEnable = StrUtil.ToBool(text, false); break; case "comment_lock": this.IsCommentLock = StrUtil.ToBool(text, false); break; case "background_comment": this.IsBackgroundComment = StrUtil.ToBool(text, false); break; case "contents_list": foreach (var childObj2 in child.ChildNodes) { var child2 = (XmlNode)childObj2; if (child2.Name == "contents") { var content = new ContentType(child2); this.ContentList.Add(content); } } break; case "press": this.Press = new PressType(child); break; } } }