Made handling of bar changing nicer, high quality images

This commit is contained in:
Wizzard 2023-10-16 20:30:46 -04:00
parent 62285d572b
commit 1b0cf7c2b3
1 changed files with 16 additions and 0 deletions

16
main.js
View File

@ -3,10 +3,13 @@ const sharp = require('sharp');
const rp = require('request-promise'); const rp = require('request-promise');
const fs = require('fs'); const fs = require('fs');
const { exec } = require('child_process'); const { exec } = require('child_process');
const crypto = require('crypto');
const config = JSON.parse(fs.readFileSync("config.json")); const config = JSON.parse(fs.readFileSync("config.json"));
const updateInterval = 5000; const updateInterval = 5000;
let previousHash = null;
async function processAlbumCover(url) { async function processAlbumCover(url) {
try { try {
console.log(`Processing album cover from URL: ${url}`); 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) { if (coverURL) {
const { outputBuffer, dominantColor } = await processAlbumCover(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); await setAsWallpaper(outputBuffer, dominantColor);
console.log("Successfully fetched current scrobble."); console.log("Successfully fetched current scrobble.");
return { outputBuffer, dominantColor }; return { outputBuffer, dominantColor };