Skip to content

Commit

Permalink
Add option for custom ListenBrainz API URL
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiNtD committed Oct 19, 2024
1 parent 6df6c3c commit 86cc48d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ disableOnPresence:
- Apple Music
# lastFmApiKey: ""
# discordClientId: ""
# listenBrainzAPIURL: http://localhost:8100
1 change: 1 addition & 0 deletions src/config/V4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export default v.object({

lastFmApiKey: v.optional(v.string()),
discordClientId: v.optional(v.string()),
listenBrainzAPIURL: v.optional(v.string()),
});
23 changes: 10 additions & 13 deletions src/listenProvider/listenbrainz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ListenProvider, Track } from "./index.ts";
import * as Time from "../lib/time.ts";

const api = axios.create({
baseURL: "https://api.listenbrainz.org/1/",
baseURL: config.listenBrainzAPIURL || "https://api.listenbrainz.org",
headers: { "User-Agent": "https://github.com/RuiNtD/lastfm-rp" },
});
const log = getLogger(
Expand Down Expand Up @@ -45,18 +45,15 @@ async function _lookup(
album?: string,
): Promise<Lookup | undefined> {
try {
const { data } = await api.get(
`https://api.listenbrainz.org/1/metadata/lookup/`,
{
params: {
recording_name: track,
artist_name: artist,
release_name: album,
inc: "release",
metadata: true,
},
const { data } = await api.get("/1/metadata/lookup/", {
params: {
recording_name: track,
artist_name: artist,
release_name: album,
inc: "release",
metadata: true,
},
);
});
return v.parse(Lookup, data);
} catch (e) {
if (e instanceof AxiosError) log.error(chalk.red("Error"), e.message);
Expand All @@ -82,7 +79,7 @@ const LBPlayingAPI = v.object({

async function _getListening(): Promise<Track | undefined | null> {
try {
const { data } = await api.get(`/user/${username}/playing-now`);
const { data } = await api.get(`/1/user/${username}/playing-now`);
log.trace("listenbrainz playing now", data);

const resp = v.parse(LBPlayingAPI, data);
Expand Down

0 comments on commit 86cc48d

Please sign in to comment.