From 4b6d192a93d8fc77ba58b24af83152691a90fd3d Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Thu, 22 Feb 2024 05:50:55 -0600 Subject: [PATCH] Oh yeah that's it. Get his ass jsdom --- .env.example | 1 + README.md | 6 ++++++ index.js | 12 ++++++++---- package.json | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 10420eb..6d84d09 100644 --- a/.env.example +++ b/.env.example @@ -20,6 +20,7 @@ NEXTCLOUD_FOLDER= # /Music/LastFMDownloader/ # Notifications +NOTIFICATION_SERVER_INSTANCE= # localhost NOTIFICATION_SERVER_PORT= # 80 NOTIFICATION_SERVER_PASSWORD= # password123 diff --git a/README.md b/README.md index 307d960..2906d61 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/index.js b/index.js index 50c57a2..e36c7cf 100644 --- a/index.js +++ b/index.js @@ -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'); diff --git a/package.json b/package.json index 2c57305..cdf4569 100644 --- a/package.json +++ b/package.json @@ -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" } }