From 5c3fcaf049305b141c0f196b3267fa539a1061fb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 6 Sep 2013 13:26:56 -0400 Subject: [PATCH] further improve last fm images --- .../ImageFromMediaLocationProvider.cs | 20 ++++++++++--------- .../Music/LastfmAlbumProvider.cs | 12 +++++++++-- .../Music/LastfmArtistProvider.cs | 2 +- .../Music/LastfmBaseProvider.cs | 2 +- MediaBrowser.Providers/Music/LastfmHelper.cs | 5 ++++- .../EpisodeImageFromMediaLocationProvider.cs | 10 ++-------- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/MediaBrowser.Providers/ImageFromMediaLocationProvider.cs b/MediaBrowser.Providers/ImageFromMediaLocationProvider.cs index dc8c30bc5..176ddce9b 100644 --- a/MediaBrowser.Providers/ImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Providers/ImageFromMediaLocationProvider.cs @@ -136,13 +136,11 @@ namespace MediaBrowser.Providers private void ValidateImages(BaseItem item, ItemResolveArgs args) { // Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below - var deletedKeys = item.Images.ToList().Where(image => - { - var path = image.Value; - - return IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null; - - }).Select(i => i.Key).ToList(); + var deletedKeys = item.Images + .ToList() + .Where(image => !File.Exists(image.Value)) + .Select(i => i.Key) + .ToList(); // Now remove them from the dictionary foreach (var key in deletedKeys) @@ -159,7 +157,9 @@ namespace MediaBrowser.Providers private void ValidateBackdrops(BaseItem item, ItemResolveArgs args) { // Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below - var deletedImages = item.BackdropImagePaths.Where(path => IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null).ToList(); + var deletedImages = item.BackdropImagePaths + .Where(path => !File.Exists(path)) + .ToList(); // Now remove them from the dictionary foreach (var path in deletedImages) @@ -176,7 +176,9 @@ namespace MediaBrowser.Providers private void ValidateScreenshots(BaseItem item, ItemResolveArgs args) { // Only validate paths from the same directory - need to copy to a list because we are going to potentially modify the collection below - var deletedImages = item.ScreenshotImagePaths.Where(path => IsInMetaLocation(item, path) && args.GetMetaFileByPath(path) == null).ToList(); + var deletedImages = item.ScreenshotImagePaths + .Where(path => !File.Exists(path)) + .ToList(); // Now remove them from the dictionary foreach (var path in deletedImages) diff --git a/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs b/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs index 9ed1ee333..1365d8764 100644 --- a/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/LastfmAlbumProvider.cs @@ -1,5 +1,4 @@ -using System.IO; -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -10,6 +9,7 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MoreLinq; using System; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -40,6 +40,14 @@ namespace MediaBrowser.Providers.Music get { return MetadataProviderPriority.Third; } } + protected override string ProviderVersion + { + get + { + return "8"; + } + } + private bool HasAltMeta(BaseItem item) { return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName("album.xml"); diff --git a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs index a65cecb88..7d1cb715f 100644 --- a/MediaBrowser.Providers/Music/LastfmArtistProvider.cs +++ b/MediaBrowser.Providers/Music/LastfmArtistProvider.cs @@ -58,7 +58,7 @@ namespace MediaBrowser.Providers.Music { get { - return "6"; + return "8"; } } diff --git a/MediaBrowser.Providers/Music/LastfmBaseProvider.cs b/MediaBrowser.Providers/Music/LastfmBaseProvider.cs index 82fc2e241..0efe65213 100644 --- a/MediaBrowser.Providers/Music/LastfmBaseProvider.cs +++ b/MediaBrowser.Providers/Music/LastfmBaseProvider.cs @@ -47,7 +47,7 @@ namespace MediaBrowser.Providers.Music { get { - return "5"; + return "8"; } } diff --git a/MediaBrowser.Providers/Music/LastfmHelper.cs b/MediaBrowser.Providers/Music/LastfmHelper.cs index f48874350..ae849b418 100644 --- a/MediaBrowser.Providers/Music/LastfmHelper.cs +++ b/MediaBrowser.Providers/Music/LastfmHelper.cs @@ -54,8 +54,11 @@ namespace MediaBrowser.Providers.Music return null; } - var img = data.image + 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)) ?? diff --git a/MediaBrowser.Providers/TV/EpisodeImageFromMediaLocationProvider.cs b/MediaBrowser.Providers/TV/EpisodeImageFromMediaLocationProvider.cs index 8eb01a143..896b32f6f 100644 --- a/MediaBrowser.Providers/TV/EpisodeImageFromMediaLocationProvider.cs +++ b/MediaBrowser.Providers/TV/EpisodeImageFromMediaLocationProvider.cs @@ -4,11 +4,11 @@ using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Logging; using System; using System.IO; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Model.Logging; namespace MediaBrowser.Providers.TV { @@ -115,13 +115,7 @@ namespace MediaBrowser.Providers.TV return; } - // Only validate images in the season/metadata folder - if (!string.Equals(Path.GetDirectoryName(path), metadataFolderPath, StringComparison.OrdinalIgnoreCase)) - { - return; - } - - if (episode.Parent.ResolveArgs.GetMetaFileByPath(path) == null) + if (!File.Exists(path)) { episode.PrimaryImagePath = null; }