fix(multi-scrobbler): randomize User-Agent, enable ListenBrainz album art via Cover Art Archive

- Replace hardcoded User-Agent with random pick from 8 browser UAs to avoid rate limiting
- Uncomment Cover Art Archive URL in ListenBrainzService so album thumbnails appear on actual Discord RPC (not just the preview)
- Remove unused ListenBrainzResponse and ListenBrainzPlayingNowResponse interfaces
This commit is contained in:
kmmiio99o 2026-07-08 12:42:09 +02:00
parent 28958a79af
commit 5d5364b3e6
No known key found for this signature in database
GPG key ID: AC9D7747D423B9BF
2 changed files with 15 additions and 18 deletions

View file

@ -2,6 +2,17 @@ import { ServiceClient, Track } from "../../../defs";
import Constants from "../constants"; import Constants from "../constants";
import { incrementApiCall, recordServiceError } from "../utils/debug"; import { incrementApiCall, recordServiceError } from "../utils/debug";
const USER_AGENTS = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64; rv:127.0) Gecko/20100101 Firefox/127.0",
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1",
];
export abstract class BaseService implements ServiceClient { export abstract class BaseService implements ServiceClient {
protected retryCount = 0; protected retryCount = 0;
protected lastError = 0; protected lastError = 0;
@ -54,7 +65,7 @@ export abstract class BaseService implements ServiceClient {
const response = await fetch(url, { const response = await fetch(url, {
...options, ...options,
headers: { headers: {
"User-Agent": "Vendetta Multi-Service Scrobbler/3.0.0", "User-Agent": USER_AGENTS[Math.floor(Math.random() * USER_AGENTS.length)],
...options.headers, ...options.headers,
}, },
}); });

View file

@ -3,11 +3,6 @@ import { currentSettings } from "..";
import Constants from "../constants"; import Constants from "../constants";
import { BaseService } from "./BaseService"; import { BaseService } from "./BaseService";
interface ListenBrainzResponse {
listens?: ListenBrainzListen[];
error?: string;
}
interface ListenBrainzListen { interface ListenBrainzListen {
listened_at: number; listened_at: number;
track_metadata: { track_metadata: {
@ -32,10 +27,6 @@ interface ListenBrainzListen {
playing_now?: boolean; playing_now?: boolean;
} }
interface ListenBrainzPlayingNowResponse {
listens: ListenBrainzListen[];
}
export class ListenBrainzService extends BaseService { export class ListenBrainzService extends BaseService {
getServiceName(): string { getServiceName(): string {
return "ListenBrainz"; return "ListenBrainz";
@ -179,15 +170,10 @@ export class ListenBrainzService extends BaseService {
} }
} }
// Try to get album art from MusicBrainz or other sources // Try to get album art from Cover Art Archive
const albumArt: string | null = null; let albumArt: string | null = null;
if (latestListen.track_metadata.additional_info?.release_mbid) { if (latestListen.track_metadata.additional_info?.release_mbid) {
try { albumArt = `https://coverartarchive.org/release/${latestListen.track_metadata.additional_info.release_mbid}/front`;
// We could fetch cover art from Cover Art Archive, but for now we'll leave it null
// albumArt = `https://coverartarchive.org/release/${latestListen.track_metadata.additional_info.release_mbid}/front`;
} catch (error) {
this.logVerbose("Failed to fetch album art:", error);
}
} }
const track: Track = { const track: Track = {