move last fm providers to a plugin
This commit is contained in:
parent
baf44b2718
commit
d7f3214b32
|
@ -29,6 +29,8 @@ namespace MediaBrowser.Controller.Channels
|
|||
|
||||
public MediaProtocol Protocol { get; set; }
|
||||
|
||||
public long? RunTimeTicks { get; set; }
|
||||
|
||||
public ChannelMediaInfo()
|
||||
{
|
||||
RequiredHttpHeaders = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
|
|
@ -93,6 +93,7 @@ namespace MediaBrowser.Model.Configuration
|
|||
BlockUnratedItems = new UnratedItem[] { };
|
||||
|
||||
ExcludeFoldersFromGrouping = new string[] { };
|
||||
DisplayCollectionsView = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,6 @@
|
|||
<Compile Include="Music\AudioDbExternalIds.cs" />
|
||||
<Compile Include="Music\AudioMetadataService.cs" />
|
||||
<Compile Include="Music\Extensions.cs" />
|
||||
<Compile Include="Music\LastfmArtistProvider.cs" />
|
||||
<Compile Include="Music\MovieDbMusicVideoProvider.cs" />
|
||||
<Compile Include="Music\MusicBrainzArtistProvider.cs" />
|
||||
<Compile Include="Music\MusicExternalIds.cs" />
|
||||
|
@ -138,11 +137,8 @@
|
|||
<Compile Include="Movies\FanArtMovieUpdatesPostScanTask.cs" />
|
||||
<Compile Include="Movies\MovieDbProvider.cs" />
|
||||
<Compile Include="Music\FanArtUpdatesPostScanTask.cs" />
|
||||
<Compile Include="Music\LastfmAlbumProvider.cs" />
|
||||
<Compile Include="Music\LastfmHelper.cs" />
|
||||
<Compile Include="Music\FanArtAlbumProvider.cs" />
|
||||
<Compile Include="Music\FanArtArtistProvider.cs" />
|
||||
<Compile Include="Music\LastFmImageProvider.cs" />
|
||||
<Compile Include="Music\MusicBrainzAlbumProvider.cs" />
|
||||
<Compile Include="Music\SoundtrackPostScanTask.cs" />
|
||||
<Compile Include="People\PersonMetadataService.cs" />
|
||||
|
|
|
@ -12,6 +12,11 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
/// <param name="result">The result.</param>
|
||||
public static void NormalizeFFProbeResult(InternalMediaInfoResult result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
throw new ArgumentNullException("result");
|
||||
}
|
||||
|
||||
if (result.format != null && result.format.tags != null)
|
||||
{
|
||||
result.format.tags = ConvertDictionaryToCaseInSensitive(result.format.tags);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
|
@ -86,6 +87,8 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
item.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, result.strMusicBrainzArtistID);
|
||||
item.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, result.strMusicBrainzID);
|
||||
|
||||
item.Overview = (result.strDescriptionEN ?? string.Empty).StripHtml();
|
||||
}
|
||||
|
||||
public string Name
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
if (!string.IsNullOrEmpty(artistMusicBrainzId))
|
||||
{
|
||||
await FanartArtistProvider.Current.EnsureMovieXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false);
|
||||
await FanartArtistProvider.Current.EnsureArtistXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var artistXmlPath = FanartArtistProvider.GetArtistXmlPath(_config.CommonApplicationPaths, artistMusicBrainzId);
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
if (!String.IsNullOrEmpty(artistMusicBrainzId))
|
||||
{
|
||||
await EnsureMovieXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false);
|
||||
await EnsureArtistXml(artistMusicBrainzId, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var artistXmlPath = GetArtistXmlPath(_config.CommonApplicationPaths, artistMusicBrainzId);
|
||||
|
||||
|
@ -390,7 +390,7 @@ namespace MediaBrowser.Providers.Music
|
|||
}
|
||||
|
||||
private readonly Task _cachedTask = Task.FromResult(true);
|
||||
internal Task EnsureMovieXml(string musicBrainzId, CancellationToken cancellationToken)
|
||||
internal Task EnsureArtistXml(string musicBrainzId, CancellationToken cancellationToken)
|
||||
{
|
||||
var xmlPath = GetArtistXmlPath(_config.ApplicationPaths, musicBrainzId);
|
||||
|
||||
|
|
|
@ -1,164 +0,0 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
public class LastfmImageProvider : IRemoteImageProvider, IHasOrder
|
||||
{
|
||||
private readonly IHttpClient _httpClient;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
|
||||
public LastfmImageProvider(IHttpClient httpClient, IServerConfigurationManager config)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return ProviderName; }
|
||||
}
|
||||
|
||||
public static string ProviderName
|
||||
{
|
||||
get { return "last.fm"; }
|
||||
}
|
||||
|
||||
public bool Supports(IHasImages item)
|
||||
{
|
||||
return item is MusicAlbum || item is MusicArtist;
|
||||
}
|
||||
|
||||
public IEnumerable<ImageType> GetSupportedImages(IHasImages item)
|
||||
{
|
||||
return new List<ImageType>
|
||||
{
|
||||
ImageType.Primary
|
||||
};
|
||||
}
|
||||
|
||||
public Task<IEnumerable<RemoteImageInfo>> GetImages(IHasImages item, CancellationToken cancellationToken)
|
||||
{
|
||||
var list = new List<RemoteImageInfo>();
|
||||
|
||||
RemoteImageInfo info = null;
|
||||
|
||||
var musicBrainzId = item is MusicAlbum ?
|
||||
item.GetProviderId(MetadataProviders.MusicBrainzAlbum) :
|
||||
item.GetProviderId(MetadataProviders.MusicBrainzArtist);
|
||||
|
||||
if (!string.IsNullOrEmpty(musicBrainzId))
|
||||
{
|
||||
var cachePath = Path.Combine(_config.ApplicationPaths.CachePath, "lastfm", musicBrainzId, "image.txt");
|
||||
|
||||
try
|
||||
{
|
||||
var parts = File.ReadAllText(cachePath).Split('|');
|
||||
|
||||
info = GetInfo(parts.FirstOrDefault(), parts.LastOrDefault());
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (info == null)
|
||||
{
|
||||
var musicBrainzReleaseGroupId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
|
||||
|
||||
if (!string.IsNullOrEmpty(musicBrainzReleaseGroupId))
|
||||
{
|
||||
var cachePath = Path.Combine(_config.ApplicationPaths.CachePath, "lastfm", musicBrainzReleaseGroupId, "image.txt");
|
||||
|
||||
try
|
||||
{
|
||||
var parts = File.ReadAllText(cachePath).Split('|');
|
||||
|
||||
info = GetInfo(parts.FirstOrDefault(), parts.LastOrDefault());
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (info != null)
|
||||
{
|
||||
list.Add(info);
|
||||
}
|
||||
|
||||
// The only info we have is size
|
||||
return Task.FromResult<IEnumerable<RemoteImageInfo>>(list.OrderByDescending(i => i.Width ?? 0));
|
||||
}
|
||||
|
||||
private RemoteImageInfo GetInfo(string url, string size)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var info = new RemoteImageInfo
|
||||
{
|
||||
ProviderName = Name,
|
||||
Url = url,
|
||||
Type = ImageType.Primary
|
||||
};
|
||||
|
||||
if (string.Equals(size, "mega", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
}
|
||||
else if (string.Equals(size, "extralarge", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
}
|
||||
else if (string.Equals(size, "large", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
}
|
||||
else if (string.Equals(size, "medium", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
public int Order
|
||||
{
|
||||
get
|
||||
{
|
||||
// After all others
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
return _httpClient.GetResponse(new HttpRequestOptions
|
||||
{
|
||||
CancellationToken = cancellationToken,
|
||||
Url = url,
|
||||
ResourcePool = LastfmArtistProvider.LastfmResourcePool
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
public class LastfmAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder
|
||||
{
|
||||
private readonly IJsonSerializer _json;
|
||||
private readonly IHttpClient _httpClient;
|
||||
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public LastfmAlbumProvider(IHttpClient httpClient, IJsonSerializer json, IServerConfigurationManager config, ILogger logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_json = json;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
return new List<RemoteSearchResult>();
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<MusicAlbum>();
|
||||
|
||||
var lastFmData = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (lastFmData != null && lastFmData.album != null)
|
||||
{
|
||||
result.HasMetadata = true;
|
||||
result.Item = new MusicAlbum();
|
||||
ProcessAlbumData(result.Item, lastFmData.album);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<LastfmGetAlbumResult> GetAlbumResult(AlbumInfo item, CancellationToken cancellationToken)
|
||||
{
|
||||
// Try album release Id
|
||||
var id = item.GetReleaseId();
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
var result = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result != null && result.album != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Try album release group Id
|
||||
id = item.GetReleaseGroupId();
|
||||
if (!string.IsNullOrEmpty(id))
|
||||
{
|
||||
var result = await GetAlbumResult(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result != null && result.album != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
var albumArtist = item.GetAlbumArtist();
|
||||
// Get each song, distinct by the combination of AlbumArtist and Album
|
||||
var songs = item.SongInfos.DistinctBy(i => (i.AlbumArtists.FirstOrDefault() ?? string.Empty) + (i.Album ?? string.Empty), StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
foreach (var song in songs.Where(song => !string.IsNullOrEmpty(song.Album) && !string.IsNullOrEmpty(song.AlbumArtists.FirstOrDefault())))
|
||||
{
|
||||
var result = await GetAlbumResult(song.AlbumArtists.FirstOrDefault(), song.Album, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result != null && result.album != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(albumArtist))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return await GetAlbumResult(albumArtist, item.Name, cancellationToken);
|
||||
}
|
||||
|
||||
private async Task<LastfmGetAlbumResult> GetAlbumResult(string artist, string album, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get albu info using artist and album name
|
||||
var url = LastfmArtistProvider.RootUrl + string.Format("method=album.getInfo&artist={0}&album={1}&api_key={2}&format=json", UrlEncode(artist), UrlEncode(album), LastfmArtistProvider.ApiKey);
|
||||
|
||||
using (var json = await _httpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
ResourcePool = LastfmArtistProvider.LastfmResourcePool,
|
||||
CancellationToken = cancellationToken,
|
||||
EnableHttpCompression = false
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
using (var reader = new StreamReader(json))
|
||||
{
|
||||
var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||
|
||||
// Fix their bad json
|
||||
jsonText = jsonText.Replace("\"#text\"", "\"url\"");
|
||||
|
||||
return _json.DeserializeFromString<LastfmGetAlbumResult>(jsonText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<LastfmGetAlbumResult> GetAlbumResult(string musicbraizId, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get albu info using artist and album name
|
||||
var url = LastfmArtistProvider.RootUrl + string.Format("method=album.getInfo&mbid={0}&api_key={1}&format=json", musicbraizId, LastfmArtistProvider.ApiKey);
|
||||
|
||||
using (var json = await _httpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
ResourcePool = LastfmArtistProvider.LastfmResourcePool,
|
||||
CancellationToken = cancellationToken,
|
||||
EnableHttpCompression = false
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
return _json.DeserializeFromStream<LastfmGetAlbumResult>(json);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessAlbumData(MusicAlbum item, LastfmAlbum data)
|
||||
{
|
||||
var overview = data.wiki != null ? data.wiki.content : null;
|
||||
|
||||
if (!item.LockedFields.Contains(MetadataFields.Overview))
|
||||
{
|
||||
item.Overview = overview;
|
||||
}
|
||||
|
||||
// Only grab the date here if the album doesn't already have one, since id3 tags are preferred
|
||||
DateTime release;
|
||||
|
||||
if (DateTime.TryParse(data.releasedate, out release))
|
||||
{
|
||||
// Lastfm sends back null as sometimes 1901, other times 0
|
||||
if (release.Year > 1901)
|
||||
{
|
||||
if (!item.PremiereDate.HasValue)
|
||||
{
|
||||
item.PremiereDate = release;
|
||||
}
|
||||
|
||||
if (!item.ProductionYear.HasValue)
|
||||
{
|
||||
item.ProductionYear = release.Year;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string imageSize;
|
||||
var url = LastfmHelper.GetImageUrl(data, out imageSize);
|
||||
|
||||
var musicBrainzId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum) ??
|
||||
item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
|
||||
|
||||
if (!string.IsNullOrEmpty(musicBrainzId) && !string.IsNullOrEmpty(url))
|
||||
{
|
||||
LastfmHelper.SaveImageInfo(_config.ApplicationPaths, _logger, musicBrainzId, url, imageSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes an URL.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private string UrlEncode(string name)
|
||||
{
|
||||
return WebUtility.UrlEncode(name);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "last.fm"; }
|
||||
}
|
||||
|
||||
public int Order
|
||||
{
|
||||
get
|
||||
{
|
||||
// After fanart & audiodb
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
#region Result Objects
|
||||
|
||||
public class LastfmStats
|
||||
{
|
||||
public string listeners { get; set; }
|
||||
public string playcount { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmTag
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string url { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class LastfmTags
|
||||
{
|
||||
public List<LastfmTag> tag { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmFormationInfo
|
||||
{
|
||||
public string yearfrom { get; set; }
|
||||
public string yearto { get; set; }
|
||||
}
|
||||
|
||||
public class LastFmBio
|
||||
{
|
||||
public string published { get; set; }
|
||||
public string summary { get; set; }
|
||||
public string content { get; set; }
|
||||
public string placeformed { get; set; }
|
||||
public string yearformed { get; set; }
|
||||
public List<LastfmFormationInfo> formationlist { get; set; }
|
||||
}
|
||||
|
||||
public class LastFmImage
|
||||
{
|
||||
public string url { get; set; }
|
||||
public string size { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmArtist : IHasLastFmImages
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string mbid { get; set; }
|
||||
public string url { get; set; }
|
||||
public string streamable { get; set; }
|
||||
public string ontour { get; set; }
|
||||
public LastfmStats stats { get; set; }
|
||||
public List<LastfmArtist> similar { get; set; }
|
||||
public LastfmTags tags { get; set; }
|
||||
public LastFmBio bio { get; set; }
|
||||
public List<LastFmImage> image { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class LastfmAlbum : IHasLastFmImages
|
||||
{
|
||||
public string name { get; set; }
|
||||
public string artist { get; set; }
|
||||
public string id { get; set; }
|
||||
public string mbid { get; set; }
|
||||
public string releasedate { get; set; }
|
||||
public int listeners { get; set; }
|
||||
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
|
||||
{
|
||||
public LastfmAlbum album { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmGetArtistResult
|
||||
{
|
||||
public LastfmArtist artist { get; set; }
|
||||
}
|
||||
|
||||
public class Artistmatches
|
||||
{
|
||||
public List<LastfmArtist> artist { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmArtistSearchResult
|
||||
{
|
||||
public Artistmatches artistmatches { get; set; }
|
||||
}
|
||||
|
||||
public class LastfmArtistSearchResults
|
||||
{
|
||||
public LastfmArtistSearchResult results { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
public class LastfmArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>, IHasOrder
|
||||
{
|
||||
private readonly IJsonSerializer _json;
|
||||
private readonly IHttpClient _httpClient;
|
||||
|
||||
internal static readonly SemaphoreSlim LastfmResourcePool = new SemaphoreSlim(4, 4);
|
||||
|
||||
internal const string RootUrl = @"http://ws.audioscrobbler.com/2.0/?";
|
||||
internal static string ApiKey = "7b76553c3eb1d341d642755aecc40a33";
|
||||
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public LastfmArtistProvider(IHttpClient httpClient, IJsonSerializer json, IServerConfigurationManager config, ILogger logger)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_json = json;
|
||||
_config = config;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
return new List<RemoteSearchResult>();
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<MusicArtist>();
|
||||
|
||||
var musicBrainzId = id.GetMusicBrainzArtistId();
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(musicBrainzId))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
result.Item = new MusicArtist();
|
||||
result.HasMetadata = true;
|
||||
|
||||
await FetchLastfmData(result.Item, musicBrainzId, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async Task FetchLastfmData(MusicArtist item, string musicBrainzId, CancellationToken cancellationToken)
|
||||
{
|
||||
// Get artist info with provided id
|
||||
var url = RootUrl + String.Format("method=artist.getInfo&mbid={0}&api_key={1}&format=json", UrlEncode(musicBrainzId), ApiKey);
|
||||
|
||||
LastfmGetArtistResult result;
|
||||
|
||||
using (var json = await _httpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
ResourcePool = LastfmResourcePool,
|
||||
CancellationToken = cancellationToken,
|
||||
EnableHttpCompression = false
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
using (var reader = new StreamReader(json))
|
||||
{
|
||||
var jsonText = await reader.ReadToEndAsync().ConfigureAwait(false);
|
||||
|
||||
// Fix their bad json
|
||||
jsonText = jsonText.Replace("\"#text\"", "\"url\"");
|
||||
|
||||
result = _json.DeserializeFromString<LastfmGetArtistResult>(jsonText);
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null && result.artist != null)
|
||||
{
|
||||
ProcessArtistData(item, result.artist, musicBrainzId);
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessArtistData(MusicArtist artist, LastfmArtist data, string musicBrainzId)
|
||||
{
|
||||
var yearFormed = 0;
|
||||
|
||||
if (data.bio != null)
|
||||
{
|
||||
Int32.TryParse(data.bio.yearformed, out yearFormed);
|
||||
if (!artist.LockedFields.Contains(MetadataFields.Overview))
|
||||
{
|
||||
artist.Overview = (data.bio.content ?? string.Empty).StripHtml();
|
||||
}
|
||||
if (!string.IsNullOrEmpty(data.bio.placeformed) && !artist.LockedFields.Contains(MetadataFields.ProductionLocations))
|
||||
{
|
||||
artist.AddProductionLocation(data.bio.placeformed);
|
||||
}
|
||||
}
|
||||
|
||||
if (yearFormed > 0)
|
||||
{
|
||||
artist.PremiereDate = new DateTime(yearFormed, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
artist.ProductionYear = yearFormed;
|
||||
}
|
||||
|
||||
string imageSize;
|
||||
var url = LastfmHelper.GetImageUrl(data, out imageSize);
|
||||
|
||||
if (!string.IsNullOrEmpty(musicBrainzId) && !string.IsNullOrEmpty(url))
|
||||
{
|
||||
LastfmHelper.SaveImageInfo(_config.ApplicationPaths, _logger, musicBrainzId, url, imageSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes an URL.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private string UrlEncode(string name)
|
||||
{
|
||||
return WebUtility.UrlEncode(name);
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return "last.fm"; }
|
||||
}
|
||||
|
||||
public int Order
|
||||
{
|
||||
get
|
||||
{
|
||||
// After fanart & audiodb
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
public static class LastfmHelper
|
||||
{
|
||||
public static string GetImageUrl(IHasLastFmImages data, out string size)
|
||||
{
|
||||
size = null;
|
||||
|
||||
if (data.image == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var validImages = data.image
|
||||
.Where(i => !string.IsNullOrWhiteSpace(i.url))
|
||||
.ToList();
|
||||
|
||||
var img = validImages
|
||||
.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();
|
||||
|
||||
if (img != null)
|
||||
{
|
||||
size = img.size;
|
||||
return img.url;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void SaveImageInfo(IApplicationPaths appPaths, ILogger logger, string musicBrainzId, string url, string size)
|
||||
{
|
||||
if (appPaths == null)
|
||||
{
|
||||
throw new ArgumentNullException("appPaths");
|
||||
}
|
||||
if (string.IsNullOrEmpty(musicBrainzId))
|
||||
{
|
||||
throw new ArgumentNullException("musicBrainzId");
|
||||
}
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
}
|
||||
|
||||
var cachePath = Path.Combine(appPaths.CachePath, "lastfm", musicBrainzId, "image.txt");
|
||||
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
File.Delete(cachePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(cachePath));
|
||||
File.WriteAllText(cachePath, url + "|" + size);
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// Don't fail if this is unable to write
|
||||
logger.ErrorException("Error saving to {0}", ex, cachePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Implementations.Collections
|
|||
|
||||
public override bool IsHiddenFromUser(User user)
|
||||
{
|
||||
return true;
|
||||
return !user.Configuration.DisplayCollectionsView;
|
||||
}
|
||||
|
||||
public override string CollectionType
|
||||
|
|
|
@ -10,12 +10,12 @@ using MediaBrowser.Controller.Localization;
|
|||
using MediaBrowser.Model.Channels;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Library;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Querying;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Library
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
list.Add(await GetUserView(CollectionType.Games, user, string.Empty, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
if (user.Configuration.DisplayCollectionsView ||
|
||||
if (user.Configuration.DisplayCollectionsView &&
|
||||
recursiveChildren.OfType<BoxSet>().Any())
|
||||
{
|
||||
list.Add(await GetUserView(CollectionType.BoxSets, user, CollectionType.BoxSets, cancellationToken).ConfigureAwait(false));
|
||||
|
|
Loading…
Reference in New Issue
Block a user