mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
create cleanupArtistName() in song-info
This commit is contained in:
@ -41,7 +41,6 @@ const defaultConfig = {
|
|||||||
api_root: "http://ws.audioscrobbler.com/2.0/",
|
api_root: "http://ws.audioscrobbler.com/2.0/",
|
||||||
api_key: "04d76faaac8726e60988e14c105d421a", // api key registered by @semvis123
|
api_key: "04d76faaac8726e60988e14c105d421a", // api key registered by @semvis123
|
||||||
secret: "a5d2a36fdf64819290f6982481eaffa2",
|
secret: "a5d2a36fdf64819290f6982481eaffa2",
|
||||||
suffixesToRemove: [' - Topic', 'VEVO'] // removes suffixes of the artist name, for better recognition
|
|
||||||
},
|
},
|
||||||
discord: {
|
discord: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
@ -16,7 +16,7 @@ let downloadLabel = defaultMenuDownloadLabel;
|
|||||||
let metadataURL = undefined;
|
let metadataURL = undefined;
|
||||||
let callbackIsRegistered = false;
|
let callbackIsRegistered = false;
|
||||||
|
|
||||||
module.exports = (win, options, refreshMenu) => {
|
module.exports = (win, options) => {
|
||||||
if (!callbackIsRegistered) {
|
if (!callbackIsRegistered) {
|
||||||
const registerCallback = getSongInfo(win);
|
const registerCallback = getSongInfo(win);
|
||||||
registerCallback((info) => {
|
registerCallback((info) => {
|
||||||
@ -36,6 +36,7 @@ module.exports = (win, options, refreshMenu) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("trying to get playlist ID" +playlistID);
|
||||||
const playlist = await ytpl(playlistID,
|
const playlist = await ytpl(playlistID,
|
||||||
{ limit: options.playlistMaxItems || Infinity }
|
{ limit: options.playlistMaxItems || Infinity }
|
||||||
);
|
);
|
||||||
|
|||||||
@ -14,7 +14,8 @@ 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 { defaultMenuDownloadLabel, getFolder } = require("./utils");
|
const { getFolder } = require("./utils");
|
||||||
|
const { cleanupArtistName } = require("../../providers/song-info");
|
||||||
|
|
||||||
const { createFFmpeg } = FFmpeg;
|
const { createFFmpeg } = FFmpeg;
|
||||||
const ffmpeg = createFFmpeg({
|
const ffmpeg = createFFmpeg({
|
||||||
@ -24,13 +25,6 @@ const ffmpeg = createFFmpeg({
|
|||||||
});
|
});
|
||||||
const ffmpegMutex = new Mutex();
|
const ffmpegMutex = new Mutex();
|
||||||
|
|
||||||
function noTopic(channelName) {
|
|
||||||
if (channelName && channelName.endsWith(" - Topic")) {
|
|
||||||
channelName = channelName.slice(0, -8);
|
|
||||||
}
|
|
||||||
return channelName;
|
|
||||||
}
|
|
||||||
|
|
||||||
const downloadVideoToMP3 = async (
|
const downloadVideoToMP3 = async (
|
||||||
videoUrl,
|
videoUrl,
|
||||||
sendFeedback,
|
sendFeedback,
|
||||||
@ -46,7 +40,7 @@ const downloadVideoToMP3 = async (
|
|||||||
const info = await ytdl.getInfo(videoUrl);
|
const info = await ytdl.getInfo(videoUrl);
|
||||||
const thumbnails = info.videoDetails?.author?.thumbnails;
|
const thumbnails = info.videoDetails?.author?.thumbnails;
|
||||||
metadata = {
|
metadata = {
|
||||||
artist: info.videoDetails?.media?.artist || noTopic(info.videoDetails?.author?.name) || "",
|
artist: info.videoDetails?.media?.artist || cleanupArtistName(info.videoDetails?.author?.name) || "",
|
||||||
title: info.videoDetails?.media?.song || info.videoDetails?.title || "",
|
title: info.videoDetails?.media?.song || info.videoDetails?.title || "",
|
||||||
imageSrc: thumbnails ? thumbnails[thumbnails.length - 1].url : ""
|
imageSrc: thumbnails ? thumbnails[thumbnails.length - 1].url : ""
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,21 +5,10 @@ const { setOptions } = require('../../config/plugins');
|
|||||||
const getSongInfo = require('../../providers/song-info');
|
const getSongInfo = require('../../providers/song-info');
|
||||||
const defaultConfig = require('../../config/defaults');
|
const defaultConfig = require('../../config/defaults');
|
||||||
|
|
||||||
const cleanupArtistName = (config, artist) => {
|
|
||||||
// removes the suffixes of the artist name for more recognition by last.fm
|
|
||||||
const { suffixesToRemove } = config;
|
|
||||||
if (suffixesToRemove === undefined) return artist;
|
|
||||||
|
|
||||||
for (suffix of suffixesToRemove) {
|
|
||||||
artist = artist.replace(suffix, '');
|
|
||||||
}
|
|
||||||
return artist;
|
|
||||||
}
|
|
||||||
|
|
||||||
const createFormData = params => {
|
const createFormData = params => {
|
||||||
// creates the body for in the post request
|
// creates the body for in the post request
|
||||||
const formData = new URLSearchParams();
|
const formData = new URLSearchParams();
|
||||||
for (key in params) {
|
for (const key in params) {
|
||||||
formData.append(key, params[key]);
|
formData.append(key, params[key]);
|
||||||
}
|
}
|
||||||
return formData;
|
return formData;
|
||||||
@ -28,7 +17,7 @@ const createQueryString = (params, api_sig) => {
|
|||||||
// creates a querystring
|
// creates a querystring
|
||||||
const queryData = [];
|
const queryData = [];
|
||||||
params.api_sig = api_sig;
|
params.api_sig = api_sig;
|
||||||
for (key in params) {
|
for (const key in params) {
|
||||||
queryData.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`);
|
queryData.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`);
|
||||||
}
|
}
|
||||||
return '?'+queryData.join('&');
|
return '?'+queryData.join('&');
|
||||||
@ -37,12 +26,12 @@ const createQueryString = (params, api_sig) => {
|
|||||||
const createApiSig = (params, secret) => {
|
const createApiSig = (params, secret) => {
|
||||||
// this function creates the api signature, see: https://www.last.fm/api/authspec
|
// this function creates the api signature, see: https://www.last.fm/api/authspec
|
||||||
const keys = [];
|
const keys = [];
|
||||||
for (key in params) {
|
for (const key in params) {
|
||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
keys.sort();
|
keys.sort();
|
||||||
let sig = '';
|
let sig = '';
|
||||||
for (key of keys) {
|
for (const key of keys) {
|
||||||
if (String(key) === 'format')
|
if (String(key) === 'format')
|
||||||
continue
|
continue
|
||||||
sig += `${key}${params[key]}`;
|
sig += `${key}${params[key]}`;
|
||||||
@ -157,8 +146,6 @@ const lastfm = async (win, config) => {
|
|||||||
registerCallback( songInfo => {
|
registerCallback( songInfo => {
|
||||||
// set remove the old scrobble timer
|
// set remove the old scrobble timer
|
||||||
clearTimeout(scrobbleTimer);
|
clearTimeout(scrobbleTimer);
|
||||||
// make the artist name a bit cleaner
|
|
||||||
songInfo.artist = cleanupArtistName(config, songInfo.artist);
|
|
||||||
if (!songInfo.isPaused) {
|
if (!songInfo.isPaused) {
|
||||||
setNowPlaying(songInfo, config);
|
setNowPlaying(songInfo, config);
|
||||||
// scrobble when the song is half way through, or has passed the 4 minute mark
|
// scrobble when the song is half way through, or has passed the 4 minute mark
|
||||||
|
|||||||
@ -58,7 +58,7 @@ 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?.media?.song || data?.videoDetails?.title;
|
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.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;
|
||||||
@ -102,5 +102,20 @@ const registerProvider = (win) => {
|
|||||||
return registerCallback;
|
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 = registerProvider;
|
||||||
module.exports.getImage = getImage;
|
module.exports.getImage = getImage;
|
||||||
|
module.exports.cleanupArtistName = cleanupArtistName;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user