Пример #1
0
        public async Task <PodcastChannel> GetPodcastFeedAsync(string url)
        {
            var podcastChannel = new PodcastChannel {
                Episodes = new List <Episode>()
            };
            var response = await HttpClient.GetStringAsync(url);

            //Should be on a separate service
            return(await Task.Run(() =>
            {
                var xdoc = XDocument.Parse(response);

                foreach (var item in xdoc.Descendants("item"))
                {
                    Episode episode = new Episode
                    {
                        Title = item.Element("title")?.Value,
                        EpisodeNumber = item.Element(itunes + "episode")?.Value,
                        Duration = item.Element(itunes + "duration")?.Value,
                        Explicit = item.Element(itunes + "explicit")?.Value,
                        AudioLink = item.Element("enclosure")?.Attribute("url")?.Value,
                        PublicationDate = item.Element("pubDate")?.Value
                    };

                    podcastChannel.Episodes.Add(episode);
                }

                podcastChannel.Link = xdoc.Root.Element("channel").Element("link")?.Value;
                podcastChannel.Summary = xdoc.Root.Element("channel").Element("description")?.Value;
                Debug.WriteLine($"Episodes Count: {podcastChannel.Episodes.Count}");
                return podcastChannel;
            }));
        }
Пример #2
0
        private async Task <PodcastChannel> ParsePodcastFeed(string responseString)
        {
            var podcastChannel = new PodcastChannel();

            podcastChannel.Episodes = new List <Episode>();

            return(await Task.Run(() =>
            {
                var xdoc = XDocument.Parse(responseString);

                XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";

                foreach (var item in xdoc.Descendants("item"))
                {
                    if (item.Element(itunes + "episodeType").Value == "full")
                    {
                        var episode = new Episode
                        {
                            Title = item.Element("title").Value,
                            EpisodeNumber = item.Element(itunes + "episode").Value,
                            Duration = item.Element(itunes + "duration").Value,
                            Explicit = item.Element(itunes + "explicit").Value,
                            AudioLink = item.Element("enclosure").Attribute("url").Value
                        };

                        podcastChannel.Episodes.Add(episode);
                    }
                }
                podcastChannel.Link = xdoc.Root.Element("channel").Element("link").Value;
                podcastChannel.Summary = xdoc.Root.Element("channel").Element("description").Value;

                return podcastChannel;
            }));
        }
Пример #3
0
 public PodcastSource(UITableView tableView, PodcastChannel podcast, Dictionary <string, string> locationResources)
 {
     _tableView         = tableView;
     _podcast           = podcast;
     _locationResources = locationResources;
     tableView.RegisterNibForCellReuse(EpisodeCell.Nib, EpisodeCell.Key);
     tableView.RegisterNibForCellReuse(ConnectionCell.Nib, ConnectionCell.Key);
     tableView.RegisterNibForCellReuse(AboutCell.Nib, AboutCell.Key);
     tableView.RegisterNibForCellReuse(PodcastHeaderCell.Nib, PodcastHeaderCell.Key);
 }
Пример #4
0
 public static TrackInfo ToTrackInfo(this FeedItem feedItem, PodcastChannel channel)
 {
     return(new TrackInfo
     {
         Id = feedItem.Id,
         CollectionId = channel.CollectionId,
         Title = feedItem.Title,
         Path = feedItem.Uri,
         Duration = feedItem.Duration
     });
 }
Пример #5
0
        public async Task ClickChannelRow(PodcastChannel channel)
        {
            var feed = await Data.GetEpisodes(channel.CollectionId);

            CurrentChannelSummary = new ChannelSummary
            {
                Title       = feed.Title,
                Description = feed.Description,
                ImageUrl    = feed.ImageUrl,
            };
            EpisodesFiltered = feed.Items.Select(i => i.ToTrackInfo(channel)).ToList();
        }
Пример #6
0
        public async Task <IActionResult> ChannelCreate(PodcastChannel podcastchannel)
        {
            //Ignore user from model state
            // ModelState.Remove("podcastchannel.User");

            //This creates a new variable to hold our current instance of the ActiveCustomer class and then sets the active customer's id to the CustomerId property on the product being created so that a valid model is sent to the database
            var user = await GetCurrentUserAsync();

            if (ModelState.IsValid)
            {
                // podcastchannel.User = user;
                context.Add(podcastchannel);
                await context.SaveChangesAsync();

                return(RedirectToAction("Create"));
            }

            ChannelCreateViewModel model = new ChannelCreateViewModel(context, user);

            return(View(model));
        }
Пример #7
0
        public async Task AddNewChannel(PodcastChannel podcast)
        {
            _channels.Add(podcast);
            FileStream fs = null;

            try
            {
                fs = new FileStream(_channelListFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                await JsonSerializer.SerializeAsync(fs, _channels);
            }
            catch (Exception)
            {
                _channels = new List <PodcastChannel>();
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Пример #8
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ApplicationDbContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicationDbContext> >()))
            {
                // Look for any episodes.
                if (context.PodcastEpisode.Any())
                {
                    return; // DB has been seeded
                }

                // add channels


                var channels = new PodcastChannel[]
                {
                    new PodcastChannel {
                        ChannelName = "The Joe Rogan Experience"
                    },
                    new PodcastChannel {
                        ChannelName = "The Tim Ferriss Show"
                    },
                    new PodcastChannel {
                        ChannelName = "Dan Carlin's Hardcore History"
                    }
                };

                foreach (PodcastChannel c in channels)
                {
                    context.PodcastChannel.Add(c);
                }
                context.SaveChanges();



                // add episodes

                var episodes = new PodcastEpisode[]
                {
                    new PodcastEpisode {
                        EpisodeName      = "#310 - Neil DeGrasse Tyson",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Joe Rogan Experience").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "#801 - Gary Johnson",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Joe Rogan Experience").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "#763 - Action Bronson",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Joe Rogan Experience").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Episode 1: Kevin Rose",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Tim Ferriss Show").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Episode 2: Joshua Waitzkin",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Tim Ferriss Show").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Ep. 14: Sam Harris, PhD - Spirituality, Neuroscienece, Meditation, and More",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "The Tim Ferriss Show").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Show 56 - King of Kings",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "Dan Carlin's Hardcore History").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Show 50 - Blueprint for Armageddon",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "Dan Carlin's Hardcore History").PodcastChannelId
                    },
                    new PodcastEpisode {
                        EpisodeName      = "Show 43 - Wrath of the Khans",
                        PodcastChannelId = channels.Single(s => s.ChannelName == "Dan Carlin's Hardcore History").PodcastChannelId
                    }
                };

                foreach (PodcastEpisode e in episodes)
                {
                    context.PodcastEpisode.Add(e);
                }
                context.SaveChanges();



                //   var products = new Product[]
                //   {
                //       new Product {
                //           Description = "Colorful throw pillows to liven up your home",
                //           ProductTypeId = productTypes.Single(s => s.Label == "Housewares").ProductTypeId,
                //           Title = "Throw Pillow",
                //           Price = 7.49,
                //           CustomerId = customers.Single(s => s.FirstName == "Tractor").CustomerId
                //       },
                //       new Product {
                //           Description = "A 2012 iPod Shuffle. Headphones are included. 16G capacity.",
                //           ProductTypeId = productTypes.Single(s => s.Label == "Electronics").ProductTypeId,
                //           Title = "iPod Shuffle",
                //           Price = 18.00,
                //           CustomerId = customers.Single(s => s.FirstName == "Steve").CustomerId
                //       },
                //       new Product {
                //           Description = "Stainless steel refrigerator. Three years old. Minor scratches.",
                //           ProductTypeId = productTypes.Single(s => s.Label == "Appliances").ProductTypeId,
                //           Title = "Samsung refrigerator",
                //           Price = 500.00,
                //           CustomerId = customers.Single(s => s.FirstName == "Carson").CustomerId
                //       }
                //   };

                //   foreach (Product i in products)
                //   {
                //       context.Product.Add(i);
                //   }
                //   context.SaveChanges();
            }
        }
Пример #9
0
 public async Task SubscribeToPodcast(PodcastChannel podcastChannel)
 {
     await _client.PostAsJsonAsync($"api/Podcast/NewChannels", podcastChannel);
 }
Пример #10
0
 public async Task NewChannels([FromBody] PodcastChannel podcast)
 {
     await _podcastStore.AddNewChannel(podcast);
 }