private void AccessButton_Click(object sender, System.EventArgs e) { try { PocketLadioUtility.AccessWebsite(channel.GetWebsiteUrl()); } catch (FileNotFoundException) { MessageBox.Show("ブラウザが見つかりません", "警告"); } }
private void PlayButton_Click(object sender, System.EventArgs e) { try { PocketLadioUtility.PlayStreaming(channel.GetPlayUrl()); } catch (FileNotFoundException) { MessageBox.Show("メディアプレイヤーが見つかりません", "警告"); } }
/// <summary> /// ヘッドラインをネットから取得する /// </summary> public virtual void FetchHeadline() { // 時刻をセットする lastCheckTime = DateTime.Now; WebStream st = null; try { // チャンネルのリスト ArrayList alChannels = new ArrayList(); Channel channel = null; string searchWord = ((setting.SearchWord.Length != 0) ? "&s=" + setting.SearchWord : string.Empty); // 半角スペースと全角スペースを+に置き換える SHOUTcast上のURLでAND検索のスペースが+に置き換えられるため searchWord = searchWord.Replace(' ', '+').Replace(" ", "+"); string perView = ((setting.PerView.ToString().Length != 0) ? "&numresult=" + setting.PerView : string.Empty); Uri url = new Uri(Headline.SHOUTCAST_URL + "/?" + searchWord + perView); st = PocketLadioUtility.GetWebStream(url); WebTextFetch fetch = new WebTextFetch(st, Encoding.GetEncoding("Windows-1252")); if (HeadlineFetch != null) { fetch.Fetch += HeadlineFetch; } if (HeadlineFetching != null) { fetch.Fetching += HeadlineFetching; } if (HeadlineFetched != null) { fetch.Fetched += HeadlineFetched; } string httpString = fetch.ReadToEnd(); #if SHOUTCAST_HTTP_LOG // ShoutcastのHTTPのログを書き出す StreamWriter sw = null; try { sw = new StreamWriter( AssemblyUtility.GetExecutablePath() + @"\" + PocketLadioInfo.ShoutcastHttpLog, false, Encoding.GetEncoding("Windows-1252")); sw.Write(httpString); } finally { if (sw != null) { sw.Close(); } } #endif // タグの後に改行を入れる(Willcom高速化サービス対応のため) httpString = httpString.Replace(">", ">\n"); string[] lines = httpString.Split('\n'); #region HTML解析 // 順位らしき行 string maybeRankLine = string.Empty; // 1〜指定行目まではHTMLを解析しない int analyzeHtmlFirstTo = setting.IgnoreHtmlAnalyzeFirstTo; // 指定行目から行末まではHTMLを解析しない int analyzeHtmlLast = lines.Length - setting.IgnoreHtmlAnalyzeEndFrom; OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, -1)); // 解析したヘッドラインの個数 int analyzedCount = 0; // HTML解析 for (int lineNumber = analyzeHtmlFirstTo; lineNumber < analyzeHtmlLast && lineNumber < lines.Length; ++lineNumber) { /*** playlist.plsを検索 ***/ Match pathMatch = pathRegex.Match(lines[lineNumber]); // playlist.plsが見つかった場合 if (pathMatch.Success) { channel = new Channel(this); channel.Path = pathMatch.Groups[1].Value; /*** Rankを検索 ***/ Match rankMatch = rankRegex.Match(maybeRankLine); // Rankが見つかった場合 if (rankMatch.Success) { channel.Rank = rankMatch.Groups[1].Value; } /*** Categoryを検索 ***/ Match categoryMatch; // Categoryが見つからない場合は行を読み飛ばして検索する for (++lineNumber; lineNumber < analyzeHtmlLast; ++lineNumber) { categoryMatch = categoryRegex.Match(lines[lineNumber]); // Categoryが見つかった場合 if (categoryMatch.Success) { channel.Category = categoryMatch.Groups[1].Value; break; } } /*** ClusterUrlを検索 ***/ Match clusterUrlMatch; // ClusterUrlが見つからない場合は行を読み飛ばして検索する for (; lineNumber < analyzeHtmlLast; ++lineNumber) { clusterUrlMatch = clusterUrlRegex.Match(lines[lineNumber]); // Categoryが見つかった場合 if (clusterUrlMatch.Success) { try { channel.ClusterUrl = new Uri(clusterUrlMatch.Groups[1].Value); } catch (UriFormatException) { channel.ClusterUrl = null; } break; } } /*** Titleを検索 ***/ Match titleMatch; // Titleが見つからない場合は行を読み飛ばして検索する for (; lineNumber < analyzeHtmlLast; ++lineNumber) { titleMatch = titleRegex.Match(lines[lineNumber]); // Titleが見つかった場合 if (titleMatch.Success) { channel.Title = titleMatch.Groups[1].Value; break; } } /*** Listenerを検索 ***/ Match listenerMatch = listenerRegex.Match(lines[lineNumber]); for (; lineNumber < analyzeHtmlLast; ++lineNumber) { listenerMatch = listenerRegex.Match(lines[lineNumber]); if (listenerMatch.Success) { break; } // Now Playing:は存在しない場合があるのでリスナー数検出の中でチェックを行う Match playingNowMatch = playingNowRegex.Match(lines[lineNumber]); if (playingNowMatch.Success) { Match playingMatch = playingRegex.Match(playingNowMatch.Groups[1].Value); if (playingMatch.Success) { channel.Playing = playingMatch.Groups[1].Value; } } } try { channel.Listener = int.Parse(listenerMatch.Groups[1].Value); channel.ListenerTotal = int.Parse(listenerMatch.Groups[2].Value); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } /*** Bitrateを検索 ***/ Match bitrateMatch; // Bitrateが見つからない場合は行を読み飛ばして検索する for (++lineNumber; lineNumber < analyzeHtmlLast; ++lineNumber) { bitrateMatch = bitRateRegex.Match(lines[lineNumber]); // Bitrateが見つかった場合 if (bitrateMatch.Success) { try { channel.BitRate = int.Parse(bitrateMatch.Groups[1].Value); break; } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } } alChannels.Add(channel); OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++analyzedCount, -1)); } /*** Rankらしき行を保存する ***/ Match maybeRankLineMatch = maybeRankLineRegex.Match(lines[lineNumber]); if (maybeRankLineMatch.Success) { maybeRankLine = lines[lineNumber]; } } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(analyzedCount, analyzedCount)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); #endregion } finally { if (st != null) { st.Close(); } } }
/// <summary> /// ヘッドラインをネットから取得する /// </summary> public virtual void FetchHeadline() { if (setting.RssUrl == null) { return; } // 時刻をセットする lastCheckTime = DateTime.Now; WebStream st = null; XmlTextReader reader = null; try { // 番組のリスト ArrayList alChannels = new ArrayList(); // チャンネル Channel channel = null; // itemタグの中にいるか bool inItemFlag = false; // Enclosureの一時リスト ArrayList alTempEnclosure = new ArrayList(); st = PocketLadioUtility.GetWebStream(setting.RssUrl); reader = new XmlTextReader(st); // 解析したヘッドラインの個数 int analyzedCount = 0; OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "item") { inItemFlag = true; channel = new Channel(this); } // End of item // itemタグの中にいる場合 else if (inItemFlag == true) { if (reader.LocalName == "title") { channel.Title = reader.ReadString(); } // End of title else if (reader.LocalName == "description") { channel.Description = reader.ReadString(); } // End of description else if (reader.LocalName == "link") { try { channel.Link = new Uri(reader.ReadString()); } catch (UriFormatException) { ; } } // End of link else if (reader.LocalName == "pubDate") { channel.SetDate(reader.ReadString()); } // End of pubDate else if (reader.LocalName == "category") { channel.Category = reader.ReadString(); } // End of category else if (reader.LocalName == "author") { channel.Author = reader.ReadString(); } // End of author else if (reader.LocalName == "guid") { try { channel.Link = new Uri(reader.ReadString()); } catch (UriFormatException) { ; } } // End of guid else if (reader.LocalName == "enclosure") { Uri enclosureUrl = null; string enclosureLength = string.Empty; string enclosureType = string.Empty; try { if (reader.MoveToFirstAttribute()) { enclosureUrl = new Uri(reader.GetAttribute("url")); enclosureLength = reader.GetAttribute("length"); enclosureType = reader.GetAttribute("type"); } if (enclosureLength == null) { enclosureLength = string.Empty; } if (enclosureType == null) { enclosureType = string.Empty; } // Enclosureタグの数だけ、 Enclosure一時リストにEnclosureの内容を追加していく Enclosure enclosure = new Enclosure(enclosureUrl, enclosureLength, enclosureType); if (enclosure.IsPodcast() == true) { alTempEnclosure.Add(enclosure); } } catch (UriFormatException) { ; } } // End of enclosure } // End of itemタグの中にいる場合 } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName == "item") { inItemFlag = false; // Enclosureの要素の数だけ、Channelの複製を作る if (alTempEnclosure.Count != 0) { foreach (Enclosure enclosure in alTempEnclosure) { Channel clonedChannel = (Channel)channel.Clone(this); clonedChannel.Url = enclosure.Url; clonedChannel.Length = enclosure.Length; clonedChannel.Type = enclosure.Type; alChannels.Add(clonedChannel); OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++analyzedCount, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); } } // Enclosure一時リストをクリア alTempEnclosure.Clear(); } } } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(analyzedCount, analyzedCount)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); } finally { if (st != null) { st.Close(); } if (reader != null) { reader.Close(); } } }
/// <summary> /// ヘッドラインをネットから取得する(DAT v2使用) /// </summary> private void FetchHeadlineDatV2() { WebStream st = null; string[] channelsDat; // チャンネルのリスト ArrayList alChannels = new ArrayList(); try { st = PocketLadioUtility.GetWebStream(setting.HeadlineDatV2Url); WebTextFetch fetch = new WebTextFetch(st, Encoding.GetEncoding("shift-jis")); if (HeadlineFetch != null) { fetch.Fetch += HeadlineFetch; } if (HeadlineFetching != null) { fetch.Fetching += HeadlineFetching; } if (HeadlineFetched != null) { fetch.Fetched += HeadlineFetched; } string httpString = fetch.ReadToEnd(); channelsDat = httpString.Split('\n'); } finally { if (st != null) { st.Close(); } } // 番組の総数を数える int channelLength = 0; for (int i = 0; i < channelsDat.Length; ++i) { // 空行の場合 if (channelsDat[i] == string.Empty) { ++channelLength; } } OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, channelLength)); Channel channel = null; // 解析済みの番組数 int channelAnalyzed = 0; for (int count = 0; count < channelsDat.Length; ++count) { // Url取得 Match urlMatch = urlRegex.Match(channelsDat[count]); if (urlMatch.Success) { try { if (urlMatch.Groups[1].Value != string.Empty) { if (channel == null) { channel = new Channel(this); } channel.Url = new Uri(urlMatch.Groups[1].Value); } } catch (UriFormatException) { ; } continue; } // Gnl取得 Match gnlMatch = gnlRegex.Match(channelsDat[count]); if (gnlMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Gnl = gnlMatch.Groups[1].Value; continue; } Match namMatch = namRegex.Match(channelsDat[count]); if (namMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Nam = namMatch.Groups[1].Value; continue; } Match mntMatch = mntRegex.Match(channelsDat[count]); if (mntMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Mnt = mntMatch.Groups[1].Value; continue; } Match timsMatch = timsRegex.Match(channelsDat[count]); if (timsMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.SetTims(timsMatch.Groups[1].Value); continue; } // Cln取得 Match clnMatch = clnRegex.Match(channelsDat[count]); if (clnMatch.Success) { try { if (channel == null) { channel = new Channel(this); } channel.Cln = int.Parse(clnMatch.Groups[1].Value); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } continue; } // Clns取得 Match clnsMatch = clnsRegex.Match(channelsDat[count]); if (clnsMatch.Success) { try { if (channel == null) { channel = new Channel(this); } channel.Clns = int.Parse(clnsMatch.Groups[1].Value); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } continue; } Match maxMatch = maxRegex.Match(channelsDat[count]); if (maxMatch.Success) { if (channel == null) { channel = new Channel(this); } continue; } Match srvMatch = srvRegex.Match(channelsDat[count]); if (srvMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Srv = srvMatch.Groups[1].Value; continue; } Match prtMatch = prtRegex.Match(channelsDat[count]); if (prtMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Prt = prtMatch.Groups[1].Value; continue; } Match bitMatch = bitRegex.Match(channelsDat[count]); if (bitMatch.Success) { try { if (channel == null) { channel = new Channel(this); } channel.Bit = int.Parse(bitMatch.Groups[1].Value); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } continue; } Match songMatch = songRegex.Match(channelsDat[count]); if (prtMatch.Success) { if (channel == null) { channel = new Channel(this); } channel.Tit = songMatch.Groups[1].Value; continue; } if (channelsDat[count] == string.Empty) { if (channel != null) { alChannels.Add(channel); OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++channelAnalyzed, channelLength)); channel = null; } } } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(channelLength, channelLength)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); }
/// <summary> /// ヘッドラインをネットから取得する(XML使用) /// </summary> private void FetchHeadlineXml() { WebStream st = null; XmlTextReader reader = null; try { // 番組のリスト ArrayList alChannels = new ArrayList(); st = PocketLadioUtility.GetWebStream(setting.HeadlineXmlUrl); reader = new XmlTextReader(st); // チャンネル Channel channel = new Channel(this); // sourceタグの中にいるか bool inSourceFlag = false; // 解析したヘッドラインの個数 int analyzedCount = 0; OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "source") { inSourceFlag = true; channel = new Channel(this); } // End of source // sourceタグの中にいる場合 else if (inSourceFlag == true) { if (reader.LocalName == "url") { try { string url = reader.ReadString(); if (url != string.Empty) { channel.Url = new Uri(url); } } catch (UriFormatException) { ; } } // End of url else if (reader.LocalName == "gnl") { channel.Gnl = reader.ReadString(); } // End of gnl else if (reader.LocalName == "nam") { channel.Nam = reader.ReadString(); } // End of nam else if (reader.LocalName == "tit") { channel.Tit = reader.ReadString(); } // End of tit else if (reader.LocalName == "mnt") { channel.Mnt = reader.ReadString(); } // End of mnt else if (reader.LocalName == "tim") { channel.SetTim(reader.ReadString()); } // End of tim else if (reader.LocalName == "tims") { channel.SetTims(reader.ReadString()); } // End of tims else if (reader.LocalName == "cln") { try { channel.Cln = int.Parse(reader.ReadString()); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } // End of cln else if (reader.LocalName == "clns") { try { channel.Clns = int.Parse(reader.ReadString()); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } // End of clns else if (reader.LocalName == "srv") { channel.Srv = reader.ReadString(); } // End of srv else if (reader.LocalName == "prt") { channel.Prt = reader.ReadString(); } // End of prt else if (reader.LocalName == "typ") { channel.Typ = reader.ReadString(); } // End of typ else if (reader.LocalName == "bit") { try { channel.Bit = int.Parse(reader.ReadString()); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } // End of bit } // End of sourceタグの中にいる場合 } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName == "source") { inSourceFlag = false; alChannels.Add(channel); OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++analyzedCount, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); } } } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(analyzedCount, analyzedCount)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); } finally { if (st != null) { st.Close(); } if (reader != null) { reader.Close(); } } }
/// <summary> /// ヘッドラインをネットから取得する(CVS使用) /// </summary> private void FetchHeadlineCvs() { WebStream st = null; string[] channelsCvs; // チャンネルのリスト ArrayList alChannels = new ArrayList(); try { st = PocketLadioUtility.GetWebStream(setting.HeadlineCsvUrl); WebTextFetch fetch = new WebTextFetch(st, Encoding.GetEncoding("shift-jis")); if (HeadlineFetch != null) { fetch.Fetch += HeadlineFetch; } if (HeadlineFetching != null) { fetch.Fetching += HeadlineFetching; } if (HeadlineFetched != null) { fetch.Fetched += HeadlineFetched; } string httpString = fetch.ReadToEnd(); channelsCvs = httpString.Split('\n'); } finally { if (st != null) { st.Close(); } } OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, channelsCvs.Length - 1)); // 1行目はヘッダなので無視 for (int count = 1; count < channelsCvs.Length; ++count) { if (channelsCvs[count].Length > 0) { Channel channel = new Channel(this); string[] channelCsv = channelsCvs[count].Split(','); // CVS列が11列以上の場合のみ番組とみなす if (channelCsv.Length >= 11) { // Url取得 try { if (channelCsv[0] != string.Empty) { channel.Url = new Uri(channelCsv[0]); } } catch (UriFormatException) { ; } // PC上で起きることを確認したが、対処するべきか分からないのでとりあえず無視 catch (IndexOutOfRangeException) { ; } // Gnl取得 channel.Gnl = channelCsv[1]; // Nam取得 channel.Nam = channelCsv[2]; // Tit取得 channel.Tit = channelCsv[3]; // Mnt取得 channel.Mnt = channelCsv[4]; // Tim取得 channel.SetTim(channelCsv[5]); // Tims取得 channel.SetTims(channelCsv[6]); try { // Cln取得 channel.Cln = int.Parse(channelCsv[7]); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } try { // Clns取得 channel.Clns = int.Parse(channelCsv[8]); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } // Srv取得 channel.Srv = channelCsv[9]; // Prt取得 channel.Prt = channelCsv[10]; if (channelCsv.Length >= 12) { // Typ取得 channel.Typ = channelCsv[11]; } if (channelCsv.Length >= 13) { try { // Bit取得 channel.Bit = int.Parse(channelCsv[12]); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } alChannels.Add(channel); } } OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(count, channelsCvs.Length - 1)); } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(channelsCvs.Length - 1, channelsCvs.Length - 1)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); }
/// <summary> /// ヘッドラインをネットから取得する /// </summary> public virtual void FetchHeadline() { // 時刻をセットする lastCheckTime = DateTime.Now; WebStream st = null; XmlTextReader reader = null; try { // 番組のリスト ArrayList alChannels = new ArrayList(); // チャンネル Channel channel = null; // itemタグの中にいるか bool inEntry = false; st = PocketLadioUtility.GetWebStream(new Uri(Headline.ICECAST_URL)); reader = new XmlTextReader(st); // 解析したヘッドラインの個数 int analyzedCount = 0; OnHeadlineAnalyze(new HeadlineAnalyzeEventArgs(0, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.LocalName == "entry") { inEntry = true; channel = new Channel(this); } // End of item // Entryタグの中にいる場合 else if (inEntry == true) { if (reader.LocalName == "server_name") { channel.ServerName = reader.ReadString(); } // End of server_name else if (reader.LocalName == "listen_url") { try { channel.ListenUrl = new Uri(reader.ReadString()); } catch (UriFormatException) { ; } } // End of listen_url else if (reader.LocalName == "server_type") { channel.ServerType = reader.ReadString(); } // End of server_type else if (reader.LocalName == "bitrate") { try { channel.BitRate = int.Parse(reader.ReadString()); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } // End of bitrate else if (reader.LocalName == "channels") { channel.Channels = reader.ReadString(); } // End of channels else if (reader.LocalName == "samplerate") { try { channel.SampleRate = int.Parse(reader.ReadString()); } catch (ArgumentException) { ; } catch (FormatException) { ; } catch (OverflowException) { ; } } // End of samplerate else if (reader.LocalName == "genre") { channel.Genre = reader.ReadString(); } // End of genre else if (reader.LocalName == "current_song") { channel.CurrentSong = reader.ReadString(); } // End of current_song } // End of entryタグの中にいる場合 } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.LocalName == "entry") { inEntry = false; alChannels.Add(channel); OnHeadlineAnalyzing(new HeadlineAnalyzeEventArgs(++analyzedCount, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); // 指定の数のヘッドラインを取得し終わったら終了 if (setting.FetchChannelNum != Icecast.UserSetting.ALL_CHANNEL_FETCH && analyzedCount >= setting.FetchChannelNum) { break; } } } } OnHeadlineAnalyzed(new HeadlineAnalyzeEventArgs(analyzedCount, HeadlineAnalyzeEventArgs.UNKNOWN_WHOLE_COUNT)); channels = (Channel[])alChannels.ToArray(typeof(Channel)); } finally { if (st != null) { st.Close(); } if (reader != null) { reader.Close(); } } }