Merge pull request #252 from Araxeus/fix-download-idtag-if-not-playing

Fix downloader metadata if not currently playing
This commit is contained in:
th-ch
2021-05-07 23:11:10 +02:00
committed by GitHub
9 changed files with 145 additions and 56 deletions

View File

@ -38,7 +38,7 @@ const getArtist = async (win) => {
artistName.textContent;
}
`
)
);
}
// Fill songInfo with empty values
@ -57,8 +57,8 @@ const songInfo = {
const handleData = async (responseText, win) => {
let data = JSON.parse(responseText);
songInfo.title = data?.videoDetails?.title;
songInfo.artist = await getArtist(win) || data?.videoDetails?.author;
songInfo.title = data.videoDetails?.media?.song || data?.videoDetails?.title;
songInfo.artist = data.videoDetails?.media?.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;
@ -102,5 +102,20 @@ const registerProvider = (win) => {
return registerCallback;
};
const suffixesToRemove = [' - Topic', 'VEVO'];
function cleanupArtistName(artist) {
if (!artist) {
return artist;
}
for (const suffix of suffixesToRemove) {
if (artist.endsWith(suffix)) {
return artist.slice(0, -suffix.length);
}
}
return artist;
}
module.exports = registerProvider;
module.exports.getImage = getImage;
module.exports.cleanupArtistName = cleanupArtistName;