Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/listenbrainz/mod.ts>ListenBrainzClient

Deno library and CLI to access the ListenBrainz API
Latest
class ListenBrainzClient
import { ListenBrainzClient } from "https://deno.land/x/listenbrainz@v0.8.1/mod.ts";

ListenBrainz API client to submit listens and request data.

You have to specify a user token which you can obtain from your settings.

Examples

Example 1

const client = new ListenBrainzClient({ userToken: Deno.env.get("LB_TOKEN") });
await client.playingNow({ artist_name: "John Doe", track_name: "Love Song" });

Constructors

new
ListenBrainzClient(options: ClientOptions)

Properties

apiBaseUrl: string

Base URL of the ListenBrainz API endpoints.

maxRetries: number

Maximum number of times a failed request is repeated.

Methods

Deletes a particular listen from a user’s listen history.

The listen is not deleted immediately, but is scheduled for deletion, which usually happens shortly after the hour.

get(endpoint: string, query?: Query<string | number>): Promise<any>

Fetches JSON data from the given GET endpoint.

This method should only be directly called for unsupported endpoints.

getListenCount(userName: string): Promise<number>

Gets the number of listens for the given user.

getListens(userName: string, options?: LimitOptions): Promise<UserListens>

Gets listens for the given user.

If no options are given, the most recent listens will be returned. The optional max_ts and min_ts timestamps control at which point in time to start or stop returning listens. Listens are always returned in descending timestamp order.

getPlayingNow(userName: string): Promise<UserPlayingNow>

Gets the listen being played right now for the given user.

import(listens: Listen[])

Imports the given listens.

listen(track: Track, listenedAt: number)

Submits a listen for the given track.

Submits a playing now notification for the given track.

post(endpoint: string, json: any): Promise<any>

Sends the given JSON data to the given POST endpoint.

This method should only be directly called for unsupported endpoints.

searchUsers(searchTerm: string): Promise<string[]>

Searches a ListenBrainz-registered user and returns a list of names.

validateToken(): Promise<string | false>

Checks whether the client’s user token is valid.