public static void RemovePodcast(Podcast podcast, bool save = true) { Podcasts.Remove(podcast); if (save) { Save(); } }
public static Episode GetEpisodeByUri(string enclosure) { try { return(Podcasts.SelectMany(p => p.Episodes).FirstOrDefault(e => !string.IsNullOrEmpty(e.Enclosure) && new Uri(e.Enclosure).ToString() == enclosure)); } catch { return(null); } }
public static void Clear() { var podcasts = Podcasts.ToArray(); foreach (var podcast in podcasts) { RemovePodcast(podcast, false); } Podcasts.Clear(); lock (DownloadedEpisodes) { DownloadedEpisodes.Clear(); } }
public static async Task DumpFromCloudAsync(string cloudData) { var temp = JsonConvert.DeserializeObject <ObservableCollection <Podcast> >(cloudData); Clear(); foreach (var podcast in temp) { Podcasts.Add(podcast); podcast.CheckDownloads(); podcast.GetLocalImage(); } CheckZombieFolders(); await SaveAsync(); await DeserializeAsync(true); }
public static async Task LoadCastFile(StorageFile libraryFile, bool merge) { SuccessfullyLoaded = false; Debug.WriteLine("> Deserialize podcasts"); Notifier.BlockUpdates = true; Debug.WriteLine("> Load json file"); var json = await FileIO.ReadTextAsync(libraryFile); var temp = JsonConvert.DeserializeObject <List <Podcast> >(json); Notifier.BlockUpdates = false; Debug.WriteLine("> Check downloads and local image"); if (temp != null) { if (!merge) { Clear(); } foreach (var podcast in temp) { if (GetPodcastByFeedUrl(podcast.FeedUrl) != null) { continue; } Podcasts.Add(podcast); podcast.Clean(); podcast.CheckDownloads(); podcast.GetLocalImage(); } } Debug.WriteLine("> Loaded episodes: " + Podcasts.SelectMany(p => p.Episodes).Count()); Debug.WriteLine("> CheckZombieFolders"); CheckZombieFolders(); Debug.WriteLine("> Loading done"); SuccessfullyLoaded = true; }
public static async Task SaveOPMLFile(StorageFile libraryFile) { var document = new Windows.Data.Xml.Dom.XmlDocument(); var rootNode = document.CreateElement("opml"); rootNode.AddAttribute("version", "1.1"); document.AppendChild(rootNode); var headNode = document.CreateElement("head"); headNode.AddChildWithInnerText("title", "Generated by Cast"); headNode.AddChildWithInnerText("dateCreated", DateTime.Now.ToString(CultureInfo.InvariantCulture)); rootNode.AppendChild(headNode); var bodyNode = document.CreateElement("body"); rootNode.AppendChild(bodyNode); foreach (var category in Categories) { var categoryNode = document.CreateElement("outline"); bodyNode.AppendChild(categoryNode); categoryNode.AddAttribute("text", category); foreach (var podcast in Podcasts.Where(p => p.Category == category)) { var podcastNode = document.CreateElement("outline"); categoryNode.AppendChild(podcastNode); podcastNode.AddAttribute("title", podcast.Title); podcastNode.AddAttribute("type", "rss"); podcastNode.AddAttribute("text", podcast.FeedUrl); podcastNode.AddAttribute("xmlUrl", podcast.FeedUrl); } } await document.SaveToFileAsync(libraryFile); }
public static async Task LoadOPMLFile(StorageFile libraryFile, bool merge) { var document = new Windows.Data.Xml.Dom.XmlDocument(); var content = await FileIO.ReadTextAsync(libraryFile); document.LoadXml(content); var bodyNode = document.DocumentElement.GetChildByName("body"); var categoriesNodes = bodyNode.ChildNodes.Where(n => n is Windows.Data.Xml.Dom.XmlElement).Cast <Windows.Data.Xml.Dom.XmlElement>().ToArray(); SuccessfullyLoaded = false; if (!merge) { Clear(); } foreach (var categoryNode in categoriesNodes) { if (categoryNode.HasChildNodes()) { var category = categoryNode.GetAttributeValue("text"); var podcastsNodes = categoryNode.ChildNodes.Where(n => n is Windows.Data.Xml.Dom.XmlElement).Cast <Windows.Data.Xml.Dom.XmlElement>().ToArray(); foreach (var podcastNode in podcastsNodes) { var feedUrl = podcastNode.GetAttributeValue("xmlUrl"); if (string.IsNullOrEmpty(feedUrl)) { feedUrl = podcastNode.GetAttributeValue("text"); } if (GetPodcastByFeedUrl(feedUrl) != null) { continue; } var podcast = await Podcast.ParseAsync(feedUrl, true); if (podcast != null) { podcast.Category = category; Podcasts.Add(podcast); podcast.Clean(); podcast.CheckDownloads(); podcast.GetLocalImage(); } } } else { var feedUrl = categoryNode.GetAttributeValue("xmlUrl"); if (string.IsNullOrEmpty(feedUrl)) { feedUrl = categoryNode.GetAttributeValue("text"); } var podcast = await Podcast.ParseAsync(feedUrl, true); if (podcast != null) { podcast.Category = StringsHelper.NoCategory; Podcasts.Add(podcast); podcast.CheckDownloads(); podcast.GetLocalImage(); } } } CheckZombieFolders(); SuccessfullyLoaded = true; }
public static void RefreshAllPodcasts() { if (RefreshInProgress) { return; } if (Podcasts.Count == 0) { fullRefreshEvent.Set(); return; } if (lastFullRefresh.HasValue) { if (DateTime.Now.Subtract(lastFullRefresh.Value).TotalDays < 1) { fullRefreshEvent.Set(); return; } } lastFullRefresh = DateTime.Now; RefreshInProgress = true; Task.Run(async() => { try { fullRefreshEvent.Reset(); if (NetworkHelper.Instance.ConnectionInformation.IsInternetAvailable) { // background downloads await ReconnectBackgroundDownloadsAsync(); } var tasks = Podcasts.Select(async podcast => { podcast.CheckDownloads(); await podcast.RefreshAsync(false, true, false); }).ToList(); await Task.WhenAll(tasks); if (LocalSettings.Instance.NewEpisodesCount > 0) { await SaveAsync(); } OnFullRefreshDone?.Invoke(); fullRefreshEvent.Set(); FullRefreshExecutedOnce = true; } catch { // Ignore error fullRefreshEvent.Set(); } RefreshInProgress = false; }); }
public static Podcast GetPodcastByRoot(string root) { return(Podcasts.FirstOrDefault(p => p.Root == root)); }
public static Podcast GetPodcastByFeedUrl(string podcastFeedUrl) { return(Podcasts.FirstOrDefault(p => p.FeedUrl == podcastFeedUrl)); }
public static bool ContainsFeedUrl(string podcastFeedUrl) { return(Podcasts.Any(p => p.FeedUrl == podcastFeedUrl)); }
public static Episode GetEpisodeByEnclosure(string enclosure) { return(Podcasts.SelectMany(p => p.Episodes).FirstOrDefault(e => e.Enclosure == enclosure)); }