// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets the media content items that meet the criteria /// </summary> /// <param name="obj">IRssMEdiaContent object</param> /// <param name="mimeType">Mime Type</param> /// <param name="minWidth">Minimun Width</param> /// <param name="maxWidth">Maximum width</param> /// <param name="minHeight">Minimum Height</param> /// <param name="maxHeight">Maximun Height</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public IEnumerable<RssMediaContent> GetImageItems(IRssMediaContent obj, string mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0, bool ExitAfterOneFound = false) { List<RssMediaContent> rt = new List<RssMediaContent>(); bool TestMimeType = mimeType.Length > 0 ? true : false; StringComparer cmp = StringComparer.OrdinalIgnoreCase; // loop through each content item getting the ones that match the criteria for (int i = 0; i < obj.mediaContentItems.Count; i++) { RssMediaContent rslt = obj.mediaContentItems[i].GetIfImageItem(mimeType, minWidth, maxWidth, minHeight, maxHeight); if (rslt != null) { rt.Add(rslt); if (ExitAfterOneFound) { break; } } } // next media content item return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Loads the media group properties with the content of the XElement /// </summary> /// <param name="parEl">XElement</param> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public void Load(XElement parEl) { if (parEl.Name.Namespace == RSS.MEDIA_NS || parEl.Name.Namespace == RSS.DUBLIN_CORE_TERMS_NS || parEl.Name.Namespace == RSS.GEORSS_NS || parEl.Name.Namespace == RSS.GML_NS) { IEnumerable <XElement> lst = parEl.Elements(); foreach (XElement el in lst) { switch (el.Name.LocalName) { case TAG_MEDIACONTENT: RssMediaContent mc = new RssMediaContent(this); mc.Load(el); mediaContentItems.Add(mc); break; // load the media options if any exist for the media group element default: mediaOptions.LoadEl(el); break; } } } }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets a single image /// </summary> /// <param name="obj">IRssMEdiaContent object</param> /// <param name="mimeType">Mime Type</param> /// <param name="minWidth">Minimun Width</param> /// <param name="maxWidth">Maximum width</param> /// <param name="minHeight">Minimum Height</param> /// <param name="maxHeight">Maximun Height</param> /// <returns>RssMediaContent</returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetImageItem(IRssMediaContent obj, string mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0) { RssMediaContent rt = null; IEnumerable<RssMediaContent> lst = GetImageItems(obj, mimeType, minWidth, maxWidth, minHeight, maxHeight, true); if (lst.Count() > 0) { rt = lst.First(); } return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Returns self if medium or mimetype matches the properties of this item /// </summary> /// <param name="mediumX">medium</param> /// <param name="mimeTypeX">Mime Type</param> /// <returns>RssMediaContent</returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetIfMediumOrMimeType(string mediumX = "", string mimeTypeX = "") { RssMediaContent rt = null; string med = mediumX.ToLower(); string mtype = mimeTypeX.ToLower(); bool mediumTest = med.Length > 0 ? true : false; bool mimeTypeTest = mtype.Length > 0 ? true : false; bool bRslt = false; if (bRslt) { if (mediumTest) { if (string.Compare(med, medium) == 0) { bRslt = true; } } } if (!bRslt) { if (mimeTypeTest) { if (string.Compare(mtype, type) == 0) { bRslt = true; } } } if (!bRslt) { if (!mediumTest && !mimeTypeTest) { bRslt = true; } } if (bRslt) { rt = this; } return(rt); }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Gets the media content items /// </summary> /// <param name="obj">IRssMediaContent object</param> /// <param name="medium">medium, resource type</param> /// <param name="mimeType">mime type</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetFirstContentItem(IRssMediaContent obj, string medium = "", string mimeType = "") { RssMediaContent rt = null; // get the content items in a list. Should only be one. IEnumerable<RssMediaContent> lst = GetContentItems(obj, medium, mimeType, ExitAfterOneFound: true); // if the list count is greater than zero if (lst.Count() > 0) { // get the first one....the only one. rt = lst.First(); } return rt; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <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> /// Gets the first image that meets the criteria /// </summary> /// <param name="mimeType">Mime Type</param> /// <param name="minWidth">Minimun Width</param> /// <param name="maxWidth">Maximum width</param> /// <param name="minHeight">Minimum Height</param> /// <param name="maxHeight">Maximun Height</param> /// <returns>IEnumerable<RssMediaContent></returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetImageItem(string mimeType = "", int minWidth = 0, int maxWidth = 0, int minHeight = 0, int maxHeight = 0) { RssMediaContent rt = rssUtil.GetImageItem(this, mimeType, minWidth, maxWidth, minHeight, maxHeight); if (rt == null) { for (int i = 0; i < mediaGroups.Count; i++) { rt = rssUtil.GetImageItem(mediaGroups[i], mimeType, minWidth, maxWidth, minHeight, maxHeight); if (rt != null) { break; } } } 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; }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// THis returns the effective image for the item. If the enclosure is found, it returns that in the form of a /// RSSMediaContent object. Otherwise, it searches the tree downwards looking for a media content item. /// </summary> /// <returns>RssMediaContent</returns> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public RssMediaContent GetFirstContentItem(string medium, string mimeType = "", bool IncludeEnclosures = true) { RssMediaContent rt = null; if (IncludeEnclosures) { // try and get an image enclosure RssCoreItemEnclosure enc = base.GetFirstEnclosure(medium, mimeType); // if we got an enclosure, good, set the return and we will fall through if (enc != null) { rt = rssUtil.CreateMediaContentItemFromEnclosure(enc); } } // if no enclosures, search the media content items if (rt == null) { rt = rssUtil.GetFirstContentItem(this, medium, mimeType); // none found in current content items, lets look to the content groupings if (rt == null) { for (int i = 0; i < mediaGroups.Count; i++) { rt = rssUtil.GetFirstContentItem(mediaGroups[i], medium, mimeType); if (rt != null) { break; } } } } return(rt); }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Adds a Media Content Item to the Items collection /// </summary> /// <param name="contentItem"></param> // ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- public void AddMediaContentItem(RssMediaContent contentItem) { contentItem.Parent = this; mediaContentItems.Add(contentItem); }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <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); }
// ------------------------------------------------------------------------------- // ------------------------------------------------------------------------------- /// <summary> /// Loads the RssItem object from the XElement /// </summary> /// <param name="el">Current Element</param> private new void LoadEl(XElement el) { // if the el is a core element, load from the base if (el.Name.Namespace == XNamespace.None) { base.LoadEl(el); } // if the el is in the media namespace or the dublin core terms namespace, load what we know. else if (el.Name.Namespace == RSS.MEDIA_NS || el.Name.Namespace == RSS.DUBLIN_CORE_TERMS_NS) { switch (el.Name.LocalName) { case RssMediaGroup.TAG_PARENT: RssMediaGroup mediaGroup = new RssMediaGroup(this); mediaGroup.Load(el); mediaGroups.Add(mediaGroup); break; case RssMediaContent.TAG_PARENT: RssMediaContent mediaContent = new RssMediaContent(this); mediaContent.Load(el); mediaContentItems.Add(mediaContent); break; default: mediaOptions.LoadEl(el); break; } } // if the element is in the DublinCoreNS, load what we know else if (el.Name.Namespace == RSS.DUBLIN_CORE_NS) { switch (el.Name.LocalName) { case RssDublinCoreCreator.TAG_PARENT: RssDublinCoreCreator creator = new RssDublinCoreCreator(); creator.Load(el); creators.Add(creator); break; } } // is the element in the Content Namespace, if so, process it else if (el.Name.Namespace == RSS.CONTENT_NS) { switch (el.Name.LocalName) { case RssContentEncoded.TAG_PARENT: ContentEncoded = new RssContentEncoded(); ContentEncoded.Load(el); break; } } else if (el.Name.Namespace == RSS.SLASH_NS) { switch (el.Name.LocalName) { case RssSlashComments.TAG_PARENT: SlashComments = new RssSlashComments(); SlashComments.Load(el); break; } } else if (el.Name.Namespace == RSS.CREATIVE_COMMONS_NS) { switch (el.Name.LocalName) { case RssCreativeCommonsLicense.TAG_PARENT: CreativeCommonsLicense = new RssCreativeCommonsLicense(); CreativeCommonsLicense.Load(el); break; } } }