From c66ff2bf0564722b7054db101ca80099318ee07a Mon Sep 17 00:00:00 2001 From: TC Date: Mon, 23 Aug 2021 00:49:00 +0200 Subject: [PATCH] Apply clean up util to title + enrich prefixes --- plugins/downloader/youtube-dl.js | 7 +++++-- providers/song-info.js | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index f0f47cec..906fc35c 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -15,7 +15,7 @@ const ytdl = require("ytdl-core"); const { triggerAction, triggerActionSync } = require("../utils"); const { ACTIONS, CHANNEL } = require("./actions.js"); const { getFolder, urlToJPG } = require("./utils"); -const { cleanupArtistName } = require("../../providers/song-info"); +const { cleanupName } = require("../../providers/song-info"); const { createFFmpeg } = FFmpeg; const ffmpeg = createFFmpeg({ @@ -40,7 +40,10 @@ const downloadVideoToMP3 = async ( const { videoDetails } = await ytdl.getInfo(videoUrl); const thumbnails = videoDetails?.thumbnails; metadata = { - artist: videoDetails?.media?.artist || cleanupArtistName(videoDetails?.author?.name) || "", + artist: + videoDetails?.media?.artist || + cleanupName(videoDetails?.author?.name) || + "", title: videoDetails?.media?.song || videoDetails?.title || "", imageSrcYTPL: thumbnails ? urlToJPG(thumbnails[thumbnails.length - 1].url, videoDetails?.videoId) diff --git a/providers/song-info.js b/providers/song-info.js index 08eaf944..0ef0f868 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -55,8 +55,9 @@ const songInfo = { const handleData = async (responseText, win) => { let data = JSON.parse(responseText); - songInfo.title = data?.videoDetails?.title; - songInfo.artist = await getArtist(win) || cleanupArtistName(data?.videoDetails?.author); + songInfo.title = cleanupName(data?.videoDetails?.title); + songInfo.artist = + (await getArtist(win)) || cleanupName(data?.videoDetails?.author); songInfo.views = data?.videoDetails?.viewCount; songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url; songInfo.songDuration = data?.videoDetails?.lengthSeconds; @@ -98,8 +99,15 @@ const registerProvider = (win) => { }); }; -const suffixesToRemove = [' - Topic', 'VEVO']; -function cleanupArtistName(artist) { +const suffixesToRemove = [ + " - Topic", + "VEVO", + " (Performance Video)", + " (Official Music Video)", + " (Official Video)", + " (Clip officiel)", +]; +function cleanupName(artist) { if (!artist) { return artist; } @@ -114,4 +122,4 @@ function cleanupArtistName(artist) { module.exports = registerCallback; module.exports.setupSongInfo = registerProvider; module.exports.getImage = getImage; -module.exports.cleanupArtistName = cleanupArtistName; +module.exports.cleanupName = cleanupName;