コード例 #1
0
ファイル: RSSFeed.cs プロジェクト: purplecow/Media-Browser
        private static IEnumerable<BaseItem> GetChildren(SyndicationFeed feed) {
            if (feed == null) yield break;

            foreach (var item in feed.Items) {
                VodCastVideo video = new VodCastVideo();
                video.DateCreated = item.PublishDate.UtcDateTime;
                video.DateModified = item.PublishDate.UtcDateTime;
                video.Name = item.Title.Text;

                // itunes podcasts sometimes don't have a summary 
                if (item.Summary != null && item.Summary.Text != null) {
                    video.Overview = Regex.Replace(item.Summary.Text, @"<(.|\n)*?>", string.Empty);

                    var match = Regex.Match(item.Summary.Text, @"<img src=[\""\']([^\'\""]+)", RegexOptions.IgnoreCase);
                    if (match != null && match.Groups.Count > 1) {
                        video.PrimaryImagePath = match.Groups[1].Value;
                    }
                }

                foreach (var link in item.Links) {
                    if (link.RelationshipType == "enclosure") {
                        video.Path = (link.Uri.AbsoluteUri);
                    }
                }
                if (video.Path != null) {
                    video.Id = video.Path.GetMD5();
                    yield return video;
                }

            }
        }
コード例 #2
0
        private static IEnumerable<BaseItem> GetChildren(SyndicationFeed feed) {
            var videos = new List<BaseItem>();
            
            if (feed == null) return videos;

            foreach (var item in feed.Items) {
                VodCastVideo video = new VodCastVideo();
                video.DateCreated = item.PublishDate.UtcDateTime;
                video.DateModified = item.PublishDate.UtcDateTime;
                video.Name = item.Title.Text;

                // itunes podcasts sometimes don't have a summary 
                if (item.Summary != null && item.Summary.Text != null) {
                    video.Overview = Regex.Replace(item.Summary.Text, @"<(.|\n)*?>", string.Empty);

                    var match = Regex.Match(item.Summary.Text, @"<img src=[\""\']([^\'\""]+)", RegexOptions.IgnoreCase);
                    if (match != null && match.Groups.Count > 1) {
                        video.PrimaryImagePath = match.Groups[1].Value;
                    }
                }

                foreach (var link in item.Links) {
                    if (link.RelationshipType == "enclosure")
                    {
                        video.Path = (link.Uri.AbsoluteUri);
                    }
                }

                foreach (var extension in item.ElementExtensions.Where(e => e.OuterNamespace == "http://search.yahoo.com/mrss/" && e.OuterName == "thumbnail"))
                {
                    var attr = extension.GetObject<XElement>();
                    if (attr != null)
                    {
                        var url = attr.Attribute("url");
                        if (url != null)
                        {
                            video.PrimaryImagePath = url.Value;
                        }
                    }
                
                }

                if (video.Path != null)
                {
                    video.Id = video.Path.GetMD5();
                    videos.Add(video);
                }
            }

            // TED Talks appends the same damn string on each title, fix it
            if (videos.Count > 5)
            {
                string common = videos[0].Name;

                foreach (var video in videos.Skip(1))
                {
                    while (!video.Name.StartsWith(common))
                    {
                        if (common.Length < 2)
                        {
                            break;
                        }
                        common = common.Substring(0, common.Length - 1);
                    }

                    if (common.Length < 2)
                    {
                        break;
                    }
                }
                
                if (common.Length > 2)
                {
                    foreach (var video in videos)
                    {
                        if (video.Name.Length > common.Length)
                        {
                            video.Name = video.Name.Substring(common.Length);
                        }
                    }
                }

            }

            return videos;
        }