-
Notifications
You must be signed in to change notification settings - Fork 576
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
Downloader tweaks + taskbar progress bar #265
Conversation
+ Get the best possible artwork
(it never exists in the XHR responce)
songInfo.title = data.videoDetails?.media?.song || data?.videoDetails?.title; | ||
songInfo.artist = data.videoDetails?.media?.artist || await getArtist(win) || cleanupArtistName(data?.videoDetails?.author); |
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.
videoDetails.media
can only appear in data parsed from ytpl.getInfo()
(never from XHR, I shouldn't have added it here in the first place)
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`; | ||
} |
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.
this function will 99.9% of the time:
return a maxresdefault
webp converted to jpg (quite frequent with newer videos)
or return the original url (is jpg)
0.1% chance (might even be 0%)
to do more than 1 iteration over qualityList (will only happen if original doesn't contains .jpg
or maxresdefault
)
This was mostly coded this way to 100% guarantee a jpg url output
note that this function is only applicable to thumbnails from
ytpl.getInfo
and not fromXMLHttpRequest
(song-info provider), since they are stored in a different source and in completely different formats
@@ -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) => { |
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:
module.exports.UrlToJPG = (imgUrl, videoId) => { | |
module.exports.urlToJPG = (imgUrl, videoId) => { |
Just a nit but nothing blocking, otherwise looks good, thanks for the improvement, merging! ✅ |
youtube-music/plugins/downloader/back.js
Lines 51 to 56 in 6b88397
UrlToJPG
+cropMaxWidth
(in downloader/utils)(
UrlToJPG
is needed becausevideoDetails?.thumbnails[-1]
is not always presented in jpg format (webp throw errors) + can be of different sizes. so this function guarantee the highest resolution of artwork)(
cropMaxWidth
gets pixel perfect cropping for official music artwork, without it the artwork usually have just big margins filled with solid color)youtube-music/plugins/downloader/front.js
Lines 44 to 47 in a8ac2c3