|
|
@ -4,13 +4,14 @@ using MediaBrowser.Common.Net;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
|
|
using MediaBrowser.Controller.IO;
|
|
|
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
using MediaBrowser.Model.Net;
|
|
|
|
|
|
|
|
using MediaBrowser.Model.Providers;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
@ -139,50 +140,25 @@ namespace MediaBrowser.Providers.Music
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!ConfigurationManager.Configuration.DownloadMusicArtistImages.Art &&
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops &&
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner &&
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo &&
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary &&
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The fanart album provider depends on xml downloaded here, so honor it's settings too
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicAlbumImages.Disc &&
|
|
|
|
|
|
|
|
!ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
|
|
|
return base.NeedsRefreshInternal(item, providerInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override DateTime CompareDate(BaseItem item)
|
|
|
|
protected override bool NeedsRefreshBasedOnCompareDate(BaseItem item, BaseProviderInfo providerInfo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var musicBrainzId = item.GetProviderId(MetadataProviders.Musicbrainz);
|
|
|
|
var musicBrainzId = item.GetProviderId(MetadataProviders.Musicbrainz);
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(musicBrainzId))
|
|
|
|
if (!string.IsNullOrEmpty(musicBrainzId))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Process images
|
|
|
|
// Process images
|
|
|
|
var path = GetArtistDataPath(ConfigurationManager.ApplicationPaths, musicBrainzId);
|
|
|
|
var artistXmlPath = GetArtistDataPath(ConfigurationManager.CommonApplicationPaths, musicBrainzId);
|
|
|
|
|
|
|
|
artistXmlPath = Path.Combine(artistXmlPath, "fanart.xml");
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
var file = new FileInfo(artistXmlPath);
|
|
|
|
{
|
|
|
|
|
|
|
|
var files = new DirectoryInfo(path)
|
|
|
|
|
|
|
|
.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly)
|
|
|
|
|
|
|
|
.Select(i => _fileSystem.GetLastWriteTimeUtc(i))
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (files.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return files.Max();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return !file.Exists || _fileSystem.GetLastWriteTimeUtc(file) > providerInfo.LastRefreshed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return base.CompareDate(item);
|
|
|
|
return base.NeedsRefreshBasedOnCompareDate(item, providerInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -191,22 +167,22 @@ namespace MediaBrowser.Providers.Music
|
|
|
|
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the series data path.
|
|
|
|
/// Gets the artist data path.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="appPaths">The app paths.</param>
|
|
|
|
/// <param name="appPaths">The application paths.</param>
|
|
|
|
/// <param name="musicBrainzArtistId">The music brainz artist id.</param>
|
|
|
|
/// <param name="musicBrainzArtistId">The music brainz artist identifier.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
internal static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId)
|
|
|
|
internal static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var seriesDataPath = Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId);
|
|
|
|
var dataPath = Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId);
|
|
|
|
|
|
|
|
|
|
|
|
return seriesDataPath;
|
|
|
|
return dataPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the series data path.
|
|
|
|
/// Gets the artist data path.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="appPaths">The app paths.</param>
|
|
|
|
/// <param name="appPaths">The application paths.</param>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
internal static string GetArtistDataPath(IApplicationPaths appPaths)
|
|
|
|
internal static string GetArtistDataPath(IApplicationPaths appPaths)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -243,17 +219,9 @@ namespace MediaBrowser.Providers.Music
|
|
|
|
ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo ||
|
|
|
|
ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo ||
|
|
|
|
ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary)
|
|
|
|
ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (File.Exists(xmlPath))
|
|
|
|
var images = await _providerManager.GetAvailableRemoteImages(item, cancellationToken, ManualFanartArtistProvider.ProviderName).ConfigureAwait(false);
|
|
|
|
{
|
|
|
|
|
|
|
|
await FetchFromXml(item, xmlPath, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BaseProviderInfo data;
|
|
|
|
await FetchFromXml(item, images.ToList(), cancellationToken).ConfigureAwait(false);
|
|
|
|
if (!item.ProviderData.TryGetValue(Id, out data))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
data = new BaseProviderInfo();
|
|
|
|
|
|
|
|
item.ProviderData[Id] = data;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
|
SetLastRefreshed(item, DateTime.UtcNow);
|
|
|
@ -296,151 +264,75 @@ namespace MediaBrowser.Providers.Music
|
|
|
|
/// Fetches from XML.
|
|
|
|
/// Fetches from XML.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="item">The item.</param>
|
|
|
|
/// <param name="xmlFilePath">The XML file path.</param>
|
|
|
|
/// <param name="images">The images.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
private async Task FetchFromXml(BaseItem item, string xmlFilePath, CancellationToken cancellationToken)
|
|
|
|
private async Task FetchFromXml(BaseItem item, List<RemoteImageInfo> images , CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var doc = new XmlDocument();
|
|
|
|
|
|
|
|
doc.Load(xmlFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
string path;
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.HasImage(ImageType.Primary))
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.HasImage(ImageType.Logo))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var node =
|
|
|
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Primary);
|
|
|
|
doc.SelectSingleNode("//fanart/music/hdmusiclogos/hdmusiclogo/@url") ??
|
|
|
|
|
|
|
|
doc.SelectSingleNode("//fanart/music/musiclogos/musiclogo/@url");
|
|
|
|
if (image != null)
|
|
|
|
path = node != null ? node.Value : null;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
|
|
|
{
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Logo, null, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sometimes fanart has bad url's in their xml. Nothing we can do here but catch it
|
|
|
|
|
|
|
|
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && item.BackdropImagePaths.Count == 0)
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.HasImage(ImageType.Logo))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url");
|
|
|
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Logo);
|
|
|
|
if (nodes != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var numBackdrops = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode node in nodes)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
path = node.Value;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path) && !item.ContainsImageWithSourceUrl(path))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
numBackdrops++;
|
|
|
|
|
|
|
|
if (numBackdrops >= backdropLimit) break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sometimes fanart has bad url's in their xml. Nothing we can do here but catch it
|
|
|
|
|
|
|
|
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (image != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Logo, null, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.HasImage(ImageType.Art))
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Art && !item.HasImage(ImageType.Art))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var node =
|
|
|
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Art);
|
|
|
|
doc.SelectSingleNode("//fanart/music/hdmusicarts/hdmusicart/@url") ??
|
|
|
|
|
|
|
|
doc.SelectSingleNode("//fanart/music/musicarts/musicart/@url");
|
|
|
|
if (image != null)
|
|
|
|
path = node != null ? node.Value : null;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Art, null, cancellationToken).ConfigureAwait(false);
|
|
|
|
{
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Art, null, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sometimes fanart has bad url's in their xml. Nothing we can do here but catch it
|
|
|
|
|
|
|
|
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.HasImage(ImageType.Banner))
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Banner && !item.HasImage(ImageType.Banner))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var node = doc.SelectSingleNode("//fanart/music/hdmusicbanners/hdmusicbanner/@url") ??
|
|
|
|
var image = images.FirstOrDefault(i => i.Type == ImageType.Banner);
|
|
|
|
doc.SelectSingleNode("//fanart/music/musicbanners/musicbanner/@url");
|
|
|
|
|
|
|
|
path = node != null ? node.Value : null;
|
|
|
|
if (image != null)
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Banner, null, cancellationToken).ConfigureAwait(false);
|
|
|
|
{
|
|
|
|
|
|
|
|
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Banner, null, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sometimes fanart has bad url's in their xml. Nothing we can do here but catch it
|
|
|
|
|
|
|
|
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
// Artist thumbs are actually primary images (they are square/portrait)
|
|
|
|
var backdropLimit = ConfigurationManager.Configuration.MaxBackdrops;
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Primary && !item.HasImage(ImageType.Primary))
|
|
|
|
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops &&
|
|
|
|
|
|
|
|
item.BackdropImagePaths.Count < backdropLimit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var node = doc.SelectSingleNode("//fanart/music/artistthumbs/artistthumb/@url");
|
|
|
|
var numBackdrops = item.BackdropImagePaths.Count;
|
|
|
|
path = node != null ? node.Value : null;
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(path))
|
|
|
|
foreach (var image in images.Where(i => i.Type == ImageType.Backdrop))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
await _providerManager.SaveImage(item, image.Url, FanArtResourcePool, ImageType.Backdrop, numBackdrops, cancellationToken)
|
|
|
|
{
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
await _providerManager.SaveImage(item, path, FanArtResourcePool, ImageType.Primary, null, cancellationToken)
|
|
|
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
numBackdrops++;
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (HttpException ex)
|
|
|
|
if (item.BackdropImagePaths.Count >= backdropLimit) break;
|
|
|
|
{
|
|
|
|
|
|
|
|
// Sometimes fanart has bad url's in their xml. Nothing we can do here but catch it
|
|
|
|
|
|
|
|
if (!ex.StatusCode.HasValue || ex.StatusCode.Value != HttpStatusCode.NotFound)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|