public async Task <PodcastEnclosureViewModel> ParseRssFeed(string url) { var rss = await FeedReader.ReadAsync(url); if (rss.Type == FeedType.Rss_2_0) { var feed = (CodeHollow.FeedReader.Feeds.Rss20Feed)rss.SpecificFeed; var podcastFeed = rss.GetItunesChannel(); var ret = new PodcastEnclosureViewModel { Title = feed.Title, Description = feed.Description, Author = podcastFeed.Author, Category = feed.Categories.Join("\n"), Link = feed.Link, Image = feed.Image.Link ?? podcastFeed.Image.Href, PublishDate = feed.PublishingDateString, Language = feed.Language, Copyright = feed.Copyright, Owner = podcastFeed.Owner.Name, OwnerEmail = podcastFeed.Owner.Email, Items = feed.Items .Cast <Rss20FeedItem>() .Select(item => new PodcastEnclosureItemViewModel { Uid = item.Guid, Title = item.Title, Description = item.Description, Author = item.Author ?? "", UpdateDate = item.PublishingDateString, AudioUrl = item.Enclosure.Url, // Duration = item.Id, }).ToList() }; return(ret); } throw new InvalidOperationException("This is not a podcast RSS feed."); }
public async Task <IActionResult> Get(string userSlug, string podcastSlug) { var user = await _userManager.FindBySlugAsync(userSlug); if (user is null) { //check if we have a redirect in place var redirect = await _redirectsRepository .GetAll() .Where(r => r.OldSlug == userSlug) .FirstOrDefaultAsync(); if (redirect is null) { return(NotFound()); } user = await _userManager.FindByIdAsync(redirect.ApplicationUserId.ToString()); if (user is null) { return(NotFound()); } var url = Flurl.Url.Combine(_appSettings.RssUrl, user.Slug, podcastSlug); return(Redirect(url)); } var podcast = await _podcastRepository.GetForUserAndSlugAsync(userSlug, podcastSlug); if (podcast is null) { return(NotFound()); } try { var xml = await ResourceReader.ReadResource("podcast.xml"); var template = Handlebars.Compile(xml); var compiled = new PodcastEnclosureViewModel { Title = podcast.Title, Description = podcast.Description.RemoveUnwantedHtmlTags(), Author = "PodNoms Podcasts", Image = podcast.GetRawImageUrl(_storageOptions.CdnUrl, _imageStorageOptions.ContainerName), Link = $"{_appSettings.PagesUrl}/{user.Slug}/{podcast.Slug}", PublishDate = podcast.CreateDate.ToRFC822String(), Category = podcast.Category?.Description, Language = "en-IE", Copyright = $"© {DateTime.Now.Year} PodNoms RSS", Owner = $"{user.FirstName} {user.LastName}", OwnerEmail = user.Email, ShowUrl = Flurl.Url.Combine(_appSettings.RssUrl, user.Slug, podcast.Slug), Items = ( from e in podcast.PodcastEntries select new PodcastEnclosureItemViewModel { Title = e.Title.StripNonXmlChars().RemoveUnwantedHtmlTags(), Uid = e.Id.ToString(), Summary = e.Description.StripNonXmlChars().RemoveUnwantedHtmlTags(), Description = e.Description.StripNonXmlChars(), Author = e.Author.StripNonXmlChars().Truncate(252, true), EntryImage = e.GetImageUrl(_storageOptions.CdnUrl, _imageStorageOptions.ContainerName), UpdateDate = e.CreateDate.ToRFC822String(), AudioUrl = e.GetRssAudioUrl(_appSettings.AudioUrl), AudioDuration = TimeSpan.FromSeconds(e.AudioLength).ToString(@"hh\:mm\:ss"), AudioFileSize = e.AudioFileSize } ).ToList() }; var result = template(compiled); return(Content(result, "application/xml", Encoding.UTF8)); } catch (NullReferenceException ex) { _logger.LogError(ex, "Error getting RSS", user, userSlug); } return(NotFound()); }