fixes #522 - Use last fm as a secondary provider for album images

pull/702/head
Luke Pulverenti 11 years ago
parent 4039c0f704
commit 062d2dc29f

@ -8,6 +8,8 @@ namespace MediaBrowser.Controller.Entities.Audio
/// </summary>
public class MusicAlbum : Folder
{
public string LastFmImageUrl { get; set; }
/// <summary>
/// Songs will group into us so don't also include us in the index
/// </summary>

@ -77,7 +77,7 @@
<Compile Include="Music\FanArtUpdatesPrescanTask.cs" />
<Compile Include="Music\LastfmAlbumProvider.cs" />
<Compile Include="Music\LastfmArtistByNameProvider.cs" />
<Compile Include="Music\LastFmArtistImageProvider.cs" />
<Compile Include="Music\LastFmImageProvider.cs" />
<Compile Include="Music\LastfmArtistProvider.cs" />
<Compile Include="Music\LastfmBaseProvider.cs" />
<Compile Include="Music\LastfmHelper.cs" />

@ -13,7 +13,7 @@ namespace MediaBrowser.Providers.Music
/// <summary>
/// Class LastFmArtistImageProvider
/// </summary>
public class LastFmArtistImageProvider : BaseMetadataProvider
public class LastFmImageProvider : BaseMetadataProvider
{
/// <summary>
/// The _provider manager
@ -21,12 +21,12 @@ namespace MediaBrowser.Providers.Music
private readonly IProviderManager _providerManager;
/// <summary>
/// Initializes a new instance of the <see cref="LastFmArtistImageProvider"/> class.
/// Initializes a new instance of the <see cref="LastFmImageProvider"/> class.
/// </summary>
/// <param name="logManager">The log manager.</param>
/// <param name="configurationManager">The configuration manager.</param>
/// <param name="providerManager">The provider manager.</param>
public LastFmArtistImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager) :
public LastFmImageProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IProviderManager providerManager) :
base(logManager, configurationManager)
{
_providerManager = providerManager;
@ -39,7 +39,7 @@ namespace MediaBrowser.Providers.Music
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item)
{
return item is Artist || item is MusicArtist;
return item is Artist || item is MusicArtist || item is MusicAlbum;
}
/// <summary>
@ -114,6 +114,13 @@ namespace MediaBrowser.Providers.Music
return artistByName.LastFmImageUrl;
}
var album = item as MusicAlbum;
if (album != null)
{
return album.LastFmImageUrl;
}
return null;
}
}

@ -1,4 +1,5 @@
using MediaBrowser.Common.Extensions;
using System.IO;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
@ -143,7 +144,15 @@ namespace MediaBrowser.Providers.Music
}).ConfigureAwait(false))
{
return JsonSerializer.DeserializeFromStream<LastfmGetAlbumResult>(json);
using (var reader = new StreamReader(json))
{
var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false);
// Fix their bad json
jsonText = jsonText.Replace("\"#text\"", "\"url\"");
return JsonSerializer.DeserializeFromString<LastfmGetAlbumResult>(jsonText);
}
}
}

@ -193,7 +193,7 @@ namespace MediaBrowser.Providers.Music
public string size { get; set; }
}
public class LastfmArtist
public class LastfmArtist : IHasLastFmImages
{
public string name { get; set; }
public string mbid { get; set; }
@ -208,7 +208,7 @@ namespace MediaBrowser.Providers.Music
}
public class LastfmAlbum
public class LastfmAlbum : IHasLastFmImages
{
public string name { get; set; }
public string artist { get; set; }
@ -219,6 +219,12 @@ namespace MediaBrowser.Providers.Music
public int playcount { get; set; }
public LastfmTags toptags { get; set; }
public LastFmBio wiki { get; set; }
public List<LastFmImage> image { get; set; }
}
public interface IHasLastFmImages
{
List<LastFmImage> image { get; set; }
}
public class LastfmGetAlbumResult

@ -47,14 +47,17 @@ namespace MediaBrowser.Providers.Music
}
}
private static string GetImageUrl(LastfmArtist data)
private static string GetImageUrl(IHasLastFmImages data)
{
if (data.image == null)
{
return null;
}
var img = data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ??
var img = data.image
.Where(i => !string.IsNullOrWhiteSpace(i.url))
.FirstOrDefault(i => string.Equals(i.size, "mega", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "extralarge", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "large", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault(i => string.Equals(i.size, "medium", StringComparison.OrdinalIgnoreCase)) ??
data.image.FirstOrDefault();
@ -99,6 +102,9 @@ namespace MediaBrowser.Providers.Music
{
AddTags(item, data.toptags);
}
var album = (MusicAlbum)item;
album.LastFmImageUrl = GetImageUrl(data);
}
private static void AddTags(BaseItem item, LastfmTags tags)

Loading…
Cancel
Save