Skip to content

MusicBrainz: check for genre aliases in tag list #7228

Backlog

Description

@mrpapersonic

Some genres have multiple names. For example, power noise is also widely known as rhythmic noise. MusicBrainz implements these as tags with "associated genres": https://musicbrainz.org/tag/power%20noise https://musicbrainz.org/tag/rhythmic%20noise

Rhythmic noise is the clear winner here, largely because that's the name Discogs uses.

Currently I don't think there is an actual API to check whether a tag is a genre alias. MusicBrainz Taggregator uses this function:

  function checkForGenreAlias(tag){
      const cacheNamespace = "MusicBrainzTagGenre:";
      const cached = GM_getValue(cacheNamespace + tag);
      const cacheLifetimeDays = 90;
      if(cached){
          if(cached.isGenre){
              return Promise.resolve(cached.value);
          }else if(Date.now() - cached.date < (1000 * 60 * 60 * 24 * cacheLifetimeDays)){
              return Promise.resolve(cached.value);
          }
      }
      const mbUrl = "https://musicbrainz.org/tag/";
      return fetchAsHTML(mbUrl + tag)
          .then((html) => {
              let genre = html.querySelector("a[href^=\"/genre/\"]");
              if(genre){
                  GM_setValue(cacheNamespace + tag, { value: genre.textContent,
                                                      isGenre: true,
                                                      date: Date.now()});
                  return genre.textContent;
              }else {
                  GM_setValue(cacheNamespace + tag, { value: tag,
                                                      isGenre: false,
                                                      date: Date.now()});
                  return tag;
              }
          })
          .catch((error) => {
              console.error(error);
              return tag;
          });
  }

which is pretty nasty (parsing HTML is terrible), but works okay enough for this.

Goals

Resolve tags that are genre aliases to their original genre.

Anti-goals

Doing a request for each tag in each album would be very expensive. Thus, there should be a cache that stores each unknown tag's genre (or lack thereof) for at least the lifetime of the program.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    musicbrainz

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions