mirror of
https://github.com/sphildreth/roadie
synced 2025-02-16 13:08:25 +00:00
Fix for LastFM returning string empty objects.
This commit is contained in:
parent
0fd9fc92d0
commit
5a5e4cae70
2 changed files with 27 additions and 6 deletions
|
@ -1,4 +1,7 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using Roadie.Library.Caching;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Roadie.Library.SearchEngines.MetaData.LastFm
|
||||
{
|
||||
|
@ -12,8 +15,8 @@ namespace Roadie.Library.SearchEngines.MetaData.LastFm
|
|||
public string artist { get; set; }
|
||||
|
||||
public string mbid { get; set; }
|
||||
|
||||
public Tags tags { get; set; }
|
||||
|
||||
public string tags { get; set; }
|
||||
|
||||
public string name { get; set; }
|
||||
|
||||
|
@ -26,6 +29,23 @@ namespace Roadie.Library.SearchEngines.MetaData.LastFm
|
|||
public string playcount { get; set; }
|
||||
|
||||
public string url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sometimes LastFM returns string empty for an object (?!) and that blows up the serializer. This returns tags if the object value isn't an empty string.
|
||||
/// </summary>
|
||||
public IEnumerable<Tag> GetTags(ICacheSerializer serializer)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(tags))
|
||||
{
|
||||
return Enumerable.Empty<Tag>();
|
||||
}
|
||||
var t = serializer.Deserialize<Tags>(tags);
|
||||
if(t != null)
|
||||
{
|
||||
return t.tag;
|
||||
}
|
||||
return Enumerable.Empty<Tag>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Tags
|
||||
|
@ -58,8 +78,6 @@ namespace Roadie.Library.SearchEngines.MetaData.LastFm
|
|||
[JsonPropertyName("@attr")]
|
||||
public Attr attr { get; set; }
|
||||
|
||||
//public int? TrackNumber => string.IsNullOrWhiteSpace(attr) ? null : int.Parse(attr.Replace("\"@attr\":{\"rank\":", "").Replace("}", ""));
|
||||
|
||||
public int? TrackNumber => attr?.rank;
|
||||
|
||||
public Artist artist { get; set; }
|
||||
|
|
|
@ -240,7 +240,10 @@ namespace Roadie.Library.MetaData.LastFm
|
|||
|
||||
// No longer fetching/consuming images LastFm says is violation of ToS ; https://getsatisfaction.com/lastfm/topics/api-announcement-dac8oefw5vrxq
|
||||
|
||||
if (lastFmAlbum.tags != null) result.Tags = lastFmAlbum.tags.tag.Select(x => x.name).ToList();
|
||||
if (!string.IsNullOrWhiteSpace(lastFmAlbum.tags))
|
||||
{
|
||||
result.Tags = lastFmAlbum.GetTags(CacheManager.CacheSerializer)?.Select(x => x.name).ToList();
|
||||
}
|
||||
if (lastFmAlbum.tracks != null)
|
||||
{
|
||||
var tracks = new List<TrackSearchResult>();
|
||||
|
|
Loading…
Add table
Reference in a new issue