From 9a820efde33b7a4cfe1dd3e5c37a2f1beaaec896 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 27 May 2013 12:53:10 -0400 Subject: fixes #280 - MB3 Local metadata fetcher for Music not seeing/using Artist Folder.jpg --- MediaBrowser.Controller/Library/ILibraryManager.cs | 4 +- .../Library/ILibraryPostScanTask.cs | 20 ++++ .../MediaBrowser.Controller.csproj | 2 + .../Providers/ImagesByNameProvider.cs | 9 +- .../Providers/Music/ArtistsPostScanTask.cs | 132 +++++++++++++++++++++ 5 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Controller/Library/ILibraryPostScanTask.cs create mode 100644 MediaBrowser.Controller/Providers/Music/ArtistsPostScanTask.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 90c96c1ee..f5abb8dcd 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -144,12 +144,14 @@ namespace MediaBrowser.Controller.Library /// The intro providers. /// The item comparers. /// The prescan tasks. + /// The postscan tasks. void AddParts(IEnumerable rules, IEnumerable pluginFolders, IEnumerable resolvers, IEnumerable introProviders, IEnumerable itemComparers, - IEnumerable prescanTasks); + IEnumerable prescanTasks, + IEnumerable postscanTasks); /// /// Sorts the specified items. diff --git a/MediaBrowser.Controller/Library/ILibraryPostScanTask.cs b/MediaBrowser.Controller/Library/ILibraryPostScanTask.cs new file mode 100644 index 000000000..694422907 --- /dev/null +++ b/MediaBrowser.Controller/Library/ILibraryPostScanTask.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Library +{ + /// + /// An interface for tasks that run after the media library scan + /// + public interface ILibraryPostScanTask + { + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + Task Run(IProgress progress, CancellationToken cancellationToken); + } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 921e16eed..d3f8ba927 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -73,8 +73,10 @@ + + diff --git a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs index 54a6f3a89..20305006e 100644 --- a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs +++ b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs @@ -155,7 +155,14 @@ namespace MediaBrowser.Controller.Providers { var location = GetLocation(item); - var files = new DirectoryInfo(location).EnumerateFiles("*", SearchOption.TopDirectoryOnly).ToList(); + var directoryInfo = new DirectoryInfo(location); + + if (!directoryInfo.Exists) + { + return null; + } + + var files = directoryInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly).ToList(); var file = files.FirstOrDefault(i => string.Equals(i.Name, filenameWithoutExtension + ".png", StringComparison.OrdinalIgnoreCase)); diff --git a/MediaBrowser.Controller/Providers/Music/ArtistsPostScanTask.cs b/MediaBrowser.Controller/Providers/Music/ArtistsPostScanTask.cs new file mode 100644 index 000000000..67bb35b63 --- /dev/null +++ b/MediaBrowser.Controller/Providers/Music/ArtistsPostScanTask.cs @@ -0,0 +1,132 @@ +using MediaBrowser.Common.Progress; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Entities; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Providers.Music +{ + /// + /// Class ArtistsPostScanTask + /// + public class ArtistsPostScanTask : ILibraryPostScanTask + { + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + /// + /// Initializes a new instance of the class. + /// + /// The library manager. + public ArtistsPostScanTask(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + + /// + /// Runs the specified progress. + /// + /// The progress. + /// The cancellation token. + /// Task. + public async Task Run(IProgress progress, CancellationToken cancellationToken) + { + var allItems = _libraryManager.RootFolder.RecursiveChildren.ToList(); + + var allArtists = await GetAllArtists(allItems).ConfigureAwait(false); + + progress.Report(10); + + var allMusicArtists = allItems.OfType().ToList(); + + var numComplete = 0; + + foreach (var artist in allArtists) + { + var musicArtist = FindMusicArtist(artist, allMusicArtists); + + if (musicArtist != null) + { + artist.Images = new Dictionary(musicArtist.Images); + + artist.BackdropImagePaths = musicArtist.BackdropImagePaths.ToList(); + artist.ScreenshotImagePaths = musicArtist.ScreenshotImagePaths.ToList(); + artist.SetProviderId(MetadataProviders.Musicbrainz, musicArtist.GetProviderId(MetadataProviders.Musicbrainz)); + } + + numComplete++; + double percent = numComplete; + percent /= allArtists.Length; + percent *= 5; + + progress.Report(10 + percent); + } + + var innerProgress = new ActionableProgress(); + + innerProgress.RegisterAction(pct => progress.Report(15 + pct * .85)); + + await _libraryManager.ValidateArtists(cancellationToken, innerProgress).ConfigureAwait(false); + } + + /// + /// Gets all artists. + /// + /// All items. + /// Task{Artist[]}. + private Task GetAllArtists(IEnumerable allItems) + { + var itemsList = allItems.OfType