Nibble

Embedding third party media in Umbraco

Since Umbraco v4.9 embedding third party media in the RTE has gotten a lot easier, it’ just a matter of supplying the Url to the video/image/sound/poll/… you want to add setting the size and hitting insert!

image

This is done by making use of the oembed format so every site that support the format can be supported by the dialog in a minute  (if it isn’t already) Smile

All this is setup in the new config file /config/EmbeddedMedia.config, for each supported third party site there is an entry in the config file

  <!-- Youtube Settings -->
  <provider name="Youtube" type="Umbraco.Web.Media.EmbedProviders.OEmbedVideo, umbraco">
    <urlShemeRegex><![CDATA[youtu(?:\.be|be\.com)/(?:(.*)v(/|=)|(.*/)?)([a-zA-Z0-9-_]+)]]></urlShemeRegex>
    <apiEndpoint><![CDATA[http://www.youtube.com/oembed]]></apiEndpoint>
    <requestParams type="Umbraco.Web.Media.EmbedProviders.Settings.Dictionary, umbraco">
      <param name="iframe">1</param>
      <param name="format">xml</param>
    </requestParams>
  </provider>

The provider that needs to be used (most of the time it’s oembed), a regex that will match the supported urls, the api endpount for the oembed stuff and some optional request params if needed.

So if a third party site supports oembed and isn’t supported by the insert third party media dialog yet it’s just a case if adding an entry to the config file

But the implementation isn’t fixed to oembed it’s also possible to plug in custom providers that don’t make use of the oembed format

Look at the following entry for twitgoo

  <!-- Twitgoo Settings , not an OEmbed one -->
  <provider name="Twitgoo" type="Umbraco.Web.Media.EmbedProviders.Twitgoo, umbraco">
    <urlShemeRegex><![CDATA[twitgoo\.com/]]></urlShemeRegex>
  </provider>

That makes use of a custom provider that looks like

using HtmlAgilityPack;
 
namespace Umbraco.Web.Media.EmbedProviders
{
    public class Twitgoo : AbstractProvider
    {
        public override bool SupportsDimensions
        {
            get
            {
                return false;
            }
        }
 
        public override string GetMarkup(string url, int maxWidth, int maxHeight)
        {
            var web = new HtmlWeb();
            var doc = web.Load(url);
 
            var img = doc.DocumentNode.SelectSingleNode("//img [@id = ‘fullsize’]").Attributes["src"];
 
            return string.Format("<img src=\"{0}\"/>",
               img.Value);
        }
    }
}

Which will basically search for the element with id full-size and return an image using the src attribute of the full-size element found.

So you can also write your own providers for sites you wish to support Smile

4 Comments so far

  1. Bjørn Fridal on October 24th, 2012

    Great Tim. Its really neat to see useful features like this directly in Umbraco. Even though several packages for this already exists, supporting Oembed out of the box, will be quite handy.

    Cheers
    Bjørn

  2. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do
    it for you? Plz answer back as I’m looking to create my own blog and would
    like to find out where u got this from. many thanks

    Also visit my webpage :: riot points gratuit, riotpointsgeneratorgratuit.blogspot.fr,

  3. nadruki na koszulki on August 31st, 2014

    nadruki na koszulki
    holiday deals
    religious organizations
    university of northern colorado
    csaa
    donating a car
    provillus

  4. Carl on September 1st, 2014

    Its not my first time to go to see this web page,
    i am browsing this site dailly and take nice data from here
    every day.

Leave a Reply