diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-05-24 20:42:12 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-05-24 20:42:12 -0400 |
| commit | 77dc47df0c2b7e3f81ebd2c48c4cf84afb518612 (patch) | |
| tree | 9bc13dcd0ab41a3e905fb4bd258b7dff33e5b7ea /MediaBrowser.Providers/Music | |
| parent | 6bb6e0ff849e09fa39281adf6001599c0a73f979 (diff) | |
deprecate provider options
Diffstat (limited to 'MediaBrowser.Providers/Music')
4 files changed, 2 insertions, 262 deletions
diff --git a/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs b/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs index 5b3bd87db0..b47e8df5ae 100644 --- a/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/FanArtAlbumProvider.cs @@ -19,7 +19,7 @@ using MediaBrowser.Model.Serialization; namespace MediaBrowser.Providers.Music { - public class FanartAlbumProvider : IRemoteImageProvider, IHasItemChangeMonitor, IHasOrder + public class FanartAlbumProvider : IRemoteImageProvider, IHasOrder { private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IServerConfigurationManager _config; @@ -212,34 +212,5 @@ namespace MediaBrowser.Providers.Music ResourcePool = FanartArtistProvider.Current.FanArtResourcePool }); } - - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) - { - var options = FanartSeriesProvider.Current.GetFanartOptions(); - if (!options.EnableAutomaticUpdates) - { - return false; - } - - var album = (MusicAlbum)item; - var artist = album.MusicArtist; - - if (artist != null) - { - var artistMusicBrainzId = artist.GetProviderId(MetadataProviders.MusicBrainzArtist); - - if (!String.IsNullOrEmpty(artistMusicBrainzId)) - { - // Process images - var artistJsonPath = FanartArtistProvider.GetArtistJsonPath(_config.CommonApplicationPaths, artistMusicBrainzId); - - var fileInfo = _fileSystem.GetFileInfo(artistJsonPath); - - return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > item.DateLastRefreshed; - } - } - - return false; - } } } diff --git a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs index 37b51da5a3..9b18ac5e92 100644 --- a/MediaBrowser.Providers/Music/FanArtArtistProvider.cs +++ b/MediaBrowser.Providers/Music/FanArtArtistProvider.cs @@ -22,7 +22,7 @@ using MediaBrowser.Model.Serialization; namespace MediaBrowser.Providers.Music { - public class FanartArtistProvider : IRemoteImageProvider, IHasItemChangeMonitor, IHasOrder + public class FanartArtistProvider : IRemoteImageProvider, IHasOrder { internal readonly SemaphoreSlim FanArtResourcePool = new SemaphoreSlim(3, 3); internal const string ApiKey = "5c6b04c68e904cfed1e6cbc9a9e683d4"; @@ -207,29 +207,6 @@ namespace MediaBrowser.Providers.Music }); } - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) - { - var options = FanartSeriesProvider.Current.GetFanartOptions(); - if (!options.EnableAutomaticUpdates) - { - return false; - } - - var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist); - - if (!String.IsNullOrEmpty(id)) - { - // Process images - var artistJsonPath = GetArtistJsonPath(_config.CommonApplicationPaths, id); - - var fileInfo = _fileSystem.GetFileInfo(artistJsonPath); - - return !fileInfo.Exists || _fileSystem.GetLastWriteTimeUtc(fileInfo) > item.DateLastRefreshed; - } - - return false; - } - private readonly Task _cachedTask = Task.FromResult(true); internal Task EnsureArtistJson(string musicBrainzId, CancellationToken cancellationToken) { diff --git a/MediaBrowser.Providers/Music/FanArtUpdatesPostScanTask.cs b/MediaBrowser.Providers/Music/FanArtUpdatesPostScanTask.cs deleted file mode 100644 index 3b829af9eb..0000000000 --- a/MediaBrowser.Providers/Music/FanArtUpdatesPostScanTask.cs +++ /dev/null @@ -1,203 +0,0 @@ -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Logging; -using MediaBrowser.Model.Serialization; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using CommonIO; -using MediaBrowser.Providers.TV; - -namespace MediaBrowser.Providers.Music -{ - class FanartUpdatesPostScanTask : ILibraryPostScanTask - { - private const string UpdatesUrl = "https://api.fanart.tv/webservice/newmusic/{0}/{1}/"; - - /// <summary> - /// The _HTTP client - /// </summary> - private readonly IHttpClient _httpClient; - /// <summary> - /// The _logger - /// </summary> - private readonly ILogger _logger; - /// <summary> - /// The _config - /// </summary> - private readonly IServerConfigurationManager _config; - private readonly IJsonSerializer _jsonSerializer; - private readonly IFileSystem _fileSystem; - - private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); - - public FanartUpdatesPostScanTask(IJsonSerializer jsonSerializer, IServerConfigurationManager config, ILogger logger, IHttpClient httpClient, IFileSystem fileSystem) - { - _jsonSerializer = jsonSerializer; - _config = config; - _logger = logger; - _httpClient = httpClient; - _fileSystem = fileSystem; - } - - /// <summary> - /// Runs the specified progress. - /// </summary> - /// <param name="progress">The progress.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) - { - var options = FanartSeriesProvider.Current.GetFanartOptions(); - - if (!options.EnableAutomaticUpdates) - { - progress.Report(100); - return; - } - - var path = FanartArtistProvider.GetArtistDataPath(_config.CommonApplicationPaths); - - _fileSystem.CreateDirectory(path); - - var timestampFile = Path.Combine(path, "time.txt"); - - var timestampFileInfo = _fileSystem.GetFileInfo(timestampFile); - - // Don't check for updates every single time - if (timestampFileInfo.Exists && (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(timestampFileInfo)).TotalDays < 3) - { - return; - } - - // Find out the last time we queried for updates - var lastUpdateTime = timestampFileInfo.Exists ? _fileSystem.ReadAllText(timestampFile, Encoding.UTF8) : string.Empty; - - var existingDirectories = Directory.EnumerateDirectories(path).Select(Path.GetFileName).ToList(); - - // If this is our first time, don't do any updates and just record the timestamp - if (!string.IsNullOrEmpty(lastUpdateTime)) - { - var artistsToUpdate = await GetArtistIdsToUpdate(existingDirectories, lastUpdateTime, options, cancellationToken).ConfigureAwait(false); - - progress.Report(5); - - await UpdateArtists(artistsToUpdate, progress, cancellationToken).ConfigureAwait(false); - } - - var newUpdateTime = Convert.ToInt64(DateTimeToUnixTimestamp(DateTime.UtcNow)).ToString(UsCulture); - - _fileSystem.WriteAllText(timestampFile, newUpdateTime, Encoding.UTF8); - - progress.Report(100); - } - - /// <summary> - /// Gets the artist ids to update. - /// </summary> - /// <param name="existingArtistIds">The existing series ids.</param> - /// <param name="lastUpdateTime">The last update time.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task{IEnumerable{System.String}}.</returns> - private async Task<IEnumerable<string>> GetArtistIdsToUpdate(IEnumerable<string> existingArtistIds, string lastUpdateTime, FanartOptions options, CancellationToken cancellationToken) - { - var url = string.Format(UpdatesUrl, FanartArtistProvider.ApiKey, lastUpdateTime); - - if (!string.IsNullOrWhiteSpace(options.UserApiKey)) - { - url += "&client_key=" + options.UserApiKey; - } - - // First get last time - using (var stream = await _httpClient.Get(new HttpRequestOptions - { - Url = url, - CancellationToken = cancellationToken, - EnableHttpCompression = true, - ResourcePool = FanartArtistProvider.Current.FanArtResourcePool - - }).ConfigureAwait(false)) - { - // If empty fanart will return a string of "null", rather than an empty list - using (var reader = new StreamReader(stream)) - { - var json = await reader.ReadToEndAsync().ConfigureAwait(false); - - if (string.Equals(json, "null", StringComparison.OrdinalIgnoreCase)) - { - return new List<string>(); - } - - var existingDictionary = existingArtistIds.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); - - var updates = _jsonSerializer.DeserializeFromString<List<FanArtUpdate>>(json); - - return updates.Select(i => i.id).Where(existingDictionary.ContainsKey); - } - } - } - - /// <summary> - /// Updates the artists. - /// </summary> - /// <param name="idList">The id list.</param> - /// <param name="progress">The progress.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - private async Task UpdateArtists(IEnumerable<string> idList, IProgress<double> progress, CancellationToken cancellationToken) - { - var list = idList.ToList(); - var numComplete = 0; - - foreach (var id in list) - { - await UpdateArtist(id, cancellationToken).ConfigureAwait(false); - - numComplete++; - double percent = numComplete; - percent /= list.Count; - percent *= 95; - - progress.Report(percent + 5); - } - } - - /// <summary> - /// Updates the artist. - /// </summary> - /// <param name="musicBrainzId">The musicBrainzId.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - private Task UpdateArtist(string musicBrainzId, CancellationToken cancellationToken) - { - _logger.Info("Updating artist " + musicBrainzId); - - return FanartArtistProvider.Current.DownloadArtistJson(musicBrainzId, cancellationToken); - } - - /// <summary> - /// Dates the time to unix timestamp. - /// </summary> - /// <param name="dateTime">The date time.</param> - /// <returns>System.Double.</returns> - private static double DateTimeToUnixTimestamp(DateTime dateTime) - { - return (dateTime - new DateTime(1970, 1, 1).ToUniversalTime()).TotalSeconds; - } - - public class FanArtUpdate - { - public string id { get; set; } - public string name { get; set; } - public string new_images { get; set; } - public string total_images { get; set; } - } - } -} diff --git a/MediaBrowser.Providers/Music/MovieDbMusicVideoProvider.cs b/MediaBrowser.Providers/Music/MovieDbMusicVideoProvider.cs index d031b3d6b2..88689dd5a3 100644 --- a/MediaBrowser.Providers/Music/MovieDbMusicVideoProvider.cs +++ b/MediaBrowser.Providers/Music/MovieDbMusicVideoProvider.cs @@ -27,11 +27,6 @@ namespace MediaBrowser.Providers.Music get { return MovieDbProvider.Current.Name; } } - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) - { - return MovieDbProvider.Current.HasChanged(item); - } - public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken) { throw new NotImplementedException(); |
