Solocast.Services.PodcastService.DownloadEpisodeAsync C# (CSharp) Method

DownloadEpisodeAsync() public method

public DownloadEpisodeAsync ( Episode episode ) : System.Threading.Tasks.Task
episode Episode
return System.Threading.Tasks.Task
        public async Task DownloadEpisodeAsync(Episode episode)
        {
            var file = await fileDownloadManager.DownloadFileAsync(
                appFolderName: AppName,
                folderName: episode.Podcast.Title,
                fileName: string.Format("{0:dd.MM.yyyy} - {1} - {2}", episode.Published, episode.Author, episode.Title),
                fileUrl: episode.Path,
                callback: c =>
                {
                    var bytesReceived = c.Progress.BytesReceived;
                    var bytesToReceive = c.Progress.TotalBytesToReceive;
                    double percent = (bytesReceived * 100) / bytesToReceive;

                    Debug.WriteLine(string.Format("Received: {0}/{1} ({2:P1})", bytesReceived, bytesToReceive, percent / 100.0));
                },
                errorCallback: ex =>
                {
                    Debug.WriteLine(string.Format(ex.Message));
                }
                );

            if (file != null)
            {
                var podcast = episode.Podcast;
                var episodeToUpdate = podcast.Episodes.Where(e => e.Guid == episode.Guid).SingleOrDefault();

                episodeToUpdate.Path = file.Path;
                await storageService.SaveAsync(episode.Podcast);
            }
        }

Usage Example

Beispiel #1
0
        public void TestDownload()
        {
            var localStorage = new LocalPodcastService("podcasts.json");
            var feedParser = new FeedParserService();
            var fileManager = new FileDownloadService();
            var podcastService = new PodcastService(feedParser, localStorage, fileManager);

            var podcastFromService = podcastService.GetPodcastAsync("http://monstercat.com/podcast/feed.xml").Result;
            podcastService.DownloadEpisodeAsync(podcastFromService.Episodes.OrderByDescending(e => e.Published).ToList()[0]).Wait();
        }