コード例 #1
0
        public static async Task<Episode> DownloadPodcastEpisodeAsync(Episode episode, Action<DownloadOperation> callback, Action errorCallback = null)
        {
            var appFolder = await KnownFolders.MusicLibrary.CreateFolderAsync("PodcastR", CreationCollisionOption.OpenIfExists);
            var podcastFolder = await appFolder.CreateFolderAsync(episode.Podcast.Name, CreationCollisionOption.OpenIfExists);
            try
            {
                var uri = new Uri(episode.WebPath);
                var extension = uri.AbsolutePath.GetExtension();
                var fileName = (episode.Name + extension).RemoveIllegalPathChars().Replace(":", "");
                var episodeFile = await podcastFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
                var backgroundDownloader = new BackgroundDownloader();
                var downloadOperation = backgroundDownloader.CreateDownload(uri, episodeFile);
                var progress = new Progress<DownloadOperation>(callback);
                downloads.Add(episode, downloadOperation);
                var cts = new CancellationTokenSource();
                cancellationTokenSources.Add(episode, cts);

                await downloadOperation.StartAsync().AsTask(cts.Token, progress);

                downloads.Remove(episode);
                cancellationTokenSources.Remove(episode);
                episode.IsLocal = true;
                episode.WebPath = episodeFile.Path;
                return episode;
            }
            catch
            {
                if (errorCallback != null)
                    errorCallback();
                return episode;
            }
        }
コード例 #2
0
        public static async Task<IList<Episode>> CheckForNewEpisodes(IEnumerable<Podcast> podcasts)
        {
            var result = new List<Episode>();
            foreach (var podcast in podcasts.ToList())
            {
                try
                {
                    var httpClient = new HttpClient();
                    var xml = await httpClient.GetStringAsync(podcast.FeedUrl);
                    var xmlDocument = XDocument.Parse(xml);

                    var elements = xmlDocument.Element("rss").Element("channel").Elements("item");
                    foreach (var element in elements)
                    {
                        var episode = new Episode(element, podcast);
                        if (!podcast.Episodes.Any(e => string.Compare(e.Name, episode.Name) == 0))
                        {
                            podcast.Episodes.Insert(0, episode);
                            result.Add(episode);
                        }
                    }
                }
                catch
                {

                }
            }

            return result.OrderBy(e => e.Published).ToList();
        }
コード例 #3
0
 public EpisodeViewModel(Episode episode)
 {
     this.Episode = episode;
     this.IsLocal = episode.IsLocal;
     this.ToggleEpisodeLocationCommand = new SymbolCommand(new GalaSoft.MvvmLight.Command.RelayCommand(async () => await this.ToggleEpisodeLocationAsync()), this.IsLocal ? Symbol.Delete : Symbol.Download, this.IsLocal ? "Delete" : "Download");
     this.PlayCommand = new SymbolCommand(new GalaSoft.MvvmLight.Command.RelayCommand(() => this.Play()), Symbol.Play, "Play");
 }
コード例 #4
0
 public static void CancelDownload(Episode episode)
 {
     var cancellationTokenSource = cancellationTokenSources[episode];
     cancellationTokenSource.Cancel();
     cancellationTokenSource.Dispose();
     cancellationTokenSources.Remove(episode);
     downloads.Remove(episode);
 }
コード例 #5
0
 public static void ResumeDownload(Episode episode)
 {
     var downloadOperation = downloads[episode];
     if (downloadOperation.Progress.Status == BackgroundTransferStatus.PausedByApplication)
     {
         downloadOperation.Resume();
     }
 }
コード例 #6
0
 public static void PauseDownload(Episode episode)
 {
     var downloadOperation = downloads[episode];
     if (downloadOperation.Progress.Status == BackgroundTransferStatus.Running)
     {
         downloadOperation.Pause();
     }
 }
コード例 #7
0
 public static async Task DeletePodcastEpisodeAsync(Episode episode)
 {
     var file = await StorageFile.GetFileFromPathAsync(episode.WebPath);
     await file.DeleteAsync();
     episode.WebPath = episode.WebPath;
     episode.IsLocal = false; ;
 }
コード例 #8
0
ファイル: App.xaml.cs プロジェクト: robertiagar/podcastr
 public static void UpdateSystemControls(Episode episode)
 {
     if (systemControls != null)
     {
         systemControls.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromUri(episode.ImageUrl);
         systemControls.DisplayUpdater.MusicProperties.AlbumArtist = episode.Podcast.Name;
         systemControls.DisplayUpdater.MusicProperties.Artist = episode.Author;
         systemControls.DisplayUpdater.MusicProperties.Title = episode.Name;
         systemControls.DisplayUpdater.Update();
         systemControls.PlaybackStatus = MediaPlaybackStatus.Playing;
     }
 }
コード例 #9
0
        public static async Task<Podcast> LoadPodcastAsync(Uri url)
        {
            try
            {
                var httpClient = new HttpClient();
                var xml = await httpClient.GetStringAsync(url);
                var xmlDocument = XDocument.Parse(xml);

                var channelTitle = xmlDocument.Element("rss").Element("channel").Element("title").Value;
                XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";
                var elements = xmlDocument.Element("rss").Element("channel").Elements("item");
                var description = xmlDocument.Element("rss").Element("channel").Element("description").Value;
                var imageUrl = xmlDocument.Element("rss").Element("channel").Element(itunes + "image").Attribute("href").Value;
                var author = xmlDocument.Element("rss").Element("channel").Element(itunes + "author").Value;

                var podcast = new Podcast
                {
                    FeedUrl = url,
                    Name = channelTitle,
                    ImageUrl = new Uri(imageUrl),
                    Author = author,
                    Description = description,
                    DateAdded = DateTime.Now
                };

                var episodes = new List<Episode>();

                foreach (var element in elements)
                {
                    var episode = new Episode(element, podcast);
                    episodes.Add(episode);
                }
                podcast.Episodes = episodes.OrderByDescending(episode => episode.Published).ToList();

                return podcast;
            }
            catch
            {
                return null;
            }
        }