create cleanupArtistName() in song-info

This commit is contained in:
Araxeus
2021-05-07 04:47:24 +03:00
parent 2d6e858e8f
commit 8b471c0772
5 changed files with 25 additions and 29 deletions

View File

@ -58,7 +58,7 @@ 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) || data?.videoDetails?.author;
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;