VOOZH about

URL: https://www.nuget.org/packages/OEmbed/

⇱ NuGet Gallery | OEmbed 4.0.1




👁 Image
OEmbed 4.0.1

dotnet add package OEmbed --version 4.0.1
 
 
NuGet\Install-Package OEmbed -Version 4.0.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OEmbed" Version="4.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OEmbed" Version="4.0.1" />
 
Directory.Packages.props
<PackageReference Include="OEmbed" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OEmbed --version 4.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OEmbed, 4.0.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OEmbed@4.0.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OEmbed&version=4.0.1
 
Install as a Cake Addin
#tool nuget:?package=OEmbed&version=4.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

OEmbed

A simple oEmbed consumer library for .NET

Install

via NuGet:

PM> Install-Package OEmbed

DI extensions for Microsoft.Extensions.DependencyInjection:

PM> Install-Package OEmbed.Extensions.Microsoft.DependencyInjection

DI configuration

services.AddOEmbed();

// or

services.AddOEmbed(options =>
{
 options.EnableCache = true; // true by default
});

By default it's register all providers listed below:

  • CoubProvider
  • DeviantartProvider
  • FlickrProvider
  • GiphyProvider
  • GyazoProvider
  • ImgurProvider
  • KickstarterProvider
  • PinterestProvider
  • PixivProvider
  • RedditProvider
  • SoundcloudProvider
  • SpotifyProvider
  • TiktokProvider
  • TumblrProvider
  • TwitterProvider
  • VimeoProvider
  • YoutubeProvider

Additional providers can be added during configuration:

using HeyRed.OEmbed.Providers;

services.AddOEmbed()
 .ClearProviders() // remove all default providers
 .AddProvider<YoutubeProvider>()
 .AddProvider<VimeoProvider>()
 .Addprovider<ImgurProvider>();

// or with options
// NOTE: Some oembed providers defines additional parameters, so use "Parameters" option if you need them.
services.AddOEmbed()
 .ClearProviders() // remove all default providers
 .AddProvider<TwitterProvider>(options =>
 {
 options.Parameters = new Dictionary<string, string?>
 {
 ["theme"] = "dark"
 };
 })
 .AddProvider<FacebookProvider>(options =>
 {
 options.Parameters = new Dictionary<string, string?>
 {
 ["access_token"] = "app_id|token"
 };
 });

Additional providers:

  • FacebookProvider
  • InstagramProvider
  • AfreecatvProvider
  • AnnieMusicProvider
  • AudioboomProvider
  • AudiomackProvider
  • CodepenProvider
  • YandexMusicProvider
  • DeezerProvider
  • DailymotionProvider
  • RutubeProvider

Usage

  • Inject IOEmbedConsumer throught constructor injection.
  • Call one of RequestAsync() overloads.

For example:

using HeyRed.OEmbed.Abstractions;
using HeyRed.OEmbed.Models;

// Returns null if provider not found or HttpRequestException was thrown.
Video? result = await _oEmbedConsumer.RequestAsync<Video>("https://vimeo.com/22439234");

The result object is are similar to described in the spec

Models: Base, Link, Photo, Rich, Video

Basic request:

// Deserialize response based on provider preferences
var item = await _oEmbedConsumer.RequestAsync(url);

if (item is not null)
{
 if (item is Video) 
 {
 // work with video 
 }
 else if (item is Photo) 
 {
 // work with photo
 }
 else { //do something }
}

Caching

Configure cache options:

services.AddOEmbed().Configure<CacheOptions>(options =>
{
 options.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(30); // Default is 1 hour
});

By default cache is enabled and it's default implementation is just a wrapper around MemoryCache

You can write your own implementation of ICache and replace default cache during app configuration:

services.AddOEmbed().SetCache<DistributedRedisCache>();

Additional providers

An easy way to write your own provider is inheritance of ProviderBase record:

public record ExampleProvider : ProviderBase
{
 // "ProviderOptions" is optional, you can safely remove argument from constructor
 public ExampleProvider(ProviderOptions? options = default)
 {
 AddParameters(options?.Parameters);
 
 // The Provider registry is primarily using this to select right provider at first check.
 // NOTE: Add all the hosts that will be used in the schemes below.
 AddAllowedHosts(new[] { "example.com", "www.example.com" });
 
 AddScheme(
 // Simple regex without hostname, "^" and "$" asserts. 
 // If this Regex is match string url, then scheme used to build request.
 matcher: new RegexMatcher(@"/\S+"),
 
 // API endpoint for current scheme
 apiEndpoint: "http://example.com/oembed",
 
 // The response type provided by resource.
 resourceType: ResourceType.Rich);
 }
 }
 
 // (Optional) Primary API response format(default is JSON)
 public override ResponseFormat ResponseType => ResponseFormat.Xml;
}

License

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OEmbed:

Package Downloads
OEmbed.Extensions.Microsoft.DependencyInjection

OEmbed extensions for ASP.NET Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1 4,693 5/21/2025
4.0.0 13,669 1/22/2024
3.0.0 63,852 6/7/2023
2.0.1 1,624 10/28/2022
2.0.0 15,559 5/18/2022
1.6.1 1,359 4/1/2022
1.6.0 1,349 3/24/2022
1.5.0 1,323 3/23/2022
1.4.0 1,451 3/23/2022
1.3.0 1,322 3/21/2022
1.2.0 1,357 3/19/2022
1.1.0 1,357 3/18/2022
1.0.1 1,394 3/17/2022
1.0.0 1,359 3/17/2022