-
Notifications
You must be signed in to change notification settings - Fork 579
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
Downloader tweaks + taskbar progress bar #265
Changes from all commits
cceb453
2168cbc
a8ac2c3
3ea17e6
96a74f8
b3da77a
e46e7b7
3831e61
ccd320d
da3c709
6b88397
d7e4247
cf4bbf9
d2a5110
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,29 @@ const electron = require("electron"); | |
module.exports.getFolder = (customFolder) => | ||
customFolder || (electron.app || electron.remote.app).getPath("downloads"); | ||
module.exports.defaultMenuDownloadLabel = "Download playlist"; | ||
|
||
const orderedQualityList = ["maxresdefault", "hqdefault", "mqdefault", "sdddefault"]; | ||
module.exports.UrlToJPG = (imgUrl, videoId) => { | ||
if (!imgUrl || imgUrl.includes(".jpg")) return imgUrl; | ||
//it will almost never get further than hqdefault | ||
for (const quality of orderedQualityList) { | ||
if (imgUrl.includes(quality)) { | ||
return `https://img.youtube.com/vi/${videoId}/${quality}.jpg`; | ||
} | ||
} | ||
return `https://img.youtube.com/vi/${videoId}/default.jpg`; | ||
} | ||
Comment on lines
+7
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this function will 99.9% of the time: 0.1% chance (might even be 0%) This was mostly coded this way to 100% guarantee a jpg url output
|
||
|
||
module.exports.cropMaxWidth = (image) => { | ||
const imageSize = image.getSize(); | ||
// standart youtube artwork width with margins from both sides is 280 + 720 + 280 | ||
if (imageSize.width === 1280 && imageSize.height === 720) { | ||
return image.crop({ | ||
x: 280, | ||
y: 0, | ||
width: 720, | ||
height: 720 | ||
}); | ||
} | ||
return image; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,10 @@ const getPausedStatus = async (win) => { | |
}; | ||
|
||
const getArtist = async (win) => { | ||
return await win.webContents.executeJavaScript( | ||
` | ||
var bar = document.getElementsByClassName('subtitle ytmusic-player-bar')[0]; | ||
var artistName = (bar.getElementsByClassName('yt-formatted-string')[0]) || (bar.getElementsByClassName('byline ytmusic-player-bar')[0]); | ||
if (artistName) { | ||
artistName.textContent; | ||
} | ||
` | ||
); | ||
return await win.webContents.executeJavaScript(` | ||
document.querySelector(".subtitle.ytmusic-player-bar .yt-formatted-string") | ||
?.textContent | ||
`); | ||
} | ||
|
||
// Fill songInfo with empty values | ||
|
@@ -57,8 +52,8 @@ const songInfo = { | |
|
||
const handleData = async (responseText, win) => { | ||
let data = JSON.parse(responseText); | ||
songInfo.title = data.videoDetails?.media?.song || data?.videoDetails?.title; | ||
songInfo.artist = data.videoDetails?.media?.artist || await getArtist(win) || cleanupArtistName(data?.videoDetails?.author); | ||
Comment on lines
-60
to
-61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
songInfo.title = data?.videoDetails?.title; | ||
songInfo.artist = await getArtist(win) || cleanupArtistName(data?.videoDetails?.author); | ||
songInfo.views = data?.videoDetails?.viewCount; | ||
songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url; | ||
songInfo.songDuration = data?.videoDetails?.lengthSeconds; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: