Skip to content

Commit

Permalink
scrape artistName from playBar
Browse files Browse the repository at this point in the history
  • Loading branch information
Araxeus committed Apr 15, 2021
1 parent a2207a2 commit f765fb6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions providers/song-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand All @@ -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;
Expand Down

0 comments on commit f765fb6

Please sign in to comment.