Under Settings > Import List > Advanced List, there’s an option to provide a List URL for a Custom List. What format would that need to be in?

  • shrugal@lemm.ee
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    10 months ago

    A JSON array that looks like this:

    [
        {"MusicBrainzId": <id>},
        {"MusicBrainzId": <id>},
        {"MusicBrainzId": <id>}
        ...
    ]
    

    I use it to fetch my Last.fm and ListenBrainz recommendations for example.

      • shrugal@lemm.ee
        link
        fedilink
        English
        arrow-up
        0
        ·
        8 months ago

        I have a custom import list that points to the following PHP script on a local webserver:

        $API_PLAYLISTS = "https://api.listenbrainz.org/1/user/%s/playlists/createdfor";
        $API_PLAYLIST = "https://api.listenbrainz.org/1/playlist/%s";
        
        $EXT_PLAYLIST = "https://musicbrainz.org/doc/jspf#playlist";
        $EXT_TRACK = "https://musicbrainz.org/doc/jspf#track";
        
        $TMPL_PLAYLIST = "https://listenbrainz.org/playlist/%s";
        
        $USERS = [
            '<musicbrainz-username>'
        ];
        
        $LISTS = [
            "weekly-exploration",
            "weekly-jam"
        ];
        
        try {
            $ids = [];
        
            foreach ($USERS as $user) {
                $lists = fetch(sprintf($API_PLAYLISTS, $user))?->playlists ?? [];
        
                foreach($lists as $list) {
                    $meta = $list->playlist->extension->{$EXT_PLAYLIST};
                    $type = $meta->additional_metadata->algorithm_metadata->source_patch;
        
                    if (!in_array($type, $LISTS)) continue;
        
                    list($mbid) = sscanf($list->playlist->identifier, $TMPL_PLAYLIST);
                    $songs = fetch(sprintf($API_PLAYLIST, $mbid))->playlist->track;
        
                    foreach ($songs as $song) {
                        $meta = $song->extension->{$EXT_TRACK};
        
                        foreach ($meta->additional_metadata->artists as $artist) {
                            $ids[$artist->artist_mbid] = true;
                        }
                    }
                }
            }
        
            json(array_map(fn ($id) => ['MusicBrainzId' => $id], array_keys($ids)));
        } catch (Throwable $e) {
            http_response_code(500);
            json(['error' => $e->getMessage()]);
        }
        
        // -- Util --
        
        function json($data)
        {
            header("Content-Type: application/json");
            echo json_encode($data);
        }
        
        function fetch($url)
        {
            return json_decode(file_get_contents($url));
        }
        

        It fetches my “weekly exploration” and “weekly jam” playlists, extracts the artists and returns a list of artist IDs for Lidarr to import.

        • tiburon@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          0
          ·
          8 months ago

          Thank you. Is there any chance you could share what the final output looks like?

          Trying to get our own script working and it would be nice to compare to a known good output

          • shrugal@lemm.ee
            link
            fedilink
            English
            arrow-up
            0
            ·
            8 months ago

            It’s a JSON array like the one I posted in the beginning, so: [{"MusicBrainzId":<artist1-id>},{"MusicBrainzId":<artist2-id>},...].

            • tiburon@lemmy.blahaj.zone
              link
              fedilink
              English
              arrow-up
              0
              ·
              8 months ago

              Ok, one last question, does this mean you are watching the entire artist? What I’m trying to do is watch a specific release/release group via the list, not the entire artist, and I can’t work out the format the custom list is expecting for that

        • drangus@lemmy.ca
          link
          fedilink
          English
          arrow-up
          0
          ·
          8 months ago

          This is awesome, thanks! I’ve deployed the script on a basic local nginx docker container with PHP enabled but the Lidarr list import service only seems to be importing the first result. Did you run into that issue during your development?

          Seems the documentation around the custom list is non-existent. Here’s the sample output from my page:

          [ { "MusicBrainzId": "9f81247f-7f57-42f3-a8ba-75bef554e591" }, { "MusicBrainzId": "0ae49abe-d6af-44fa-8ab0-b9ace5690e6f" }, { "MusicBrainzId": "3b910f7b-018f-408f-950b-47e02d2ce305" } ]

          • shrugal@lemm.ee
            link
            fedilink
            English
            arrow-up
            0
            ·
            8 months ago

            Hmm no, I think it works correclty. I get log entries like Import List Sync Completed. Items found: 61, Artists added: 0, Albums added: 0, which suggests to me that it processes more than just one result entry.