mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
scrape artistName from playBar
This commit is contained in:
@ -28,6 +28,18 @@ const getPausedStatus = async (win) => {
|
||||
return !title.includes("-");
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
`
|
||||
)
|
||||
}
|
||||
|
||||
// Fill songInfo with empty values
|
||||
const songInfo = {
|
||||
title: "",
|
||||
@ -45,10 +57,7 @@ const songInfo = {
|
||||
const handleData = async (responseText, win) => {
|
||||
let data = JSON.parse(responseText);
|
||||
songInfo.title = data?.videoDetails?.title;
|
||||
songInfo.artist = data?.videoDetails?.author;
|
||||
if (songInfo.artist.endsWith(" - Topic")) {
|
||||
songInfo.artist = songInfo.artist.slice(0, -8);
|
||||
}
|
||||
songInfo.artist = await getArtist(win) || data?.videoDetails?.author;
|
||||
songInfo.views = data?.videoDetails?.viewCount;
|
||||
songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url;
|
||||
songInfo.songDuration = data?.videoDetails?.lengthSeconds;
|
||||
|
||||
Reference in New Issue
Block a user