From 1b0cf7c2b366053d4925aebee1ead73934691b7a Mon Sep 17 00:00:00 2001 From: Wizzard <25581244+Wizzard@users.noreply.toomuchslop.com> Date: Mon, 16 Oct 2023 20:30:46 -0400 Subject: [PATCH] Made handling of bar changing nicer, high quality images --- main.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.js b/main.js index 9a73c26..43d9329 100644 --- a/main.js +++ b/main.js @@ -3,10 +3,13 @@ const sharp = require('sharp'); const rp = require('request-promise'); const fs = require('fs'); const { exec } = require('child_process'); +const crypto = require('crypto'); const config = JSON.parse(fs.readFileSync("config.json")); const updateInterval = 5000; +let previousHash = null; + async function processAlbumCover(url) { try { console.log(`Processing album cover from URL: ${url}`); @@ -114,8 +117,21 @@ async function fetchCurrentScrobble(user) { } } + if (coverURL && coverURL.includes('300x300')) { + coverURL = coverURL.replace('300x300', '1000x1000'); + } + if (coverURL) { const { outputBuffer, dominantColor } = await processAlbumCover(coverURL); + + const hash = crypto.createHash('sha256').update(outputBuffer).digest('hex'); + if (hash === previousHash) { + console.log("Image is the same as before. Skipping updates."); + return; + } + + previousHash = hash; + await setAsWallpaper(outputBuffer, dominantColor); console.log("Successfully fetched current scrobble."); return { outputBuffer, dominantColor };