From 832832c4d20135f7155b8ebde5553500978e5d1f Mon Sep 17 00:00:00 2001 From: Thord Johansson Date: Sun, 20 Oct 2024 22:18:12 +0200 Subject: [PATCH] Refactor LbzRpcService and add HandleNewListenData method Refactored the LbzRpcService class to improve code structure and efficiency. Moved `lastRecording` and `albumArtUrl` fields to class scope and removed their initialization from the loop. Enhanced album art URL handling with `TrySetAlbumArtUrl` and `SetAlbumArtUrl` methods. Prioritized MusicBrainz data and added fallback to YouTube thumbnails. --- Program.cs | 306 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 192 insertions(+), 114 deletions(-) diff --git a/Program.cs b/Program.cs index 1c35b50..8b42367 100644 --- a/Program.cs +++ b/Program.cs @@ -8,6 +8,8 @@ using Topshelf; using System.Web; using MetaBrainz.MusicBrainz.Interfaces.Entities; using MetaBrainz.MusicBrainz.Interfaces.Searches; +using MetaBrainz.ListenBrainz.Interfaces; +using System.Net; public class LbzRpcService @@ -17,6 +19,8 @@ public class LbzRpcService readonly Thread t; bool running = false; + private string? lastRecording; + private string albumArtUrl = ""; public LbzRpcService() { @@ -71,10 +75,6 @@ public class LbzRpcService InitializeDiscordRpc(); - string? lastRecording = null; - List