mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 13:57:14 -04:00
avoid album level http requests to fanart
This commit is contained in:
parent
8ed35a00aa
commit
9c6f97cf0d
@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
@ -82,7 +83,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
{
|
||||
get
|
||||
{
|
||||
return "12";
|
||||
return "16";
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,9 +106,24 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
return false;
|
||||
}
|
||||
|
||||
// Refresh anytime the parent mbz id changes
|
||||
if (providerInfo.Data != GetComparisonData(item.Parent.GetProviderId(MetadataProviders.Musicbrainz)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.NeedsRefreshInternal(item, providerInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the comparison data.
|
||||
/// </summary>
|
||||
/// <returns>Guid.</returns>
|
||||
private Guid GetComparisonData(string id)
|
||||
{
|
||||
return string.IsNullOrEmpty(id) ? Guid.Empty : id.GetMD5();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
/// </summary>
|
||||
@ -119,67 +135,69 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var album = (MusicAlbum)item;
|
||||
var artistMusicBrainzId = item.Parent.GetProviderId(MetadataProviders.Musicbrainz);
|
||||
|
||||
if (string.IsNullOrEmpty(album.MusicBrainzReleaseGroupId))
|
||||
BaseProviderInfo data;
|
||||
|
||||
if (!item.ProviderData.TryGetValue(Id, out data))
|
||||
{
|
||||
album.MusicBrainzReleaseGroupId = await GetReleaseGroupId(item.GetProviderId(MetadataProviders.Musicbrainz), cancellationToken).ConfigureAwait(false);
|
||||
data = new BaseProviderInfo();
|
||||
item.ProviderData[Id] = data;
|
||||
}
|
||||
|
||||
// If still empty there's nothing more we can do
|
||||
if (string.IsNullOrEmpty(album.MusicBrainzReleaseGroupId))
|
||||
if (!string.IsNullOrEmpty(artistMusicBrainzId))
|
||||
{
|
||||
SetLastRefreshed(item, DateTime.UtcNow);
|
||||
var album = (MusicAlbum)item;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var url = string.Format("http://api.fanart.tv/webservice/album/{0}/{1}/xml/all/1/1", ApiKey, album.MusicBrainzReleaseGroupId);
|
||||
|
||||
var doc = new XmlDocument();
|
||||
|
||||
using (var xml = await HttpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
ResourcePool = FanArtResourcePool,
|
||||
CancellationToken = cancellationToken
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
doc.Load(xml);
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (doc.HasChildNodes)
|
||||
{
|
||||
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Disc && !item.HasImage(ImageType.Disc))
|
||||
if (string.IsNullOrEmpty(album.MusicBrainzReleaseGroupId))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/music/albums/album/cdart/@url");
|
||||
|
||||
var path = node != null ? node.Value : null;
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
Logger.Debug("FanArtProvider getting Disc for " + item.Name);
|
||||
item.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(item, path, DiscFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
album.MusicBrainzReleaseGroupId = await GetReleaseGroupId(item.GetProviderId(MetadataProviders.Musicbrainz), cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary && !item.HasImage(ImageType.Primary))
|
||||
// If still empty there's nothing more we can do
|
||||
if (!string.IsNullOrEmpty(album.MusicBrainzReleaseGroupId))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/music/albums/album/albumcover/@url");
|
||||
var artistXmlPath = FanArtArtistProvider.GetArtistDataPath(ConfigurationManager.CommonApplicationPaths, artistMusicBrainzId);
|
||||
artistXmlPath = Path.Combine(artistXmlPath, "fanart.xml");
|
||||
|
||||
var path = node != null ? node.Value : null;
|
||||
var artistXmlFileInfo = new FileInfo(artistXmlPath);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
if (artistXmlFileInfo.Exists)
|
||||
{
|
||||
Logger.Debug("FanArtProvider getting albumcover for " + item.Name);
|
||||
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PrimaryFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
|
||||
var doc = new XmlDocument();
|
||||
|
||||
doc.Load(artistXmlPath);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Disc && !item.HasImage(ImageType.Disc))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/music/albums/album[@id=\"" + album.MusicBrainzReleaseGroupId + "\"]/cdart/@url");
|
||||
|
||||
var path = node != null ? node.Value : null;
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
item.SetImage(ImageType.Disc, await _providerManager.DownloadAndSaveImage(item, path, DiscFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
|
||||
if (ConfigurationManager.Configuration.DownloadMusicAlbumImages.Primary && !item.HasImage(ImageType.Primary))
|
||||
{
|
||||
var node = doc.SelectSingleNode("//fanart/music/albums/album[@id=\"" + album.MusicBrainzReleaseGroupId + "\"]/albumcover/@url");
|
||||
|
||||
var path = node != null ? node.Value : null;
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
item.SetImage(ImageType.Primary, await _providerManager.DownloadAndSaveImage(item, path, PrimaryFile, ConfigurationManager.Configuration.SaveLocalMeta, FanArtResourcePool, cancellationToken).ConfigureAwait(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.Data = GetComparisonData(artistMusicBrainzId);
|
||||
SetLastRefreshed(item, DateTime.UtcNow);
|
||||
|
||||
return true;
|
||||
|
@ -1,4 +1,8 @@
|
||||
using MediaBrowser.Common.Net;
|
||||
using System.IO;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.Net;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
@ -69,7 +73,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
{
|
||||
get
|
||||
{
|
||||
return "4";
|
||||
return "5";
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,6 +103,41 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
}
|
||||
|
||||
protected readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||
|
||||
/// <summary>
|
||||
/// Gets the series data path.
|
||||
/// </summary>
|
||||
/// <param name="appPaths">The app paths.</param>
|
||||
/// <param name="musicBrainzArtistId">The music brainz artist id.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
internal static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId)
|
||||
{
|
||||
var seriesDataPath = Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId);
|
||||
|
||||
if (!Directory.Exists(seriesDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(seriesDataPath);
|
||||
}
|
||||
|
||||
return seriesDataPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the series data path.
|
||||
/// </summary>
|
||||
/// <param name="appPaths">The app paths.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
internal static string GetArtistDataPath(IApplicationPaths appPaths)
|
||||
{
|
||||
var dataPath = Path.Combine(appPaths.DataPath, "fanart-music");
|
||||
|
||||
if (!Directory.Exists(dataPath))
|
||||
{
|
||||
Directory.CreateDirectory(dataPath);
|
||||
}
|
||||
|
||||
return dataPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches metadata and returns true or false indicating if any work that requires persistence was done
|
||||
@ -113,12 +152,14 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
//var artist = item;
|
||||
|
||||
var url = string.Format(FanArtBaseUrl, ApiKey, item.GetProviderId(MetadataProviders.Musicbrainz));
|
||||
var doc = new XmlDocument();
|
||||
var musicBrainzId = item.GetProviderId(MetadataProviders.Musicbrainz);
|
||||
var url = string.Format(FanArtBaseUrl, ApiKey, musicBrainzId);
|
||||
|
||||
var status = ProviderRefreshStatus.Success;
|
||||
|
||||
var xmlPath = Path.Combine(GetArtistDataPath(ConfigurationManager.ApplicationPaths, musicBrainzId), "fanart.xml");
|
||||
|
||||
using (var xml = await HttpClient.Get(new HttpRequestOptions
|
||||
using (var response = await HttpClient.Get(new HttpRequestOptions
|
||||
{
|
||||
Url = url,
|
||||
ResourcePool = FanArtResourcePool,
|
||||
@ -126,16 +167,22 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
|
||||
}).ConfigureAwait(false))
|
||||
{
|
||||
doc.Load(xml);
|
||||
using (var xmlFileStream = new FileStream(xmlPath, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
|
||||
{
|
||||
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
var doc = new XmlDocument();
|
||||
doc.Load(xmlPath);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (doc.HasChildNodes)
|
||||
{
|
||||
string path;
|
||||
var hd = ConfigurationManager.Configuration.DownloadHDFanArt ? "hd" : "";
|
||||
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.ResolveArgs.ContainsMetaFileByName(LogoFile))
|
||||
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Logo && !item.HasImage(ImageType.Logo))
|
||||
{
|
||||
var node =
|
||||
doc.SelectSingleNode("//fanart/music/musiclogos/" + hd + "musiclogo/@url") ??
|
||||
@ -149,7 +196,7 @@ namespace MediaBrowser.Controller.Providers.Music
|
||||
}
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && !item.ResolveArgs.ContainsMetaFileByName(BackdropFile))
|
||||
if (ConfigurationManager.Configuration.DownloadMusicArtistImages.Backdrops && item.BackdropImagePaths.Count == 0)
|
||||
{
|
||||
var nodes = doc.SelectNodes("//fanart/music/artistbackgrounds//@url");
|
||||
if (nodes != null)
|
||||
|
Loading…
Reference in New Issue
Block a user