/// <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> /// ヘッドラインをネットから取得する /// </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> /// ヘッドラインをネットから取得する(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)); }