Skip to content

Commit

Permalink
fix unsupported hidden webp coverart
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Jun 9, 2021
1 parent 3485d26 commit 8eb3827
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions providers/song-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ const progressSelector = "#progress-bar";
// Grab the progress using the selector
const getProgress = async (win) => {
// Get current value of the progressbar element
const elapsedSeconds = await win.webContents.executeJavaScript(
return win.webContents.executeJavaScript(
'document.querySelector("' + progressSelector + '").value'
);

return elapsedSeconds;
};

// Grab the native image using the src
const getImage = async (src) => {
const result = await fetch(src);
const buffer = await result.buffer();
return nativeImage.createFromBuffer(buffer);
const output = nativeImage.createFromBuffer(buffer);
if (output.isEmpty() && !src.endsWith(".jpg") && src.includes(".jpg")) { // fix hidden webp files (https://github.com/th-ch/youtube-music/issues/315)
return getImage(src.slice(0, src.lastIndexOf(".jpg")+4));
} else {
return output;
}
};

// To find the paused status, we check if the title contains `-`
Expand All @@ -30,7 +33,7 @@ const getPausedStatus = async (win) => {
};

const getArtist = async (win) => {
return await win.webContents.executeJavaScript(`
return win.webContents.executeJavaScript(`
document.querySelector(".subtitle.ytmusic-player-bar .yt-formatted-string")
?.textContent
`);
Expand Down Expand Up @@ -112,4 +115,3 @@ module.exports = registerCallback;
module.exports.setupSongInfo = registerProvider;
module.exports.getImage = getImage;
module.exports.cleanupArtistName = cleanupArtistName;

0 comments on commit 8eb3827

Please sign in to comment.