/// <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 = LiveUtil.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> /// html形式の生放送ページから生放送情報を作成します。 /// </summary> public static LiveInfo CreateFromHtml(string idString, string pageStr) { var live = new LiveInfo(); if (string.IsNullOrEmpty(pageStr)) { throw new NicoLiveException( "ページが空です。", idString); } var m = ProviderInfoRegex.Match(pageStr); if (!m.Success) { throw new NicoLiveException( "放送の提供元情報を取得できませんでした。", idString); } var provider = LiveUtil.ParseProvider(m.Groups[1].Value); m = VideoInfoRegex.Match(pageStr); if (!m.Success) { throw new NicoLiveException( "生放送情報を取得できませんでした。", idString); } var infoStr = m.Groups[1].Value; m = IdRegex.Match(infoStr); if (!m.Success) { throw new NicoException( "生放送IDを取得できませんでした。", idString); } live.Id = int.Parse(m.Groups[1].Value); m = TitleRegex.Match(infoStr); if (!m.Success) { throw new NicoException( "生放送タイトルを取得できませんでした。", idString); } live.Title = m.Groups[1].Value .Replace("\\'", "'"); m = DescriptionRegex.Match(infoStr); if (!m.Success) { throw new NicoLiveException( "生放送概要を取得できませんでした。", idString); } live.Description = m.Groups[1].Value .Replace("\\'", "'") .Replace("\\r\\n", "\n"); switch (provider.ProviderType) { case ProviderType.Community: SetCommunityInfo(live, pageStr); break; case ProviderType.Channel: SetChannelInfo(live, pageStr); break; case ProviderType.Official: SetOfficialInfo(live, pageStr); break; default: throw new NotImplementedException( "実装されていない放送提供元です。"); } return(live); }