2013-04-10 15:56:36 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-03-04 23:24:41 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-04-10 15:56:36 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Providers.Music
|
|
|
|
|
{
|
|
|
|
|
public class MusicArtistProviderFromJson : BaseMetadataProvider
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the json serializer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The json serializer.</value>
|
|
|
|
|
protected IJsonSerializer JsonSerializer { get; private set; }
|
|
|
|
|
|
|
|
|
|
public MusicArtistProviderFromJson(IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager)
|
|
|
|
|
: base(logManager, configurationManager)
|
|
|
|
|
{
|
|
|
|
|
if (jsonSerializer == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("jsonSerializer");
|
|
|
|
|
}
|
|
|
|
|
JsonSerializer = jsonSerializer;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 05:08:27 +00:00
|
|
|
|
public override Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken)
|
2013-03-04 20:03:36 +00:00
|
|
|
|
{
|
2013-04-15 20:33:43 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, LastfmHelper.LocalArtistMetaFileName));
|
2013-04-28 05:29:27 +00:00
|
|
|
|
if (entry != null)
|
2013-04-15 20:33:43 +00:00
|
|
|
|
{
|
|
|
|
|
// read in our saved meta and pass to processing function
|
2013-04-28 05:29:27 +00:00
|
|
|
|
var data = JsonSerializer.DeserializeFromFile<LastfmArtist>(entry.FullName);
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
LastfmHelper.ProcessArtistData(item, data);
|
2013-03-04 20:03:36 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
item.SetProviderId(MetadataProviders.Musicbrainz, data.mbid);
|
2013-03-04 23:24:41 +00:00
|
|
|
|
|
2013-04-15 20:33:43 +00:00
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
|
return TrueTaskResult;
|
|
|
|
|
}
|
|
|
|
|
return FalseTaskResult;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override MetadataProviderPriority Priority
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return MetadataProviderPriority.First;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Supports(BaseItem item)
|
|
|
|
|
{
|
2013-04-28 16:25:14 +00:00
|
|
|
|
return false;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool RequiresInternet
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
|
{
|
|
|
|
|
if (!item.ResolveArgs.ContainsMetaFileByName(LastfmHelper.LocalArtistMetaFileName))
|
|
|
|
|
{
|
|
|
|
|
return false; // nothing to read
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Need to re-override to jump over intermediate implementation
|
|
|
|
|
return CompareDate(item) > providerInfo.LastRefreshed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Override this to return the date that should be compared to the last refresh date
|
|
|
|
|
/// to determine if this provider should be re-fetched.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
|
/// <returns>DateTime.</returns>
|
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
|
|
|
|
{
|
|
|
|
|
var entry = item.ResolveArgs.GetMetaFileByPath(Path.Combine(item.MetaLocation, LastfmHelper.LocalArtistMetaFileName));
|
2013-04-28 05:29:27 +00:00
|
|
|
|
return entry != null ? entry.LastWriteTimeUtc : DateTime.MinValue;
|
2013-03-04 20:03:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|