cool fixes but ok
This commit is contained in:
parent
974aa4706a
commit
60cbfeb205
2 changed files with 31 additions and 5 deletions
35
index.js
35
index.js
|
@ -1,22 +1,45 @@
|
|||
require('dotenv').config();
|
||||
const process = require('process');
|
||||
const { Readable } = require('stream');
|
||||
// const { searchMusics } = require("fix-esm").require('node-youtube-music');
|
||||
const { Readable } = require("stream");
|
||||
const { GetListByKeyword } = require("youtube-search-api");
|
||||
const skewered = require("skewered");
|
||||
const { createClient } = require('fix-esm').require("webdav");
|
||||
const { createClient } = require("fix-esm").require("webdav");
|
||||
const path = require("path");
|
||||
const { readFileSync, writeFileSync } = require("fs");
|
||||
|
||||
function pathGenerator({ url, name, channelName }) {
|
||||
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() {
|
||||
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`
|
||||
).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, [
|
||||
{type: "video"}
|
||||
|
@ -104,6 +127,8 @@ async function main() {
|
|||
const video = await getVideo();
|
||||
console.log(video);
|
||||
|
||||
if (video == null) return null;
|
||||
|
||||
const nextcloudClient = createClient(
|
||||
`https://${process.env.NEXTCLOUD_INSTANCE}/remote.php/dav/files/${process.env.NEXTCLOUD_USERNAME}/`,
|
||||
{
|
||||
|
|
1
last_song.txt
Normal file
1
last_song.txt
Normal file
|
@ -0,0 +1 @@
|
|||
when you hear it you'll shit bricks - Gingus
|
Loading…
Reference in a new issue