//------------------------------------------------------------- // 概要:チャンネル情報の取得 //------------------------------------------------------------- private static ChannelInfo SelectChannelInfo(XElement elements, List<HostInfo> hostList, string streamId) { var channelList = // channels_relayed from chRelay in elements.Elements("channels_relayed").Elements("channel") where (string)chRelay.Attribute("id") == streamId from relay in chRelay.Elements("relay") from track in chRelay.Elements("track") // channels_found from chFound in elements.Elements("channels_found").Elements("channel") where (string)chFound.Attribute("id") == streamId from hits in chFound.Elements("hits") select new ChannelInfo { // チャンネル情報 Name = (string)chRelay.Attribute("name"), Id = (string)chRelay.Attribute("id"), Bitrate = (string)chRelay.Attribute("bitrate"), Type = (string)chRelay.Attribute("type"), Genre = (string)chRelay.Attribute("genre"), Desc = (string)chRelay.Attribute("desc"), Url = (string)chRelay.Attribute("url"), Uptime = (string)chRelay.Attribute("uptime"), Comment = (string)chRelay.Attribute("comment"), Skips = (string)chRelay.Attribute("skips"), Age = (string)chRelay.Attribute("age"), Bcflags = (string)chRelay.Attribute("bcflags"), // リレー情報 Listeners = (string)relay.Attribute("listeners"), Relays = (string)relay.Attribute("relays"), Hosts = (string)relay.Attribute("hosts"), Status = (string)relay.Attribute("status"), Firewalled = (string)hits.Attribute("firewalled"), // トラック情報 TrackTitle = (string)track.Attribute("title"), TrackArtist = (string)track.Attribute("artist"), TrackAlbum = (string)track.Attribute("album"), TrackGenre = (string)track.Attribute("genre"), TrackContact = (string)track.Attribute("contact"), HostList = hostList, }; // チャンネル情報の取得 ChannelInfo channelInfo = new ChannelInfo(); if (channelList.Count() > 0) { channelInfo = channelList.SingleOrDefault(); channelInfo.Genre = FitGenre(channelInfo.Genre); Logger.Instance.DebugFormat("チャンネル情報取得結果:正常 [チャンネル名:{0}]", channelInfo.Name); } else { Logger.Instance.ErrorFormat("チャンネル情報取得結果:異常 [ストリームID:{0}]", streamId); } return channelInfo; }
//------------------------------------------------------------- // 概要:リレー色の判定 //------------------------------------------------------------- private static RelayColor JudgeRelayColor(ChannelInfo chInfo, bool isPortOpen, bool isRelay, bool canRelay) { // ポート解放済み if (isPortOpen) { // リレーあり if (isRelay) { return RelayColor.Green; } // リレーなし else { // リレーできる if (canRelay) { return RelayColor.Blue; } // リレーできない else { return RelayColor.Purple; } } } // ポート未開放 else { // リレーできる if (canRelay) { return RelayColor.Orange; } // リレーできない else { return RelayColor.Red; } } }
//------------------------------------------------------------- // 概要:チャンネル情報の取得 // 詳細:読み込む対象のXMLを指定する //------------------------------------------------------------- public ChannelInfo GetChannelInfo() { string xmlUrl = string.Format("http://{0}:{1}/admin?cmd=viewxml", urlInfo.Host, urlInfo.PortNo); Logger.Instance.DebugFormat("GetChannelInfo(Host:{0}, PortNo:{1}, StreamId:{2} xmlUrl:{3})", urlInfo.Host, urlInfo.PortNo, urlInfo.StreamId, xmlUrl); try { // ViewXMLの取得 XElement elements = XElement.Load(xmlUrl); Logger.Instance.DebugFormat("ViewXMLの取得結果:正常 [xmlUrl:{0}]", xmlUrl); // ViewXMLの解析 channelInfo = ViewXMLAnalyzer.AnlyzeViewXML(elements, urlInfo.StreamId); return channelInfo; } catch { Logger.Instance.ErrorFormat("ViewXMLの取得結果:異常 [xmlUrl:{0}]", xmlUrl); channelInfo = new ChannelInfo(); return channelInfo; } }
/// <summary> /// チャンネル名を取得 /// </summary> private string getChannelName(ChannelInfo info) { // 1.チャンネル情報を優先 if (info.Name != "") { return info.Name; } // 2.コマンドライン引数 if (Environment.GetCommandLineArgs().Length > 3) { var name = Environment.GetCommandLineArgs()[3]; return name; } // 3.データなし→空 return ""; }
/// <summary> /// チャンネル詳細を更新 /// </summary> private void UpdateChannelDetail(ChannelInfo info) { string chName = getChannelName(info); statusBar.ChannelDetail = String.Format("{0} {1}{2} {3}", chName, (string.IsNullOrEmpty(info.Genre) ? "" : string.Format("[{0}] ", info.Genre)), info.Desc, info.Comment); }
//------------------------------------------------------------- // 概要:リレー色の設定 //------------------------------------------------------------- private static void SetRelayColor(ChannelInfo chInfo) { // 自分のリレー色 { bool isPortOpen = (chInfo.Firewalled == "0"); bool isRelay = (chInfo.HostList.Count != 0); bool canRelay = (chInfo.Relays != "0"); chInfo.RelayColor = JudgeRelayColor(chInfo, isPortOpen, isRelay, canRelay); } // リレー先のリレー色 foreach (HostInfo hostInfo in chInfo.HostList) { bool isPortOpen = (hostInfo.Push == "0"); bool isRelay = (hostInfo.Relay != "0"); bool canRelay = (hostInfo.Relays != "0"); hostInfo.RelayColor = JudgeRelayColor(chInfo, isPortOpen, isRelay, canRelay); } }
public static string Format(string format, ChannelInfo info) { // 書式が空の場合、設定デフォルト値を使いたい if (string.IsNullOrEmpty(format)) { format = "yyyyMMdd_HHmmss"; } // 時刻 var buffer = DateTime.Now.ToString(format); // チャンネル名 buffer = buffer.Replace("$0", info != null ? info.Name : "チャンネル名"); // ファイル名として使えない文字を消す buffer = buffer.Replace("\"", ""); buffer = buffer.Replace(":", ""); buffer = buffer.Replace("*", ""); buffer = buffer.Replace("?", ""); buffer = buffer.Replace("<", ""); buffer = buffer.Replace(">", ""); buffer = buffer.Replace("|", ""); buffer = buffer.Replace(";", ""); buffer = buffer.Replace(",", ""); return buffer; }