Prioritize YouTube Music instead of just searching YouTube immediately.
This commit is contained in:
parent
042d715bd8
commit
1fd4e96a3c
2 changed files with 35 additions and 10 deletions
44
index.js
44
index.js
|
@ -1,6 +1,7 @@
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const { Readable } = require("stream");
|
const { Readable } = require("stream");
|
||||||
const { finished } = require("stream/promises");
|
const { finished } = require("stream/promises");
|
||||||
|
const { searchMusics } = require('fix-esm').require("node-youtube-music");
|
||||||
const { GetListByKeyword } = require("youtube-search-api");
|
const { GetListByKeyword } = require("youtube-search-api");
|
||||||
const skewered = require("skewered");
|
const skewered = require("skewered");
|
||||||
const { createClient } = require("fix-esm").require("webdav");
|
const { createClient } = require("fix-esm").require("webdav");
|
||||||
|
@ -43,17 +44,40 @@ async function getVideo() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoList = await GetListByKeyword(`${trackData.artist.name} - ${trackData.name}`, false, 1, [
|
let selectedVideo = {
|
||||||
{type: "video"}
|
url: "",
|
||||||
]);
|
name: "",
|
||||||
|
channelName: ""
|
||||||
const musicVideo = videoList.items[0];
|
|
||||||
|
|
||||||
return {
|
|
||||||
url: musicVideo.id,
|
|
||||||
name: musicVideo.title,
|
|
||||||
channelName: musicVideo.channelTitle
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const musicList = await searchMusics(`${trackData.artist.name} - ${trackData.name}`);
|
||||||
|
|
||||||
|
const youtubeMusicVideo = musicList.find((song) => {
|
||||||
|
return skewered(song.title).includes(skewered(trackData.name));
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(youtubeMusicVideo);
|
||||||
|
|
||||||
|
if (youtubeMusicVideo == null) {
|
||||||
|
const videoList = await GetListByKeyword(`${trackData.artist.name} - ${trackData.name}`, false, 1, [
|
||||||
|
{type: "video"}
|
||||||
|
]);
|
||||||
|
|
||||||
|
const musicVideo = videoList.items[0];
|
||||||
|
|
||||||
|
selectedVideo = {
|
||||||
|
url: musicVideo.id,
|
||||||
|
name: musicVideo.title,
|
||||||
|
channelName: musicVideo.channelTitle
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else selectedVideo = {
|
||||||
|
url: youtubeMusicVideo.youtubeId,
|
||||||
|
name: youtubeMusicVideo.title,
|
||||||
|
channelName: youtubeMusicVideo.artists[0].name
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectedVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkNextcloud({ url, name, channelName }, nextcloudClient) {
|
async function checkNextcloud({ url, name, channelName }, nextcloudClient) {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"fix-esm": "^1.0.1",
|
"fix-esm": "^1.0.1",
|
||||||
"node-notifier": "^10.0.1",
|
"node-notifier": "^10.0.1",
|
||||||
|
"node-youtube-music": "^0.10.3",
|
||||||
"skewered": "^1.0.0",
|
"skewered": "^1.0.0",
|
||||||
"socket.io": "^4.7.4",
|
"socket.io": "^4.7.4",
|
||||||
"socket.io-client": "^4.7.4",
|
"socket.io-client": "^4.7.4",
|
||||||
|
|
Loading…
Reference in a new issue