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
26
index.js
26
index.js
|
@ -1,6 +1,7 @@
|
|||
require('dotenv').config();
|
||||
const { Readable } = require("stream");
|
||||
const { finished } = require("stream/promises");
|
||||
const { searchMusics } = require('fix-esm').require("node-youtube-music");
|
||||
const { GetListByKeyword } = require("youtube-search-api");
|
||||
const skewered = require("skewered");
|
||||
const { createClient } = require("fix-esm").require("webdav");
|
||||
|
@ -43,17 +44,40 @@ async function getVideo() {
|
|||
});
|
||||
}
|
||||
|
||||
let selectedVideo = {
|
||||
url: "",
|
||||
name: "",
|
||||
channelName: ""
|
||||
};
|
||||
|
||||
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];
|
||||
|
||||
return {
|
||||
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) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"express": "^4.18.2",
|
||||
"fix-esm": "^1.0.1",
|
||||
"node-notifier": "^10.0.1",
|
||||
"node-youtube-music": "^0.10.3",
|
||||
"skewered": "^1.0.0",
|
||||
"socket.io": "^4.7.4",
|
||||
"socket.io-client": "^4.7.4",
|
||||
|
|
Loading…
Reference in a new issue