Fix to ensure the Youtube thumbnail is used where available

This commit is contained in:
Thord Johansson 2024-06-11 13:32:52 +02:00
parent 36a94819c5
commit c349ead544

View File

@ -137,7 +137,7 @@ public class LbzRpcService
else
{
var youtubeId = GetYoutubeId(listenData.AdditionalInfo.OriginUrl);
albumArtUrl = "https://img.youtube.com/vi/" + youtubeId + "/0.jpg";
albumArtUrl = "https://img.youtube.com/vi/" + youtubeId + "/mqdefault.jpg";
}
}
else if (lastRecording != listenData.AdditionalInfo?.RecordingId.ToString()) // MusicBrainz ID available
@ -154,7 +154,13 @@ public class LbzRpcService
buttons.Add(new Button() { Label = $"{username} on ListenBrainz", Url = $"https://listenbrainz.org/user/{username}" });
if (listenData.AdditionalInfo?.ReleaseId != null)
if (listenData.AdditionalInfo?.OriginUrl?.ToString().Contains("youtube") == true
|| listenData.AdditionalInfo?.OriginUrl?.ToString().Contains("youtu.be") == true)
{
var youtubeId = GetYoutubeId(listenData.AdditionalInfo.OriginUrl);
albumArtUrl = "https://img.youtube.com/vi/" + youtubeId + "/0.jpg";
}
else if (listenData.AdditionalInfo?.ReleaseId != null)
{
albumArtUrl = "https://coverartarchive.org/release/" + listenData.AdditionalInfo?.ReleaseId + "/front-250.jpg";
}
@ -163,7 +169,7 @@ public class LbzRpcService
Console.WriteLine("Searching for release {0} on MusicBrainz", listenData.Release);
Query q = new("LBZ-DRPC", new Version(1, 0, 0));
var release = q.FindReleases(listenData.Release, 1).Results?.FirstOrDefault();
if (release != null)
if (release != null && release?.Item?.CoverArtArchive != null)
{
albumArtUrl = "https://coverartarchive.org/release/" + release?.Item.Id + "/front-250.jpg";
}
@ -209,10 +215,17 @@ public class LbzRpcService
private string? GetYoutubeId(Uri originUrl)
{
var query = HttpUtility.ParseQueryString(originUrl.Query);
if (query["v"] != null)
if (originUrl.ToString().Contains("youtu.be"))
{
return query["v"];
return originUrl.Segments.Last();
}
else
{
var query = HttpUtility.ParseQueryString(originUrl.Query);
if (query["v"] != null)
{
return query["v"];
}
}
return null;
}