Beispiel #1
0
        public MediaItem(MediaRssItem item)
        {
            coreCategories = new List<SLMedia.Core.Category>();
            if (item.Categories != null)
                coreCategories.AddRange(item.Categories.OfType<MediaRSS.Category>().Select(c => new Core.Category { Name = c.Label }));

            this.Categories = item.Categories;
            this.Content = item.Content;
            this.Description = item.Description;
            this.Id = item.Id;
            this.Keywords = item.Keywords;
            this.Rating = item.Rating;
            this.Thumbnails = item.Thumbnails;
            this.Title = item.Title;
        }
 public PictureMediaItem(MediaRssItem item)
     : base(item)
 {
 }
        public static MediaRssItem FromFeedItem(SyndicationItem feedItem)
        {
            MediaRssItem item = new MediaRssItem();
            item.Id = item.Id;

            foreach (var extensions in feedItem.ElementExtensions)
            {
                if (extensions.OuterNamespace == MediaRssNamespace)
                {
                    if (extensions.OuterName == MediaGroup)
                    {
                        XElement groupNode = (XElement)XDocument.ReadFrom(extensions.GetReader());
                        item.Content = (from g in groupNode.Elements(XName.Get(MediaContent, MediaRssNamespace))
                                        select MediaRSS.Content.FromXml(g)).ToArray();
                    }
                    else if (extensions.OuterName == MediaContent)
                    {
                        XElement contentNode = (XElement)XDocument.ReadFrom(extensions.GetReader());
                        item.Content = new Content[] { MediaRSS.Content.FromXml(contentNode) };
                    }
                    else if (extensions.OuterName == MediaTitle)
                    {
                        XElement titleNode = (XElement)extensions.GetReader().GetXNode();

                        string type = titleNode.GetAttribute(ContentType) ?? PlainType;

                        if (type == HtmlType)
                            item.Title = HttpUtility.HtmlDecode(titleNode.Value);
                        else
                            item.Title = titleNode.Value;
                    }
                    else if (extensions.OuterName == MediaDescription)
                    {
                        XElement descriptionNode = (XElement)extensions.GetReader().GetXNode();

                        string type = descriptionNode.GetAttribute(ContentType) ?? PlainType;

                        if (type == HtmlType)
                            item.Description = HttpUtility.HtmlDecode(descriptionNode.Value);
                        else
                            item.Description = descriptionNode.Value;
                    }
                    else if (extensions.OuterName == MediaAdult)
                    {
                        item.Rating = new Rating { Scheme = Rating.RatingSchemeSimple, Value = Rating.SimpleRatingAdult };
                    }
                    else if (extensions.OuterName == MediaRating)
                    {
                        XElement rating = (XElement)extensions.GetReader().GetXNode();
                        item.Rating = new Rating { Scheme = rating.GetAttribute(MediaRatingAttributeScheme), Value = rating.Value };
                    }
                    else if (extensions.OuterName == MediaKeywords)
                    {
                        string keywords = extensions.GetReader().ReadInnerXml();

                        item.Keywords = (from kw in keywords.Split(',')
                                         select kw.Trim()).ToArray();

                    }
                    else if (extensions.OuterName == MediaThumbnail)
                    {
                        XElement thumbnail = (XElement)extensions.GetReader().GetXNode();
                        item.Thumbnails.Add(Thumbnail.FromXml(thumbnail));
                    }
                    else if (extensions.OuterName == MediaCategory)
                    {
                        XElement category = (XElement)extensions.GetReader().GetXNode();
                        item.Categories.Add(MediaRSS.Category.FromXml(category));
                    }

                    //MediaHash
                    //MediaCredit
                    //MediaPlayer
                    //MediaCopyright
                    //MediaText

                }
            }

            if (string.IsNullOrEmpty(item.Title) && feedItem.Title != null)
                item.Title = feedItem.Title.Text;

            if (string.IsNullOrEmpty(item.Description) && feedItem.Summary != null)
                item.Description = feedItem.Summary.Text;

            return item;
        }
        public static IMediaItem GetMediaItemFromRssItem(MediaRssItem item, string[] extensionsFilter)
        {
            item.Content = (from c in item.Content
                            let uri = new Uri(c.Url, UriKind.RelativeOrAbsolute)
                            where extensionsFilter.Contains(System.IO.Path.GetExtension(uri.LocalPath).ToLower())
                            select c).ToArray();
            var content = item.Content.FirstOrDefault();

            if (content == null)
                return null;

            if ((content.Medium.HasValue && content.Medium.Value == Medium.Video)
                || (content.Type != null && content.Type.StartsWith("video")))
                return new VideoMediaItem(item);

            if ((content.Medium.HasValue && content.Medium.Value == Medium.Image)
                || (content.Type != null && content.Type.StartsWith("image")))
                return new PictureMediaItem(item);

            return null;
        }
Beispiel #5
0
 public VideoMediaItem(MediaRssItem item)
     : base(item)
 {
 }