cool fixes but ok

This commit is contained in:
MeowcaTheoRange 2024-02-19 17:16:29 -06:00
parent 974aa4706a
commit 60cbfeb205
2 changed files with 31 additions and 5 deletions

View file

@ -1,22 +1,45 @@
require('dotenv').config(); require('dotenv').config();
const process = require('process'); const { Readable } = require("stream");
const { Readable } = require('stream');
// 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");
const path = require("path"); const path = require("path");
const { readFileSync, writeFileSync } = require("fs");
function pathGenerator({ url, name, channelName }) { function pathGenerator({ url, name, channelName }) {
return path.join(process.env.NEXTCLOUD_FOLDER, `${url}-${skewered(`${name} - ${channelName}`)}.mp3`) return path.join(process.env.NEXTCLOUD_FOLDER, `${url}-${skewered(`${name} - ${channelName}`)}.mp3`)
} }
function checkLastSong({ name, channelName }) {
const curSong = readFileSync(path.join(__dirname, "last_song.txt"), 'utf8');
return (curSong === `${name} - ${channelName}`);
}
function writeLastSong({ name, channelName }) {
writeFileSync(path.join(__dirname, "last_song.txt"), `${name} - ${channelName}`, 'utf8');
return null;
}
async function getVideo() { async function getVideo() {
const trackData = await fetch( const trackData = await fetch(
`https://${process.env.LASTFM_INSTANCE}/2.0/?method=user.getrecenttracks&user=${process.env.LASTFM_USERNAME}&api_key=${process.env.LASTFM_API_KEY}&format=json&limit=1&extended=1` `https://${process.env.LASTFM_INSTANCE}/2.0/?method=user.getrecenttracks&user=${process.env.LASTFM_USERNAME}&api_key=${process.env.LASTFM_API_KEY}&format=json&limit=1&extended=1`
).then(x => x.json()).then(data => data.recenttracks.track[0]); ).then(x => x.json()).then(data => data.recenttracks.track[0]);
// const musics = await searchMusics(`${trackData.artist.name} - ${trackData.name}`); if (checkLastSong({
name: trackData.name,
channelName: trackData.artist.name
})) {
console.log("Last song check failed");
return null;
} else {
console.log("Last song check succeeded, writing file");
writeLastSong({
name: trackData.name,
channelName: trackData.artist.name
});
}
const videoList = await GetListByKeyword(`${trackData.artist.name} - ${trackData.name}`, false, 1, [ const videoList = await GetListByKeyword(`${trackData.artist.name} - ${trackData.name}`, false, 1, [
{type: "video"} {type: "video"}
@ -104,6 +127,8 @@ async function main() {
const video = await getVideo(); const video = await getVideo();
console.log(video); console.log(video);
if (video == null) return null;
const nextcloudClient = createClient( const nextcloudClient = createClient(
`https://${process.env.NEXTCLOUD_INSTANCE}/remote.php/dav/files/${process.env.NEXTCLOUD_USERNAME}/`, `https://${process.env.NEXTCLOUD_INSTANCE}/remote.php/dav/files/${process.env.NEXTCLOUD_USERNAME}/`,
{ {

1
last_song.txt Normal file
View file

@ -0,0 +1 @@
when you hear it you'll shit bricks - Gingus