From 8f53bc717f05405536347fc42f51534291b6a049 Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 10:23:14 +0100 Subject: [PATCH 1/6] updates config to have new seasonumber option and fixes selected stream from choosing video. --- src/helpers/configs/default_config.js | 3 +++ src/rpc/format.js | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/helpers/configs/default_config.js b/src/helpers/configs/default_config.js index f4986ac..c39a665 100755 --- a/src/helpers/configs/default_config.js +++ b/src/helpers/configs/default_config.js @@ -60,6 +60,9 @@ module.exports = { // Show the remaining playback time displayTimeRemaining: true, + // Choose to show the season number when watching a show + seasonnumber: true, + // Keep rich presence when playback is stopped showStopped: true, diff --git a/src/rpc/format.js b/src/rpc/format.js index fa30f68..9005a09 100755 --- a/src/rpc/format.js +++ b/src/rpc/format.js @@ -138,13 +138,10 @@ module.exports = async (status) => { // Select VLC stream to fetch track information (wip for attatched mode) if (config.rpc.detached) { - selectedStream = - status.information.category["Stream 'audio/0'"] ?? - status.information.category["Stream 'video/1'"] ?? - (status.information.category["Stream 0"]?.Frame_rate - ? status.information.category["Stream 1"] - : status.information.category["Stream 0"]) ?? - null; + const streams = Object.values(status.information.category); + + // Find the first audio stream + selectedStream = streams.find((stream) => stream.Type === "Audio") ?? null; } // Fetch artwork and join URLs @@ -207,7 +204,6 @@ module.exports = async (status) => { } } ); - // Format songTitle for Bit rate and Sample Rate if (config.rpc.enableSampleRate && selectedStream) { @@ -255,7 +251,7 @@ module.exports = async (status) => { } if (meta.episodeNumber) { output.state = `Episode ${meta.episodeNumber}`; - if (meta.seasonNumber) { + if (meta.seasonNumber && config.rpc.seasonnumber) { output.state += ` - Season ${meta.seasonNumber}`; } } else if (display_artist) { From 7ab020060dbac6e4f710520dd65dc37b6aa40488 Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 10:31:28 +0100 Subject: [PATCH 2/6] fix bits reporting wrong if using decoded_bits_per_sample --- src/rpc/format.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpc/format.js b/src/rpc/format.js index 9005a09..979d850 100755 --- a/src/rpc/format.js +++ b/src/rpc/format.js @@ -17,6 +17,7 @@ let bandcampFetcher = new (require("./bandcampFetcher.js"))(); let coverartarchiveFetcher = new (require("./coverartarchiveFetcher.js"))(); let songTitle = null; let selectedStream = null; +let bitsPerSample = null; // These functions, 'fetchers', provide uniform inteface for simple access to the APIs // They take VLC metadata as the argument and on success return object containing @@ -142,6 +143,7 @@ module.exports = async (status) => { // Find the first audio stream selectedStream = streams.find((stream) => stream.Type === "Audio") ?? null; + bitsPerSample = selectedStream.Bits_per_sample ?? selectedStream.Decoded_bits_per_sample ?? null; } // Fetch artwork and join URLs @@ -208,7 +210,7 @@ module.exports = async (status) => { // Format songTitle for Bit rate and Sample Rate if (config.rpc.enableSampleRate && selectedStream) { songTitle = `${meta.title || meta.filename || "Playing something.."} [${ - selectedStream["Bits_per_sample"] + bitsPerSample } Bits, ${selectedStream["Sample_rate"].slice(0, 2)}kHz]`; } else { songTitle = meta.title || meta.filename || "Playing something.."; From 8d1039027751a739d381ce49b3f3bf82912aa1ff Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 10:39:56 +0100 Subject: [PATCH 3/6] forget to add ?. to the bitspersample fix --- src/rpc/format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/format.js b/src/rpc/format.js index 979d850..11576e6 100755 --- a/src/rpc/format.js +++ b/src/rpc/format.js @@ -143,7 +143,7 @@ module.exports = async (status) => { // Find the first audio stream selectedStream = streams.find((stream) => stream.Type === "Audio") ?? null; - bitsPerSample = selectedStream.Bits_per_sample ?? selectedStream.Decoded_bits_per_sample ?? null; + bitsPerSample = selectedStream?.Bits_per_sample ?? selectedStream?.Decoded_bits_per_sample ?? null; } // Fetch artwork and join URLs From e1f541e7afb9d690336739f199418cb5b8781f0d Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 10:59:04 +0100 Subject: [PATCH 4/6] fix: override whatg-url version for punycode deprecation warning --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 1bd7dd1..65f35ce 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,11 @@ "register-scheme": "^0.0.2", "vlc.js": "^3.2.7" }, + "overrides": { + "node-fetch@2.x": { + "whatwg-url": "14.x" + } + }, "devDependencies": { "@types/node": "^22.12.0" }, From 6708a3bdcf12eb84f39df665403e66e31713c9a6 Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 12:01:36 +0100 Subject: [PATCH 5/6] fix: change way seasonNumber is fetched --- src/helpers/configs/default_config.js | 3 -- src/rpc/format.js | 57 +++++++++++++++++++++------ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/helpers/configs/default_config.js b/src/helpers/configs/default_config.js index c39a665..f4986ac 100755 --- a/src/helpers/configs/default_config.js +++ b/src/helpers/configs/default_config.js @@ -60,9 +60,6 @@ module.exports = { // Show the remaining playback time displayTimeRemaining: true, - // Choose to show the season number when watching a show - seasonnumber: true, - // Keep rich presence when playback is stopped showStopped: true, diff --git a/src/rpc/format.js b/src/rpc/format.js index 11576e6..2028b24 100755 --- a/src/rpc/format.js +++ b/src/rpc/format.js @@ -2,11 +2,9 @@ * Description: Decides what information to display based on the nature of the media (video, music, etc) */ -const fs = require("fs"); const log = require("../helpers/lager.js"); const cl = require("../helpers/configLoader.js"); const config = cl.getOrInit("config.js"); -const axios = require("axios"); const { debug } = require("console"); let staticOverridesFetcher = new (require("./staticOverridesFetcher.js"))( @@ -137,13 +135,48 @@ module.exports = async (status) => { const { meta } = status.information.category; + console.log(meta) + + let season = meta.seasonNumber; + let episode = meta.episodeNumber; + let showname = meta.showName || ""; // fallback to VLC title if available + + if (season === undefined && episode === undefined) { + const filename = meta.filename || ""; + + console.log("im here") + + // Try matching SxxEyy or Exx + const match = + filename.match(/S(\d{1,2})E(\d{1,2})/i) || filename.match(/E(\d{1,2})/i); + + if (match) { + if (match.length === 3) { + season = parseInt(match[1], 10); + episode = parseInt(match[2], 10); + } else if (match.length === 2) { + episode = parseInt(match[1], 10); + } + + // Extract showname as everything before the match + showname = filename + .slice(0, match.index) + .replace(/[\._-]+$/, "") // remove trailing dots, underscores, or dashes + .replace(/[\._]/g, " ") // replace remaining dots/underscores with space + .trim(); + } + } + // Select VLC stream to fetch track information (wip for attatched mode) if (config.rpc.detached) { const streams = Object.values(status.information.category); // Find the first audio stream selectedStream = streams.find((stream) => stream.Type === "Audio") ?? null; - bitsPerSample = selectedStream?.Bits_per_sample ?? selectedStream?.Decoded_bits_per_sample ?? null; + bitsPerSample = + selectedStream?.Bits_per_sample ?? + selectedStream?.Decoded_bits_per_sample ?? + null; } // Fetch artwork and join URLs @@ -209,9 +242,9 @@ module.exports = async (status) => { // Format songTitle for Bit rate and Sample Rate if (config.rpc.enableSampleRate && selectedStream) { - songTitle = `${meta.title || meta.filename || "Playing something.."} [${ - bitsPerSample - } Bits, ${selectedStream["Sample_rate"].slice(0, 2)}kHz]`; + songTitle = `${ + meta.title || meta.filename || "Playing something.." + } [${bitsPerSample} Bits, ${selectedStream["Sample_rate"].slice(0, 2)}kHz]`; } else { songTitle = meta.title || meta.filename || "Playing something.."; } @@ -247,14 +280,14 @@ module.exports = async (status) => { output.largeImageKey = "youtube"; output.largeImageText = meta.url; } - if (meta.showName) { + if (showname) { // if a tv show - output.details = meta.showName; + output.details = showname; } - if (meta.episodeNumber) { - output.state = `Episode ${meta.episodeNumber}`; - if (meta.seasonNumber && config.rpc.seasonnumber) { - output.state += ` - Season ${meta.seasonNumber}`; + if (episode) { + output.state = `Episode ${episode}`; + if (season && season !== 1) { + output.state += ` - Season ${season}`; } } else if (display_artist) { output.state = display_artist; From f177e066539de6e4e8727dabff99cb08e8f4956c Mon Sep 17 00:00:00 2001 From: GreenDiscord Date: Wed, 20 Aug 2025 12:03:05 +0100 Subject: [PATCH 6/6] fix: remove leftover console logs --- src/rpc/format.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/rpc/format.js b/src/rpc/format.js index 2028b24..2439e53 100755 --- a/src/rpc/format.js +++ b/src/rpc/format.js @@ -135,17 +135,12 @@ module.exports = async (status) => { const { meta } = status.information.category; - console.log(meta) - let season = meta.seasonNumber; let episode = meta.episodeNumber; let showname = meta.showName || ""; // fallback to VLC title if available if (season === undefined && episode === undefined) { const filename = meta.filename || ""; - - console.log("im here") - // Try matching SxxEyy or Exx const match = filename.match(/S(\d{1,2})E(\d{1,2})/i) || filename.match(/E(\d{1,2})/i);