Added buffer to scrobblers.
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
const axios = require("axios");
|
||||
const Scrobbler = require("./scrobbler");
|
||||
|
||||
class MalojaScrobbler {
|
||||
class MalojaScrobbler extends Scrobbler {
|
||||
#config = null;
|
||||
#counter = 0;
|
||||
|
||||
constructor(config) {
|
||||
constructor(config, logger) {
|
||||
super(logger);
|
||||
this.#config = config;
|
||||
|
||||
if (!config.name)
|
||||
@ -12,7 +14,7 @@ class MalojaScrobbler {
|
||||
if (!config.url)
|
||||
throw new Error(`Invalid url for Maloja scrobbler '${this.name}'.`);
|
||||
if (!config.token)
|
||||
throw new Error(`Invalid token for Maloja scrobbler '${this.name}'.`)
|
||||
throw new Error(`Invalid token for Maloja scrobbler '${this.name}'.`);
|
||||
}
|
||||
|
||||
get counter() {
|
||||
@ -27,6 +29,7 @@ class MalojaScrobbler {
|
||||
const url = new URL(this.#config.url);
|
||||
url.pathname += "/apis/mlj_1/newscrobble";
|
||||
url.search = "?key=" + this.#config.token;
|
||||
|
||||
await axios.post(url.toString(), {
|
||||
title: song.name,
|
||||
album: song.album,
|
||||
|
31
services/scrobblers/scrobbler.js
Normal file
31
services/scrobblers/scrobbler.js
Normal file
@ -0,0 +1,31 @@
|
||||
const { Queue } = require("async-await-queue");
|
||||
|
||||
class Scrobbler {
|
||||
#queue = null;
|
||||
#logger = null;
|
||||
|
||||
constructor(logger) {
|
||||
this.#queue = new Queue(1, 300);
|
||||
this.#logger = logger;
|
||||
}
|
||||
|
||||
async queue(media, duration, start) {
|
||||
const id = Symbol();
|
||||
|
||||
try {
|
||||
await this.#queue.wait(id, 0);
|
||||
|
||||
await this.scrobble(media, duration, start);
|
||||
} catch (ex) {
|
||||
this.#logger.console.error(media, "Failed to scrobble: " + ex.message);
|
||||
} finally {
|
||||
this.#queue.end(id, duration, start);
|
||||
}
|
||||
}
|
||||
|
||||
async scrobble(media, duration, start) {
|
||||
console.log("This should not be running, ever.");
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Scrobbler;
|
Reference in New Issue
Block a user