From f75b978dd8f085bfa84c572094a2af7a31075cbb Mon Sep 17 00:00:00 2001 From: KGT1 Date: Mon, 18 Jan 2021 06:49:32 +0100 Subject: [PATCH] implement basic debug logging --- config.json | 3 ++- package.json | 1 + parseENV.js | 1 + src/index.js | 3 +++ src/playbackmanager.js | 11 +++++++++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/config.json b/config.json index 064510a..fb003b8 100644 --- a/config.json +++ b/config.json @@ -5,5 +5,6 @@ "jellyfin-password":"", "discord-prefix":"?", "jellyfin-app-name":"Jellyfin Discord Music Bot", - "interactive-seek-bar-update-intervall":2000 + "interactive-seek-bar-update-intervall":2000, + "log-level":"info" } diff --git a/package.json b/package.json index 2304d5e..272d811 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@discordjs/opus": "^0.3.2", "discord.js": "^12.3.1", "jellyfin-apiclient": "1.4.1", + "loglevel": "^1.7.1", "node-fetch": "^2.6.0", "nodejs": "0.0.0", "window": "^4.2.7", diff --git a/parseENV.js b/parseENV.js index a88f41b..ed2975b 100644 --- a/parseENV.js +++ b/parseENV.js @@ -9,6 +9,7 @@ if (process.env.JELLYFIN_USERNAME) { configfile["jellyfin-username"] = process.e if (process.env.JELLYFIN_PASSWORD) { configfile["jellyfin-password"] = process.env.JELLYFIN_PASSWORD; } if (process.env.JELLYFIN_APP_NAME) { configfile["jellyfin-app-name"] = process.env.JELLYFIN_APP_NAME; } if (process.env.MESSAGE_UPDATE_INTERVAL) { configfile["interactive-seek-bar-update-intervall"] = parseInt(process.env.MESSAGE_UPDATE_INTERVAL); } +if (process.env.LOG_LEVEL) { configfile["log-level"] = process.env.LOG_LEVEL; } fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => { if (err) return console.error(err); diff --git a/src/index.js b/src/index.js index 38dae36..ac1576a 100644 --- a/src/index.js +++ b/src/index.js @@ -9,6 +9,9 @@ try { const { handleChannelMessage } = require("./messagehandler"); + const log = require("loglevel"); + + log.setLevel(CONFIG["log-level"]); jellyfinClientManager.init(); // TODO Error Checking as the apiclients is inefficent diff --git a/src/playbackmanager.js b/src/playbackmanager.js index c956379..4998c4b 100644 --- a/src/playbackmanager.js +++ b/src/playbackmanager.js @@ -2,6 +2,8 @@ const interactivemsghandler = require("./interactivemsghandler"); const CONFIG = require("../config.json"); const discordclientmanager = require("./discordclientmanager"); +const log = require("loglevel"); + const { getAudioDispatcher, setAudioDispatcher @@ -29,6 +31,7 @@ function streamURLbuilder (itemID, bitrate) { } function startPlaying (voiceconnection = discordclientmanager.getDiscordClient().user.client.voice.connections.first(), itemIDPlaylist = currentPlayingPlaylist, playlistIndex = currentPlayingPlaylistIndex, seekTo, disconnectOnFinish = _disconnectOnFinish) { + log.debug("start playing ",playlistIndex, ". of list: ",itemIDPlaylist," in a voiceconnection?: ", voiceconnection=!undefined); isPaused = false; currentPlayingPlaylist = itemIDPlaylist; currentPlayingPlaylistIndex = playlistIndex; @@ -74,6 +77,7 @@ function startPlaying (voiceconnection = discordclientmanager.getDiscordClient() } async function spawnPlayMessage (message) { + log.debug("spawned Play Message: ",message); const itemIdDetails = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(), getItemId()); const imageURL = await jellyfinClientManager.getJellyfinClient().getImageUrl(itemIdDetails.AlbumId || getItemId(), { type: "Primary" }); try { @@ -107,6 +111,7 @@ async function updatePlayMessage () { * @param {Number} toSeek - where to seek in ticks */ function seek (toSeek = 0) { + log.debug("seek to: ", toSeek); if (getAudioDispatcher()) { startPlaying(undefined, undefined, undefined, ticksToSeconds(toSeek), _disconnectOnFinish); jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); @@ -119,10 +124,12 @@ function seek (toSeek = 0) { * @param {Array} itemID - array of itemIDs to be added */ function addTracks (itemID) { + log.debug("added track: ",itemID); currentPlayingPlaylist = currentPlayingPlaylist.concat(itemID); } function nextTrack () { + log.debug("nextTrack"); if (!(currentPlayingPlaylist)) { throw Error("There is currently nothing playing"); } else if (currentPlayingPlaylistIndex + 1 >= currentPlayingPlaylist.length) { @@ -134,6 +141,7 @@ function nextTrack () { } function previousTrack () { + log.debug("previousTrack"); if (ticksToSeconds(getPostitionTicks()) < 10) { if (!(currentPlayingPlaylist)) { throw Error("There is currently nothing playing"); @@ -151,6 +159,7 @@ function previousTrack () { * @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from */ function stop (disconnectVoiceConnection, itemId = getItemId()) { + log.debug("stop playback and send following payload to the server: ",getStopPayload()); isPaused = true; if (interactivemsghandler.hasMessage()) { interactivemsghandler.destroy(); @@ -170,12 +179,14 @@ function stop (disconnectVoiceConnection, itemId = getItemId()) { } function pause () { + log.debug("pause"); isPaused = true; jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); getAudioDispatcher().pause(true); } function resume () { + log.debug("resume"); isPaused = false; jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload()); getAudioDispatcher().resume();