Oh yeah that's it. Get his ass jsdom

This commit is contained in:
MeowcaTheoRange 2024-02-22 05:50:55 -06:00
parent 1dca0db9bb
commit 4b6d192a93
4 changed files with 16 additions and 5 deletions

View file

@ -20,6 +20,7 @@ NEXTCLOUD_FOLDER= # /Music/LastFMDownloader/
# Notifications
NOTIFICATION_SERVER_INSTANCE= # localhost
NOTIFICATION_SERVER_PORT= # 80
NOTIFICATION_SERVER_PASSWORD= # password123

View file

@ -34,6 +34,7 @@ NEXTCLOUD_FOLDER= # /Music/LastFMDownloader/
# Notifications
NOTIFICATION_SERVER_INSTANCE= # localhost
NOTIFICATION_SERVER_PORT= # 80
NOTIFICATION_SERVER_PASSWORD= # password123
@ -102,6 +103,7 @@ Here's the variables we left out when setting up `.env.example` for the first ti
```conf
# Notifications
NOTIFICATION_SERVER_INSTANCE= # localhost
NOTIFICATION_SERVER_PORT= # 80
NOTIFICATION_SERVER_PASSWORD= # password123
@ -110,6 +112,10 @@ NOTIFICATION_CLIENT_PORT= # 80
NOTIFICATION_CLIENT_PROTOCOL= # https
```
##### NOTIFICATION_SERVER_INSTANCE
Mostly for testing, but if you're running your notification server seperate from LastFMDownloader (you shouldn't be, in production), fill this with your server's domain. Otherwise, use `localhost`.
##### NOTIFICATION_SERVER_PORT
This will be the port that your notification server runs on. Set this to any port but 80 or 443 - you will need to use a reverse proxy like **nginx** or **Apache** in order to properly run this application.

View file

@ -9,7 +9,7 @@ const path = require("path");
const { readFileSync, writeFileSync } = require("fs");
const io = require('socket.io-client');
const NodeID3 = require('node-id3');
const xpath = require("xpath-html");
const { JSDOM } = require("jsdom");
function pathGenerator({ url, name, channelName }) {
return `${url}-${skewered(`${name} - ${channelName}`)}.mp3`;
@ -32,7 +32,11 @@ async function scrapeLastFMWebsiteForVideo(trackData) {
// classes: image-overlay-playlink-link
// attrs: data-youtube-id
const attr = xpath.fromPageSource(lastFMSite).findElement("//a[contains(@class, 'image-overlay-playlink-link')]/@data-youtube-id").getAttribute("data-youtube-id");
let attr;
try {
const dom = new JSDOM(lastFMSite);
attr = dom.window.document.querySelector("a.image-overlay-playlink-link").getAttribute("data-youtube-id");
} catch (err) { return null; }
if (attr == null) return;
@ -228,7 +232,7 @@ async function main() {
if (await checkNextcloud(video, nextcloudClient)) return dismantle();
socket.emit('nodeMessage', {
message: `New song found - ${video.tags.title} by ${video.tags.artist}`,
message: `New song found - ${video.tags.name} from ${video.tags.channelName}`,
password: process.env.NOTIFICATION_SERVER_PASSWORD
})
@ -276,7 +280,7 @@ async function main() {
return dismantle();
}
const socket = io.connect(`http://localhost:${process.env.NOTIFICATION_SERVER_PORT}`, {reconnect: true});
const socket = io.connect(`http://${process.env.NOTIFICATION_SERVER_INSTANCE}:${process.env.NOTIFICATION_SERVER_PORT}`, {reconnect: true});
socket.on('connect', function (s) {
console.log('Successfully connected to notification server');

View file

@ -13,6 +13,7 @@
"dotenv": "^16.4.4",
"express": "^4.18.2",
"fix-esm": "^1.0.1",
"jsdom": "^24.0.0",
"node-id3": "^0.2.6",
"node-notifier": "^10.0.1",
"node-youtube-music": "^0.10.3",
@ -20,7 +21,6 @@
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"webdav": "^5.3.2",
"xpath-html": "^1.0.3",
"youtube-search-api": "^1.2.1"
}
}