Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hidden webp thumbnail throwing MIME type error in downloader #318

Merged
merged 2 commits into from
Jun 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/downloader/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ function handle(win) {
{ ...nowPlayingMetadata, ...currentMetadata };

try {
const coverBuffer = songMetadata.image ? songMetadata.image.toPNG() : null;
const coverBuffer = songMetadata.image && !songMetadata.image.isEmpty() ?
songMetadata.image.toPNG() : null;

const writer = new ID3Writer(songBuffer);

// Create the metadata tags
Expand Down
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;