/// <summary> /// 選択された番組からm3uファイルを作成し、それをメディアプレイヤーに渡して実行する /// </summary> private void PlayPodcast() { // 選択された番組のリスト ArrayList alSelectedLocalChannels = new ArrayList(); // 選択された番組でクリップ済みの番組のリストを作る foreach (IChannel channel in StationList.GetChannelsOfCurrentStationFromLocalHeadline()) { if (channel.Check == true) { alSelectedLocalChannels.Add(channel); } } // 選択されたクリップ済みの番組が無い場合は警告を出して終了 if (alSelectedLocalChannels.Count == 0) { MessageBox.Show("クリップ済みの番組が選択されていません", "情報"); return; } // すでにあるm3uファイルを削除 if (File.Exists(UserSetting.M3uFilePath)) { File.Delete(UserSetting.M3uFilePath); } try { // ディレクトリを作成する if (Directory.Exists(UserSetting.PodcastClipDirectoryPath) == false) { Directory.CreateDirectory(UserSetting.PodcastClipDirectoryPath); } using (StreamWriter sw = new StreamWriter(UserSetting.M3uFilePath, false, Encoding.Default)) { foreach (IChannel channel in (IChannel[])alSelectedLocalChannels.ToArray(typeof(IChannel))) { sw.WriteLine(channel.GetPlayUrl().LocalPath); } } } catch (IOException) { } try { PodcasCoUtility.PlayStreaming(UserSetting.M3uFilePath); } catch (FileNotFoundException) { MessageBox.Show("メディアプレイヤーが見つかりません", "警告"); } }
/// <summary> /// 番組をクリップする /// </summary> /// <param name="clippingForm">ClippingForm</param> public static void ClippingPodcast(ClippingForm clippingForm) { // すでにクリップした番組 int alreadyClippingFiles = 0; // クリップできない番組があったか bool cannotCliped = false; // クリップできなかった番組の情報 string cannotClipedString = string.Empty; // 選択された番組のリスト ArrayList alSelectedGlobalChannels = new ArrayList(); // 選択された番組で未クリップの番組のリストを作る foreach (IChannel channel in GetUnclipedChannelsOfCurrentStation()) { if (channel.Check == true) { alSelectedGlobalChannels.Add(channel); } } if (clippingForm != null) { clippingForm.OnFile(new FileEventArgs(0, alSelectedGlobalChannels.Count)); } foreach (IChannel channel in (IChannel[])alSelectedGlobalChannels.ToArray(typeof(IChannel))) { try { // URLがnullの場合に対処 if (channel.GetPlayUrl() == null) { throw new WebException(); } string directoryName = UserSetting.PodcastClipDirectoryPath + @"\" + channel.ParentHeadline.ParentStation.LocalHeadline.GetId(); if (Directory.Exists(directoryName) == false) { Directory.CreateDirectory(directoryName); } string generateFilePath = directoryName + @"\" + Path.GetFileNameWithoutExtension(channel.GetPlayUrl().LocalPath) + "-" + channel.GetHash().ToString("x") + Path.GetExtension(channel.GetPlayUrl().LocalPath); PodcasCoUtility.FetchFile(channel.GetPlayUrl(), generateFilePath, new FetchEventHandler(clippingForm.ClipReceiver), new FetchEventHandler(clippingForm.ClippingReceiver), null); // 番組をローカルヘッドラインに加える IChannel localChannel = (IChannel)channel.Clone(channel.ParentHeadline.ParentStation.LocalHeadline); localChannel.SetPlayUrl(new Uri(generateFilePath)); localChannel.ParentHeadline.ParentStation.LocalHeadline.AddChannel(localChannel); // ダウンロードした番組の元のグローバル番組からはチェックを外す channel.Check = false; } catch (WebException) { cannotCliped = true; cannotClipedString += channel.ParentHeadline.ParentStation.Name + " - " + channel.GetTitle() + "\n"; } catch (UriFormatException) { cannotCliped = true; cannotClipedString += channel.ParentHeadline.ParentStation.Name + " - " + channel.GetTitle() + "\n"; } catch (SocketException) { cannotCliped = true; cannotClipedString += channel.ParentHeadline.ParentStation.Name + " - " + channel.GetTitle() + "\n"; } if (clippingForm != null) { clippingForm.OnFiling(new FileEventArgs(++alreadyClippingFiles, alSelectedGlobalChannels.Count)); } } // RSSを作成 StationList.GenerateRssLocalHeadlines(); if (cannotCliped == true) { throw new ClippingException(cannotClipedString); } }