public ActionResult Embed(string url = null) { if (string.IsNullOrEmpty(url)) { // for testing // twitter //url = "https://twitter.com/SHAQ/status/661263631045238784"; // youtube url = "https://www.youtube.com/watch?v=xjS6SftYQaQ"; // imgur video gallery url = "http://imgur.com/gallery/p3MmC"; } var provider = _providerResolver.Resolve(url); if (provider == null) { throw new Exception("The url has no provider that can handle it."); } var result = provider.LocalEmbed(url); if (result == null) { throw new Exception("Couldn't get the embedded result from the provider."); } return(View("Providers/" + provider.Name, result)); }
public ActionResult Query(string url) { if (string.IsNullOrEmpty(url)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Bad request")); } var provider = _providerResolver.Resolve(url); if (provider == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound, "No providers found for the given url")); } var embed = provider.Embed(url); var result = new OEmbedJsonResult { Type = embed.Type, Version = embed.Version, Title = embed.Title, AuthorName = embed.AuthorName, AuthorUrl = embed.AuthorUrl, ProviderName = embed.ProviderName, ProviderUrl = embed.ProviderUrl, CacheAge = embed.CacheAge, ThumbnailUrl = embed.ThumbnailUrl, ThumbnailWidth = embed.ThumbnailWidth, ThumbnailHeight = embed.ThumbnailHeight }; if (embed is IPhotoEmbeddedResult) { result.Url = ((IPhotoEmbeddedResult)embed).Url; result.Width = ((IPhotoEmbeddedResult)embed).Width; result.Height = ((IPhotoEmbeddedResult)embed).Height; } else if (embed is IVideoEmbeddedResult) { result.Html = ((IVideoEmbeddedResult)embed).Html; result.Width = ((IVideoEmbeddedResult)embed).Width; result.Height = ((IVideoEmbeddedResult)embed).Height; } else if (embed is IRichEmbeddedResult) { result.Html = ((IRichEmbeddedResult)embed).Html; result.Width = ((IRichEmbeddedResult)embed).Width; result.Height = ((IRichEmbeddedResult)embed).Height; } return(Content(JsonConvert.SerializeObject(result), "application/json")); }
public ActionResult Embed(string url = null) { if (string.IsNullOrEmpty(url)) { throw new Exception("No url provided"); } var provider = _providerResolver.Resolve(url); if (provider == null) { throw new Exception("The url has no provider that can handle it."); } var result = provider.LocalEmbed(url); if (result == null) { throw new Exception("Couldn't get the embedded result from the provider."); } return(View("Providers/" + provider.Name, result)); }