Пример #1
0
 public string GetPercent(Episode e)
 {
     return($"{(int)((ListenProgress / e.Duration.TotalMilliseconds) * 100)}%");
 }
Пример #2
0
 public EpisodePlaybackState(Episode episode)
 {
     this.Id         = Guid.NewGuid();
     this.EpisodeKey = episode?.Key;
 }
Пример #3
0
 public double GetPercentDouble(Episode e)
 {
     return((ListenProgress / e.Duration.TotalMilliseconds) * 100);
 }
Пример #4
0
        internal static List <Episode> ParseRssFeed(IInputStream stream, Feed parent)
        {
            List <Episode> results = new List <Episode>();

            XNamespace ns     = "http://purl.org/rss/1.0/";
            XNamespace mrss   = "http://search.yahoo.com/mrss/";
            XNamespace itunes = "http://www.itunes.com/dtds/podcast-1.0.dtd";
            var        media  = mrss.GetName("media");

            XDocument xdoc = XDocument.Load(stream.AsStreamForRead());

            var items = xdoc.Descendants("item");

            foreach (var item in items)
            {
                string     thumbUri = string.Empty;
                XAttribute mediadownload;

                var            pubDateStr = item.Element("pubDate")?.Value;
                DateTimeOffset pubDate    = DateTimeOffset.MinValue;
                if (!string.IsNullOrEmpty(pubDateStr))
                {
                    pubDate = DateTimeHelper.ParseDateTimeRFC822(pubDateStr);
                }

                var      durationStr = item.Element(itunes + "duration")?.Value;
                TimeSpan duration    = TimeSpan.MinValue;
                if (!string.IsNullOrEmpty(durationStr) && durationStr.Contains(":"))
                {
                    duration = TimeSpan.Parse(durationStr);
                }
#pragma warning disable SA1108                                                             // Block statements must not contain embedded comments
                else if (!string.IsNullOrEmpty(durationStr) && !durationStr.Contains(":")) // channel9
#pragma warning restore SA1108                                                             // Block statements must not contain embedded comments
                {
                    duration = TimeSpan.FromSeconds(Convert.ToInt32(durationStr));
                }

                var subtitleStr = item.Element(itunes + "subtitle")?.Value;

                if (string.IsNullOrEmpty(subtitleStr))
                {
                    var cats = item.Elements("category");
                    if (cats != null && cats.Count() > 0)
                    {
                        StringBuilder sb = new StringBuilder();
                        cats.ToList().ForEach(f => { sb.Append($"{f.Value} "); });
                        subtitleStr = sb.ToString();
                    }
                }

                var desc    = item.Element("description");
                var content = item.Elements(mrss + "content").FirstOrDefault();
                if (content != null)
                {
                    mediadownload = content.Attribute("url");
                    var thumbnailElement = content.Element(mrss + "thumbnail");
                    if (thumbnailElement != null)
                    {
                        var thumbnail = thumbnailElement.Attribute("url");
                        thumbUri = thumbnail.Value;
                    }
                }
                else
                {
                    var      thumbnailElements = item.Elements(mrss + "thumbnail");
                    XElement thumbElement      = null;
                    if (thumbnailElements.Count() >= 4)
                    {
                        thumbElement = thumbnailElements.ElementAt(3);
                    }
                    else if (thumbnailElements.Count() >= 1)
                    {
                        thumbElement = thumbnailElements.ElementAt(0);
                    }

                    if (thumbElement != null)
                    {
                        thumbUri = thumbElement.Attribute("url").Value;
                    }

                    var      mediaGroup       = item.Elements(mrss + "group");
                    var      mediaUriElements = mediaGroup.Elements(mrss + "content");
                    XElement mediaUriElement  = null;
                    if (mediaUriElements.Count() >= 4)
                    {
                        mediaUriElement = mediaUriElements.ElementAt(3);
                    }

                    if (mediaUriElements.Count() == 1)
                    {
                        mediaUriElement = mediaUriElements.ElementAt(0);
                    }

                    mediadownload = mediaUriElement?.Attribute("url");
                }

                if (mediadownload == null)
                {
                    var mediadownloadElements = item.Element("enclosure");
                    mediadownload = mediadownloadElements?.Attribute("url");
                }

                if (mediadownload != null)
                {
                    var feed = new Episode(
                        title: item.Element("title").Value,
                        description: desc.Value,
                        key: mediadownload.Value,
                        itemThumbnail: thumbUri,
                        feed: parent,
                        publishDate: pubDate,
                        duration: duration,
                        subtitle: subtitleStr);
                    results.Add(feed);
                }
                else
                {
                    Debug.WriteLine($"Skipping");
                }
            }

            return(results);
        }