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 };