Skip to content

A library for searching for youtube videos or youtube music

License

Notifications You must be signed in to change notification settings

madeyoga/YoutubeSearchApi.Net

Repository files navigation

YoutubeSearchApi.Net

CodeFactor Grade Nuget contributionswelcome discord_invite

A lightweight & simple .NET library to extract data from Youtube. The purpose of this project is to make it easier for developers to extract data from YouTube or any sources.

Supported Sites

  • Youtube
  • Youtube Music

Installation

NuGet

Quick Start

Youtube Search

using YoutubeSearchApi.Net.Models.Youtube;
using YoutubeSearchApi.Net.Services;

public static async Task AsyncMain()
{
    using (var httpClient = new HttpClient())
    {
        YoutubeSearchClient client = new YoutubeSearchClient(httpClient);

        var responseObject = await client.SearchAsync("black suit");

        foreach (YoutubeVideo video in responseObject.Results)
        {
            Console.WriteLine(video.ToString());
            Console.WriteLine("");
        }
    }
}

public static void Main(string[] args)
{
    AsyncMain().GetAwaiter().GetResult();
}

Youtube Music Search

using YoutubeSearchApi.Net.Models.Youtube;
using YoutubeSearchApi.Net.Services;

public static async Task AsyncMain()
{
    using (var httpClient = new HttpClient())
    {
        YoutubeMusicSearchClient client = new YoutubeMusicSearchClient(httpClient);

        var responseObject = await client.SearchAsync("simple ringtone");

        foreach (YoutubeVideo video in responseObject.Results)
        {
            Console.WriteLine(video.ToString());
            Console.WriteLine("");
        }
    }
}

public static void Main(string[] args)
{
    AsyncMain().GetAwaiter().GetResult();
}

Full examples at Demo project

Using Service Collection

services.AddHttpClient<YoutubeSearchClient>();
services.AddHttpClient<YoutubeMusicSearchClient>();


// MyController.cs

private readonly YoutubeSearchClient ytClient;
private readonly YoutubeMusicSearchClient ytmClient;

public MyController(YoutubeSearchClient ytClient, YoutubeMusicSearchClient ytmClient)
{
    this.ytClient = ytClient;
    this.ytmClient = ytmClient;
}

Contributing

Issues and Pull requests are very welcome. Feel free to open issues and pull requests.