Giter Site home page Giter Site logo

Comments (7)

wo80 avatar wo80 commented on July 29, 2024

This can be done using a browse request:

private static async Task BrowseReleaseGroups()
{
    // Britney Spears
    var arid = "45a663b5-b1cb-4a91-bff6-2bef7bbfdd76";

    int limit = 50;

    var groups = await ReleaseGroup.BrowseAsync("artist", arid, limit, 0, "ratings");

    Console.WriteLine("Album");
    Console.WriteLine();

    foreach (var item in groups.Items.Where(g => IsOffical(g)).OrderBy(g => g.FirstReleaseDate))
    {
        Console.WriteLine("     {0} - {1}  {2}  {3}", item.FirstReleaseDate.ToShortDate(),
            item.Id, GetRating(item.Rating, 10), item.Title);
    }

    Console.WriteLine();
    Console.WriteLine("Album + Compilation");
    Console.WriteLine();

    foreach (var item in groups.Items.Where(g => IsCompilation(g)).OrderBy(g => g.FirstReleaseDate))
    {
        Console.WriteLine("     {0} - {1}  {2}  {3}", item.FirstReleaseDate.ToShortDate(),
            item.Id, GetRating(item.Rating, 10), item.Title);
    }

    Console.WriteLine();

    if (groups.Items.Count == limit)
    {
        Console.WriteLine("There are probably more items to browse ...");
    }
}

static bool IsOffical(ReleaseGroup g)
{
    return g.PrimaryType.Equals("album", StringComparison.OrdinalIgnoreCase)
        && g.SecondaryTypes.Count == 0
        && !string.IsNullOrEmpty(g.FirstReleaseDate);
}

static bool IsCompilation(ReleaseGroup g)
{
    return g.PrimaryType.Equals("album", StringComparison.OrdinalIgnoreCase)
        && g.SecondaryTypes.Count > 0
        && g.SecondaryTypes.Contains("Compilation")
        && !string.IsNullOrEmpty(g.FirstReleaseDate);
}

static string GetRating(Rating rating, int length)
{
    string s = "";

    if (!rating.Value.HasValue)
    {
        return s.PadRight(length);
    }

    int stars = (int)(length * (double)rating.Value / 5.0);

    s = s.PadRight(stars, '+');

    return s.PadRight(length, '-');
}

from musicbrainz.

ColorTwist avatar ColorTwist commented on July 29, 2024

Awesome! This is helpful!
Pity it wont include some sort of popularity factor for each album.

from musicbrainz.

wo80 avatar wo80 commented on July 29, 2024

Sure you can!

var groups = await ReleaseGroup.BrowseAsync("artist", arid, limit, 0, "ratings");

I've updated the code above to show the rating.

from musicbrainz.

ColorTwist avatar ColorTwist commented on July 29, 2024

I tried that, the function returns 'null' :(

from musicbrainz.

wo80 avatar wo80 commented on July 29, 2024

EDIT: Sorry, this is a change, I haven't committed yet. In Rating.cs, change

public double Value { get; set; }

to

public double? Value { get; set; }

Please leave this issue open, until it's fixed.


The updated code example works well for me. Since the rating value returned by the webservice might be null, the C# equivalent rating.Value is a nullable type (meaning, you have to check, if the value is present).

from musicbrainz.

ColorTwist avatar ColorTwist commented on July 29, 2024

Sure, i also Verified that nullable type operates correctly.

from musicbrainz.

ColorTwist avatar ColorTwist commented on July 29, 2024

Verified, fixed that Rating value can be nullable.

from musicbrainz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.