From 67a3549e7bd9a2cdbce57bad5ffdd11a453eb09a Mon Sep 17 00:00:00 2001 From: Thord Johansson Date: Mon, 12 Aug 2024 18:07:38 +0200 Subject: [PATCH] Improvements to album art retrieval --- Program.cs | 44 +++++++++++++++++++++++++++++++++++--------- lbz-rpc.csproj | 1 + 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Program.cs b/Program.cs index 7315613..1c35b50 100644 --- a/Program.cs +++ b/Program.cs @@ -87,7 +87,20 @@ public class LbzRpcService var username = config_data["general"]["listenbrainz_username"]; var ignoredPlayers = config_data["general"]["ignored_sources"].Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); - var listen = listenBrainz.GetPlayingNow(username); + + MetaBrainz.ListenBrainz.Interfaces.IPlayingNow? listen = null; + + try + { + listen = listenBrainz.GetPlayingNow(username); + } + catch (MetaBrainz.Common.HttpError e) + { + Console.WriteLine("Error getting playing now: {0}", e.Message); + Thread.Sleep(10000); + continue; + } + if (listen != null) { //check ignored players @@ -101,7 +114,10 @@ public class LbzRpcService var listenData = listen.Track?.Info; if (listenData != null) { - if (listenData.AdditionalInfo.OriginUrl != null && (listenData.AdditionalInfo.OriginUrl?.Host == "music.youtube.com" || listenData.AdditionalInfo.OriginUrl?.Host == "www.youtube.com") && lastRecording != GetYoutubeId(listenData.AdditionalInfo.OriginUrl)) + if (listenData.AdditionalInfo.OriginUrl != null + && (listenData.AdditionalInfo.OriginUrl?.Host == "music.youtube.com" || listenData.AdditionalInfo.OriginUrl?.Host == "www.youtube.com") + && GetYoutubeId(listenData.AdditionalInfo.OriginUrl) != null + && lastRecording != GetYoutubeId(listenData.AdditionalInfo.OriginUrl)) { lastRecording = GetYoutubeId(listenData.AdditionalInfo.OriginUrl); @@ -129,6 +145,8 @@ public class LbzRpcService } } + lastRecording = GetYoutubeId(listenData.AdditionalInfo.OriginUrl); + if (release != null) { albumArtUrl = "https://coverartarchive.org/release/" + release.Item.Id + "/front-250.jpg"; @@ -140,12 +158,12 @@ public class LbzRpcService albumArtUrl = "https://img.youtube.com/vi/" + youtubeId + "/mqdefault.jpg"; } } - else if (lastRecording != listenData.AdditionalInfo?.RecordingId.ToString()) // MusicBrainz ID available + else if (lastRecording != listenData.AdditionalInfo?.RecordingId.ToString() && listenData.AdditionalInfo?.RecordingId != null) // MusicBrainz ID available { Console.WriteLine("Listening to {0} by {1}", listenData.Name, listenData.Artist); lastRecording = listenData.AdditionalInfo?.RecordingId.ToString(); - buttons = new List