private void addEpisode(PodcastEpisode Episode) { lock (episodeLock) { System.Diagnostics.Debug.Assert(Episode != null && Episode.GUID.Length > 0); if (episodes.Contains(Episode)) { //PodcastEpisode pe = episodes.Find(e => Episode.Equals(e)); //if (pe != null) // pe.Description = Episode.Description; return; } else { episodes.Add(Episode); } } if (Episode.DownloadDate > this.LastDownloadDate) { this.LastDownloadDate = Episode.DownloadDate; } Episode.DataChanged += (s) => { updateForEpisodeChange(Episode); }; }
private void lvwEpisodes_ContextMenuHook(ContextMenuStrip ContextMenu, PodcastEpisode Item) { ToolStripMenuItem tsi = new ToolStripMenuItem("Play"); tsi.Click += (s, ee) => { playEpisode(Item); }; tsi.Enabled = Item.Playable; ContextMenu.Items.Add(tsi); tsi = new ToolStripMenuItem("&Find in Library"); tsi.Click += (s, ee) => { controller.ShowTrack(Item.Track, true); }; tsi.Enabled = Item.Track != null; ContextMenu.Items.Add(tsi); ContextMenu.Items.Add(new ToolStripSeparator()); tsi = new ToolStripMenuItem("Mark As"); ToolStripMenuItem tsi2 = new ToolStripMenuItem("Unplayed"); tsi2.Click += (s, ee) => { Item.SetDownloadStatus(PodcastDownloadStatus.Unplayed); }; tsi2.Enabled = (Item.DownloadStatus == PodcastDownloadStatus.Played); tsi.DropDownItems.Add(tsi2); tsi2 = new ToolStripMenuItem("Played"); tsi2.Click += (s, ee) => { Item.SetDownloadStatus(PodcastDownloadStatus.Played); }; tsi2.Enabled = (Item.DownloadStatus == PodcastDownloadStatus.Unplayed); tsi.DropDownItems.Add(tsi2); ContextMenu.Items.Add(tsi); }
public static void CancelDownload(PodcastEpisode PE) { PE.CancelDownload(); lock (syncQueueLock) { syncQueue.Remove(PE); } }
private static void startSync() { if (syncing) { return; } syncing = true; try { while (!cancelDownload) { PodcastEpisode ep = null; lock (syncQueueLock) { if (syncQueue.Count > 0) { ep = syncQueue[0]; syncQueue.RemoveAt(0); } else { cancelDownload = true; } } if (ep != null) { lock (episodeLock) { downloadingEpisodes.Add(ep); } Clock.DoOnNewThread(ep.Download); bool wait; do { lock (episodeLock) { wait = downloadingEpisodes.Count >= Setting.PodcastMaxConcurrentDownloads; } System.Threading.Thread.Sleep(1000); }while (wait); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } finally { syncing = false; } }
private void downloadEpisode(PodcastEpisode PE) { if (PE.IsQueuedOrDownloading) { PodcastSubscription.CancelDownload(PE); } else { Clock.DoOnNewThread(PE.QueueForDownload); } }
public void DownloadLatestEpisode() { PodcastEpisode pe = this.LatestEpisode; if (pe != null && pe.IsQueueable) { PodcastSubscription.Download(pe); if (DataChanged != null) { DataChanged(this); } } }
private void lvwEpisodes_DoubleClickCallback(PodcastEpisode SelectedItem) { if (!Locked) { if (SelectedItem.Playable) { Controller.GetInstance().Play(SelectedItem); } else { PodcastSubscription.Download(SelectedItem); lvwEpisodes.Invalidate(); } } }
public static void StopDownloads() { cancelDownload = true; PodcastEpisode.CancelAllDownloads(); lock (syncQueueLock) { foreach (PodcastEpisode pe in syncQueue) { pe.SetDownloadStatus(PodcastDownloadStatus.DownloadCanceled); } syncQueue.Clear(); } }
public static void Download(PodcastEpisode PE) { cancelDownload = false; if (PE != null && PE.IsDownloadable) { PE.SetDownloadStatus(PodcastDownloadStatus.QueuedForDownload); lock (syncQueueLock) { if (!syncQueue.Contains(PE)) { syncQueue.Add(PE); Clock.DoOnNewThread(startSync, 100); } } } }
private void updateForEpisodeChange(PodcastEpisode Episode) { if (Episode.DownloadDate > this.LastDownloadDate) { this.LastDownloadDate = Episode.DownloadDate; } lock (episodeLock) { if (!Episode.IsDownloading && downloadingEpisodes.Contains(Episode)) { downloadingEpisodes.Remove(Episode); } } updateValues(); this.DataChanged(this); }
private void removeEpisode(PodcastEpisode PE) { List <frmTaskDialog.Option> options = new List <frmTaskDialog.Option>(); if (PE.Playable || PE.IsDownloading) // only ask if there's already some data { options.Add(new frmTaskDialog.Option("Remove Podcast Entry", "Remove this episode from the episode list but leave the audio file in your library.", 1)); options.Add(new frmTaskDialog.Option("Remove All", "Remove this episode from the list and delete the audio file.", 2)); options.Add(new frmTaskDialog.Option("Cancel", "Don't remove this episode.", 0)); frmTaskDialog od = new frmTaskDialog("Remove Podcast Episode", "Choose an option for removing a podcast episode:", options); od.ShowDialog(this); switch (od.ResultIndex) { case 0: return; case 1: break; case 2: if (PE.Track != null) { Database.RemoveFromLibrary(new List <Track>() { PE.Track }); TrackWriter.AddToDeleteList(PE.Track.FilePath); TrackWriter.DeleteItems(); PE.Track = null; } break; } } PE.SetDownloadStatus(PodcastDownloadStatus.Deleted); lvwEpisodes.RemoveItem(PE); }
private void lvwEpisodes_ClickCallback(PodcastEpisode SelectedItem) { System.Diagnostics.Debug.WriteLine(SelectedItem.ToString()); }
private void playEpisode(PodcastEpisode PE) { controller.Play(PE); }
public void UpdateEpisodeInfo() { try { XmlDocument doc = new XmlDocument(); doc.Load(URL); XmlNode baseNode = doc.SelectSingleNode("rss").FirstChild; if (baseNode != null) { if (this.Name == UNKNOWN_TITLE || Keyboard.Shift) { this.Name = getXMLField(baseNode, "title"); } this.ReferenceURL = getXMLField(baseNode, "link"); CultureInfo ci = CultureInfo.InvariantCulture; foreach (XmlNode xn in doc.SelectNodes("//item")) { try { string url = xn.SelectSingleNode("enclosure").Attributes["url"].Value; string date = String.Empty; string guid = String.Empty; string title = String.Empty; string description = String.Empty; string durationString = String.Empty; int duration = 0; if (url.Length > 0 && Track.IsValidExtension(Path.GetExtension(url))) { foreach (XmlNode n in xn.ChildNodes) { switch (n.Name.ToLowerInvariant()) { case "pubdate": date = n.InnerText; break; case "guid": guid = n.InnerText; break; case "title": title = n.InnerText; break; case "description": if (description.Length == 0) { description = n.InnerText; } break; case "itunes:duration": durationString = n.InnerText; break; case "itunes:summary": description = n.InnerText; break; default: System.Diagnostics.Debug.WriteLine(n.Name.ToLowerInvariant()); break; } } DateTime dt; if (!DateTime.TryParse(date, out dt)) { if (!DateTime.TryParseExact(date, dateParseFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dt)) { dt = extractDate(date); } } if (guid.Length == 0) { guid = url; } if (durationString.Length > 0) { duration = durationFromString(durationString); } PodcastEpisode pe = new PodcastEpisode(title, guid, clean(description), url, dt, duration, DateTime.MinValue, PodcastDownloadStatus.NotDownloaded, null, this); addEpisode(pe); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } updateValues(); if (DataChanged != null) { DataChanged(this); } Controller.ShowMessage("Refreshed " + this.Name); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); Controller.ShowMessage("Failed to find podcast updates."); } }