Пример #1
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Returns itself if this is a valid audio content item
        /// </summary>
        /// <returns>RssMediaContent object</returns>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public RssMediaContent GetIfAudioItem()
        {
            RssMediaContent rt = null;


            bool bRslt = false;

            // test the medium.  if it is image, set things to true
            if (RSS.IsMediumEqual("audio", medium))
            {
                bRslt = true;
            }

            // if the result of the last operation is false, then
            // test the mime type of the image.  If it is an image mime type, then
            // set to true.
            if (!bRslt)
            {
                if (RSS.IsAudioMimeType(type))
                {
                    bRslt = true;
                }
            }

            // if we still don't know if it is an image, then
            // lets test the extension.  NOTE, extension might not be in the list.
            // if not, then the feed creator should specify the medium or the mime type.
            // only check if medium not specified.
            if (!bRslt)
            {
                if (medium.Length == 0 && type.Length == 0)
                {
                    if (RSS.IsVideoUrl(url))
                    {
                        bRslt = true;
                    }
                }
            }

            if (bRslt)
            {
                rt = this;
            }
            return(rt);
        }
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Creates a RSSMediaContent object from a RssCoreItemEnclosure object
        /// </summary>
        /// <param name="enc">RSSItemEnclosure</param>
        /// <returns>RSSMediaContent</returns>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public RssMediaContent CreateMediaContentItemFromEnclosure(RssCoreItemEnclosure enc)
        {
            RssMediaContent rt = new RssMediaContent();
            rt.url = enc.url;
            rt.type = enc.type;

            if (RSS.IsImageMimeType(enc.type))
            {
                rt.medium = RSS.MEDIUM_TYPE_IMAGE;
            }
            else if (RSS.IsVideoMimeType(enc.type))
            {
                rt.medium = RSS.MEDIUM_TYPE_VIDEO;
            }
            else if (RSS.IsAudioMimeType(enc.type))
            {
                rt.medium = RSS.MEDIUM_TYPE_AUDIO;
            }

            return rt;
        }
Пример #3
0
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        /// <summary>
        /// This returns the effective image.  It either returns self (this) or null if it doesn't meet the specified
        /// criteria.
        /// </summary>
        /// <param name="item_type">image, audio, document, etc.</param>
        /// <param name="item_mime">Type>Mime Type</param>
        /// <param name="minWidth">Minimum Width</param>
        /// <param name="maxWidth">Maximum Width</param>
        /// <param name="minHeight">Minimum Width</param>
        /// <param name="maxHeight">Maximum Width</param>
        /// <returns>RssMediaContent object</returns>
        // -------------------------------------------------------------------------------
        // -------------------------------------------------------------------------------
        public RssMediaContent GetIfImageItem(string item_mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0)
        {
            RssMediaContent rt = null;

            string tmp1 = "";
            string tmp2 = "";

            bool bRslt = false;

            if (RSS.IsMediumEqual(RSS.MEDIUM_TYPE_IMAGE, medium))
            {
                bRslt = true;
            }


            // if the result of the last operation is false, then
            // test the mime type of the image.  If it is an image mime type, then
            // set to true.
            if (!bRslt)
            {
                if (RSS.IsImageMimeType(type))
                {
                    bRslt = true;
                }
            }

            // if we still don't know if it is an image, then
            // lets test the extension.  NOTE, extension might not be in the list.
            // if not, then the feed creator should specify the medium or the mime type.
            if (!bRslt && medium.Length == 0 && type.Length == 0)
            {
                if (RSS.IsImageUrl(url))
                {
                    bRslt = true;
                }
            }



            // test mime type
            if (bRslt)
            {
                if (item_mimeType.Length > 0)
                {
                    tmp1 = type.ToLower();
                    tmp2 = item_mimeType.ToLower();
                    if (string.Compare(tmp1, tmp2) != 0)
                    {
                        bRslt = false;
                    }
                }
            }

            // min width test
            if (bRslt)
            {
                if (minWidth > 0)
                {
                    if (width < minWidth)
                    {
                        bRslt = false;
                    }
                }
            }


            // max width test
            if (bRslt)
            {
                if (maxWidth > 0)
                {
                    if (width > maxWidth)
                    {
                        bRslt = false;
                    }
                }
            }

            // min height
            if (bRslt)
            {
                if (minHeight > 0)
                {
                    if (height < minHeight)
                    {
                        bRslt = false;
                    }
                }
            }

            // max height
            if (bRslt)
            {
                if (maxHeight > 0)
                {
                    if (height > maxHeight)
                    {
                        bRslt = false;
                    }
                }
            }

            // if there are no errors, then return the self
            if (bRslt)
            {
                rt = this;
            }

            return(rt);
        }