Esempio n. 1
0
        private string GetiTunesSourceUrl(PodcastGenre genre, uint limit)
        {
            var url = string.Empty;

            if (genre != 0)
            {
                url = string.Format(iTunesPodcastFormatGenre, limit, (int)genre);
            }
            else
            {
                url = string.Format(iTunesPodcastFormatAll, limit);
            }
            return(url);
        }
Esempio n. 2
0
        private string GetiTunesSourceRss(PodcastGenre genre, uint limit)
        {
            var rss       = string.Empty;
            var url       = GetiTunesSourceUrl(genre, limit);
            var webClient = new WebClient();

            Stream st = webClient.OpenRead(url);

            using (var sr = new StreamReader(st))
            {
                rss = sr.ReadToEnd();
            }

            return(rss);
        }
Esempio n. 3
0
 /// <summary>
 /// Gets a collection <see cref="PodcastFeed"/>, listed at the top charts for the given genre.
 /// </summary>
 /// <param name="genre">Genre for which to read the top charts.</param>
 /// <param name="podcastFeeds">Collection of podcasts read from the top charts.</param>
 /// <param name="errorMessage">A description of any error that occurred, null if successful.</param>
 /// <param name="maxPodcastLimit">Max numbe of podcasts to read from the top charts (Defaults to 10).</param>
 /// <returns>True when successful, false otherwise.</returns>
 public bool TryGetTopCharts(PodcastGenre genre, out IEnumerable <PodcastFeed> podcastFeeds, out string errorMessage, uint maxPodcastLimit = 10)
 {
     errorMessage = null;
     podcastFeeds = null;
     try
     {
         podcastFeeds = GetTopCharts(genre, maxPodcastLimit);
         return(true);
     }
     catch (Exception ex)
     {
         errorMessage = ex.Message;
         return(false);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Get a list of top podcasts
        /// </summary>
        /// <param name="genre">Podcast genre</param>
        /// <param name="maxItems">Maximum number of items you want to retrieve</param>
        /// <param name="country">Two-letter country code (ISO 3166-1 alpha-2)</param>
        /// <returns>list of top podcasts</returns>
        public async Task <IEnumerable <Podcast> > GetTopPodcastsAsync(PodcastGenre genre = PodcastGenre.All, int maxItems = 100, string country = "us")
        {
            if (country == null)
            {
                throw new ArgumentNullException(nameof(country));
            }
            if (maxItems < 1)
            {
                throw new ArgumentException("The maximum number of items must be greater than zero", nameof(maxItems));
            }

            Uri    url  = new Uri(string.Format(base_top_url, country, maxItems, (int)genre));
            string json = await WebRequestAsync(url).ConfigureAwait(false);

            return(JsonHelper.DeserializePodcast(json));
        }
Esempio n. 5
0
        private PodcastFeed GetiTunesPodcasts(PodcastGenre genre, uint limit)
        {
            var url = GetiTunesSourceUrl(genre, limit);

            var sourceSub = new PodcastFeed()
            {
                RssLink  = url,
                Title    = genre.ToString(),
                Category = "iTunes",
                MaxItems = limit,
            };

            _parser.LoadPodcastFeed(sourceSub, limit);

            return(sourceSub);
        }
Esempio n. 6
0
        public IEnumerable <PodcastFeed> GetPodcasts(PodcastGenre genre, uint limit)
        {
            var podcastsChart        = GetiTunesPodcasts(genre, limit);
            List <PodcastFeed> feeds = new List <PodcastFeed>();
            int count = 0;

            foreach (var podcast in podcastsChart.PodcastEpisodes)
            {
                var podcastId       = GetPodcastId(podcast.Link);
                var podcastInfoJson = GetPodcastInfoJson(podcastId);
                var subscriptions   = DeserializeFeeds(podcastInfoJson, _parser);
                var sub             = subscriptions.FirstOrDefault();

                if (sub != null && feeds.FirstOrDefault(p => p.Title == sub.Title) == null)
                {
                    feeds.Add(sub);
                }

                double percent = (double)(++count) / (double)podcastsChart.PodcastEpisodes.Count;
                OnPodcastSourceUpdated(percent);
            }
            return(feeds);
        }
Esempio n. 7
0
        public void GetPodcastsAsync(PodcastGenre genre, uint limit)
        {
            var thread = new Thread(() => GetPodcasts(genre, limit));

            thread.Start();
        }
        public void TryGetTopCharts_ShouldInvokePodcastChartsUnitTest(PodHead sut, IPodcastCharts podcastCharts, PodcastGenre podcastGenre, uint limit)
        {
            sut.SetField(typeof(IPodcastCharts), podcastCharts);
            bool success = sut.TryGetTopCharts(podcastGenre, out IEnumerable <PodcastFeed> podcasts, out string errors, limit);

            Assert.IsTrue(success);
            Assert.IsNull(errors);
            podcastCharts.Received(1).GetPodcasts(podcastGenre, limit);
        }
 public void GetTopCharts_ShouldInvokePodcastChartsUnitTest(PodHead sut, IPodcastCharts podcastCharts, PodcastGenre podcastGenre, uint limit)
 {
     sut.SetField(typeof(IPodcastCharts), podcastCharts);
     sut.GetTopCharts(podcastGenre, limit);
     podcastCharts.Received(1).GetPodcasts(podcastGenre, limit);
 }
Esempio n. 10
0
 /// <summary>
 /// Gets a collection <see cref="PodcastFeed"/>, listed at the top charts for the given genre.
 /// </summary>
 /// <param name="genre">Genre for which to read the top charts.</param>
 /// <param name="maxPodcastLimit">Max number of podcasts to read from the top charts (Defaults to 10).</param>
 /// <returns>Collection of podcast top charts results.</returns>
 public IEnumerable <PodcastFeed> GetTopCharts(PodcastGenre genre, uint maxPodcastLimit = 10)
 {
     return(_podcastCharts.GetPodcasts(genre, maxPodcastLimit));
 }