Compare commits
No commits in common. "ad624172a612b1e7941055032574916148dcb5e7" and "3112a29bb3ee30d5fe3c3a38b22e45c06c96cdad" have entirely different histories.
ad624172a6
...
3112a29bb3
@ -1,12 +1,4 @@
|
||||
const pino = require("pino");
|
||||
const logger = pino(pino.destination({ dest: 'logs/.log', sync: false }));
|
||||
|
||||
const environment = process.env.NODE_ENV || 'development';
|
||||
console.log(process.env.NODE_ENV);
|
||||
if (environment == "production") {
|
||||
logger.level = 30
|
||||
} else {
|
||||
logger.level = 20
|
||||
}
|
||||
|
||||
module.exports = logger;
|
@ -21,15 +21,27 @@ async function poll() {
|
||||
const previous = lastPlaying[current.sessionKey];
|
||||
lastPlaying[current.sessionKey] = current;
|
||||
if (previous == null) {
|
||||
logger.info(current, "A new session has started.");
|
||||
continue;
|
||||
}
|
||||
|
||||
let filters = [];
|
||||
if (previous.source == 'plex')
|
||||
filters = config.scrobble.plex.filters;
|
||||
|
||||
if (!applyFilter(previous, filters)) {
|
||||
logger.debug(previous, 'No filters got triggered. Ignoring.');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!previous) {
|
||||
logger.info(current, "A new session has started.");
|
||||
} else {
|
||||
if (checkIfCanScrobble(current, previous, now)) {
|
||||
logger.info(previous, "Scrobble");
|
||||
lastScrobbleTimes[previous.mediaKey] = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scrobble then remove lingering sessions
|
||||
for (let key in lastPlaying) {
|
||||
@ -65,29 +77,20 @@ function applyFilter(track, filters) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkIfCanScrobble(current, previous, now) {
|
||||
if (!previous)
|
||||
function checkIfCanScrobble(current, last, now) {
|
||||
if (!last)
|
||||
return;
|
||||
|
||||
let filters = [];
|
||||
if (previous.source == 'plex')
|
||||
filters = config.scrobble.plex.filters;
|
||||
|
||||
if (!applyFilter(previous, filters)) {
|
||||
logger.debug(previous, 'No filters got triggered. Ignoring.');
|
||||
return false;
|
||||
}
|
||||
|
||||
const scrobbleDuration = isInt(config.scrobble.minimum.duration) ? Number(config.scrobble.minimum.duration) : 30;
|
||||
const scrobblePercent = isInt(config.scrobble.minimum.percent) ? Number(config.scrobble.minimum.percent) : 30;
|
||||
|
||||
if (previous) {
|
||||
const newPlayback = current == null || current.playtime < previous.playtime;
|
||||
const canBeScrobbled = previous.playtime > scrobbleDuration * 1000 || previous.playtime / previous.duration > scrobblePercent;
|
||||
if (last) {
|
||||
const newPlayback = current == null || current.playtime < last.playtime;
|
||||
const canBeScrobbled = last.playtime > scrobbleDuration * 1000 || last.playtime / last.duration > scrobblePercent;
|
||||
|
||||
if (newPlayback && canBeScrobbled) {
|
||||
const sameSong = current != null && current.mediaKey == previous.mediaKey;
|
||||
const lastTime = lastScrobbleTimes[previous.mediaKey];
|
||||
const sameSong = current != null && current.mediaKey == last.mediaKey;
|
||||
const lastTime = lastScrobbleTimes[last.mediaKey];
|
||||
return !sameSong || !lastTime || now - lastTime > scrobbleDuration;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user