Skip to content

Latest commit

 

History

History
101 lines (75 loc) · 3.89 KB

README.md

File metadata and controls

101 lines (75 loc) · 3.89 KB

MelonChart.NET NuGet Version NuGet Downloads

This is the Melon chart scraping library written in .NET - Top 100, Hot 100, Daily 100, Weekly 100 and Monthly 100

Prerequisites

Getting Started

  1. Install the NuGet package of this library.

    dotnet add package MelonChart.NET

    You may need to run the following command to install Playwright dependencies.

    pwsh bin/Debug/net8.0/playwright.ps1 install
  2. Use the library in your code.

    var chart = new Top100Chart();
    var collection = await chart.GetChartAsync();
    foreach (var item in collection.Items)
    {
        Console.WriteLine($"{item.Rank} - {item.Title} by {item.Artist}");
    }
  3. If you want to get the Hot 100 chart, use the Hot100Chart class.

    var chart = new Hot100Chart();
    var collection = await chart.GetChartAsync();
    foreach (var item in collection.Items)
    {
        Console.WriteLine($"{item.Rank} - {item.Title} by {item.Artist}");
    }
  4. You can also register all the charts and get the chart by the type.

    var builder = WebApplication.CreateBuilder(args);
    builder.Services.AddKeyedScoped<IChart, Top100Chart>(ChartTypes.Top100);
    builder.Services.AddKeyedScoped<IChart, Hot100Chart>(ChartTypes.Hot100);
    builder.Services.AddKeyedScoped<IChart, Daily100Chart>(ChartTypes.Daily100);
    builder.Services.AddKeyedScoped<IChart, Weekly100Chart>(ChartTypes.Weekly100);
    builder.Services.AddKeyedScoped<IChart, Monthly100Chart>(ChartTypes.Monthly100);
    
    var app = builder.Build();
    
    app.MapGet("/top100", async ([FromKeyedServices(ChartTypes.Top100)] IChart chart) =>
    {
        var collection = await chart.GetChartAsync();
        return Results.Json(collection.Items);
    });
    
    app.MapGet("/hot100", async ([FromKeyedServices(ChartTypes.Hot100)] IChart chart) =>
    {
        var collection = await chart.GetChartAsync();
        return Results.Json(collection.Items);
    });
    
    app.MapGet("/daily100", async ([FromKeyedServices(ChartTypes.Daily100)] IChart chart) =>
    {
        var collection = await chart.GetChartAsync();
        return Results.Json(collection.Items);
    });
    
    app.MapGet("/weekly100", async ([FromKeyedServices(ChartTypes.Weekly100)] IChart chart) =>
    {
        var collection = await chart.GetChartAsync();
        return Results.Json(collection.Items);
    });
    
    app.MapGet("/monthly100", async ([FromKeyedServices(ChartTypes.Monthly100)] IChart chart) =>
    {
        var collection = await chart.GetChartAsync();
        return Results.Json(collection.Items);
    });

Samples

There are some samples in the samples directory.

MelonChart on Spotify

There's a playlist on Spotify using this library. If you want to sync the Melon chart to Spotify up-to-date, create a sync request, and it will automatically update the playlist.

Melon Chart on Spotify

Issues?

If you find any issues, please report them.