mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-15 04:11:47 +00:00
Apply clean up util to title + enrich prefixes
This commit is contained in:
@ -15,7 +15,7 @@ const ytdl = require("ytdl-core");
|
|||||||
const { triggerAction, triggerActionSync } = require("../utils");
|
const { triggerAction, triggerActionSync } = require("../utils");
|
||||||
const { ACTIONS, CHANNEL } = require("./actions.js");
|
const { ACTIONS, CHANNEL } = require("./actions.js");
|
||||||
const { getFolder, urlToJPG } = require("./utils");
|
const { getFolder, urlToJPG } = require("./utils");
|
||||||
const { cleanupArtistName } = require("../../providers/song-info");
|
const { cleanupName } = require("../../providers/song-info");
|
||||||
|
|
||||||
const { createFFmpeg } = FFmpeg;
|
const { createFFmpeg } = FFmpeg;
|
||||||
const ffmpeg = createFFmpeg({
|
const ffmpeg = createFFmpeg({
|
||||||
@ -40,7 +40,10 @@ const downloadVideoToMP3 = async (
|
|||||||
const { videoDetails } = await ytdl.getInfo(videoUrl);
|
const { videoDetails } = await ytdl.getInfo(videoUrl);
|
||||||
const thumbnails = videoDetails?.thumbnails;
|
const thumbnails = videoDetails?.thumbnails;
|
||||||
metadata = {
|
metadata = {
|
||||||
artist: videoDetails?.media?.artist || cleanupArtistName(videoDetails?.author?.name) || "",
|
artist:
|
||||||
|
videoDetails?.media?.artist ||
|
||||||
|
cleanupName(videoDetails?.author?.name) ||
|
||||||
|
"",
|
||||||
title: videoDetails?.media?.song || videoDetails?.title || "",
|
title: videoDetails?.media?.song || videoDetails?.title || "",
|
||||||
imageSrcYTPL: thumbnails ?
|
imageSrcYTPL: thumbnails ?
|
||||||
urlToJPG(thumbnails[thumbnails.length - 1].url, videoDetails?.videoId)
|
urlToJPG(thumbnails[thumbnails.length - 1].url, videoDetails?.videoId)
|
||||||
|
|||||||
@ -55,8 +55,9 @@ const songInfo = {
|
|||||||
|
|
||||||
const handleData = async (responseText, win) => {
|
const handleData = async (responseText, win) => {
|
||||||
let data = JSON.parse(responseText);
|
let data = JSON.parse(responseText);
|
||||||
songInfo.title = data?.videoDetails?.title;
|
songInfo.title = cleanupName(data?.videoDetails?.title);
|
||||||
songInfo.artist = await getArtist(win) || cleanupArtistName(data?.videoDetails?.author);
|
songInfo.artist =
|
||||||
|
(await getArtist(win)) || cleanupName(data?.videoDetails?.author);
|
||||||
songInfo.views = data?.videoDetails?.viewCount;
|
songInfo.views = data?.videoDetails?.viewCount;
|
||||||
songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url;
|
songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url;
|
||||||
songInfo.songDuration = data?.videoDetails?.lengthSeconds;
|
songInfo.songDuration = data?.videoDetails?.lengthSeconds;
|
||||||
@ -98,8 +99,15 @@ const registerProvider = (win) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const suffixesToRemove = [' - Topic', 'VEVO'];
|
const suffixesToRemove = [
|
||||||
function cleanupArtistName(artist) {
|
" - Topic",
|
||||||
|
"VEVO",
|
||||||
|
" (Performance Video)",
|
||||||
|
" (Official Music Video)",
|
||||||
|
" (Official Video)",
|
||||||
|
" (Clip officiel)",
|
||||||
|
];
|
||||||
|
function cleanupName(artist) {
|
||||||
if (!artist) {
|
if (!artist) {
|
||||||
return artist;
|
return artist;
|
||||||
}
|
}
|
||||||
@ -114,4 +122,4 @@ function cleanupArtistName(artist) {
|
|||||||
module.exports = registerCallback;
|
module.exports = registerCallback;
|
||||||
module.exports.setupSongInfo = registerProvider;
|
module.exports.setupSongInfo = registerProvider;
|
||||||
module.exports.getImage = getImage;
|
module.exports.getImage = getImage;
|
||||||
module.exports.cleanupArtistName = cleanupArtistName;
|
module.exports.cleanupName = cleanupName;
|
||||||
|
|||||||
Reference in New Issue
Block a user