From 22fc552fc0f67f2ea6cb6125b154dcfca150d5c7 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Aug 2016 16:25:09 -0400 Subject: [PATCH 1/5] remove paper-fab --- .../LiveTv/LiveTvManager.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 26ec599fa4..09d156661d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -133,7 +133,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv void service_DataSourceChanged(object sender, EventArgs e) { - _taskManager.CancelIfRunningAndQueue(); + if (!_isDisposed) + { + _taskManager.CancelIfRunningAndQueue(); + } } public async Task> GetInternalChannels(LiveTvChannelQuery query, CancellationToken cancellationToken) @@ -1238,7 +1241,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var programs = new List(); var channels = new List(); - var guideDays = GetGuideDays(list.Count); + var guideDays = GetGuideDays(); _logger.Info("Refreshing guide with {0} days of guide data", guideDays); @@ -1326,7 +1329,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } private const int MaxGuideDays = 14; - private double GetGuideDays(int channelCount) + private double GetGuideDays() { var config = GetConfiguration(); @@ -1335,13 +1338,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return Math.Max(1, Math.Min(config.GuideDays.Value, MaxGuideDays)); } - var programsPerDay = channelCount * 48; - - const int maxPrograms = 24000; - - var days = Math.Round((double)maxPrograms / programsPerDay); - - return Math.Max(3, Math.Min(days, MaxGuideDays)); + return 7; } private async Task>> GetChannels(ILiveTvService service, CancellationToken cancellationToken) @@ -2309,6 +2306,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv } private readonly object _disposeLock = new object(); + private bool _isDisposed = false; /// /// Releases unmanaged and - optionally - managed resources. /// @@ -2317,6 +2315,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv { if (dispose) { + _isDisposed = true; + lock (_disposeLock) { foreach (var stream in _openStreams.Values.ToList()) From 407d82ea11383f55d2187a69c9711ee7511ee0e3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Aug 2016 16:35:11 -0400 Subject: [PATCH 2/5] support mp4 subtitles --- MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs index 44a0f264da..f37e223ded 100644 --- a/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs +++ b/MediaBrowser.MediaEncoding/Probing/ProbeResultNormalizer.cs @@ -398,7 +398,8 @@ namespace MediaBrowser.MediaEncoding.Probing // These are mp4 chapters if (string.Equals(streamInfo.codec_name, "mov_text", StringComparison.OrdinalIgnoreCase)) { - return null; + // Edit: but these are also sometimes subtitles? + //return null; } var stream = new MediaStream From 23da61281ee108954de9799761fa9c78dc4547ce Mon Sep 17 00:00:00 2001 From: softworkz Date: Fri, 5 Aug 2016 23:15:48 +0200 Subject: [PATCH 3/5] Reduced compiler warnings. No functional changes (except MediaEncoder.cs and AutomaticRestartEntryPoint.cs) --- MediaBrowser.Api/ApiEntryPoint.cs | 4 ++-- MediaBrowser.Api/Playback/BaseStreamingService.cs | 2 +- MediaBrowser.Api/PluginService.cs | 2 +- MediaBrowser.Common/Plugins/BasePlugin.cs | 2 +- MediaBrowser.LocalMetadata/BaseXmlProvider.cs | 2 +- MediaBrowser.LocalMetadata/Providers/SeriesXmlProvider.cs | 2 +- MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs | 2 +- .../Connect/ConnectManager.cs | 2 +- MediaBrowser.Server.Implementations/Dto/DtoService.cs | 2 +- .../EntryPoints/ActivityLogEntryPoint.cs | 2 +- .../EntryPoints/ExternalPortForwarding.cs | 2 +- .../EntryPoints/UserDataChangeNotifier.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 2 +- .../HttpServer/RangeRequestWriter.cs | 2 +- MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs | 4 ++-- .../LiveTv/EmbyTV/ItemDataProvider.cs | 2 +- .../LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs | 2 +- .../LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs | 2 +- .../Notifications/SqliteNotificationsRepository.cs | 2 +- MediaBrowser.Server.Startup.Common/ApplicationHost.cs | 6 +++--- 20 files changed, 24 insertions(+), 24 deletions(-) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 87fa3d46ca..dbc1179e22 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -559,13 +559,13 @@ namespace MediaBrowser.Api { } - catch (IOException ex) + catch (IOException) { //Logger.ErrorException("Error deleting partial stream file(s) {0}", ex, path); DeletePartialStreamFiles(path, jobType, retryCount + 1, 500); } - catch (Exception ex) + catch { //Logger.ErrorException("Error deleting partial stream file(s) {0}", ex, path); } diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index ab73aabe43..a5f78420c7 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1080,7 +1080,7 @@ namespace MediaBrowser.Api.Playback //process.BeginOutputReadLine(); // Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback - Task.Run(() => StartStreamingLog(transcodingJob, state, process.StandardError.BaseStream, state.LogFileStream)); + var task = Task.Run(() => StartStreamingLog(transcodingJob, state, process.StandardError.BaseStream, state.LogFileStream)); // Wait for the file to exist before proceeeding while (!FileSystem.FileExists(state.WaitForPath ?? outputPath) && !transcodingJob.HasExited) diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs index 3bf70715fb..7ad69fd041 100644 --- a/MediaBrowser.Api/PluginService.cs +++ b/MediaBrowser.Api/PluginService.cs @@ -227,7 +227,7 @@ namespace MediaBrowser.Api .ToList(); } } - catch (Exception ex) + catch { //Logger.ErrorException("Error getting plugin list", ex); // Play it safe here diff --git a/MediaBrowser.Common/Plugins/BasePlugin.cs b/MediaBrowser.Common/Plugins/BasePlugin.cs index a0716137b9..b75accf9b0 100644 --- a/MediaBrowser.Common/Plugins/BasePlugin.cs +++ b/MediaBrowser.Common/Plugins/BasePlugin.cs @@ -211,7 +211,7 @@ namespace MediaBrowser.Common.Plugins { return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); } - catch (Exception ex) + catch { return (TConfigurationType)Activator.CreateInstance(typeof(TConfigurationType)); } diff --git a/MediaBrowser.LocalMetadata/BaseXmlProvider.cs b/MediaBrowser.LocalMetadata/BaseXmlProvider.cs index 0289ffb083..f23559e4be 100644 --- a/MediaBrowser.LocalMetadata/BaseXmlProvider.cs +++ b/MediaBrowser.LocalMetadata/BaseXmlProvider.cs @@ -75,7 +75,7 @@ namespace MediaBrowser.LocalMetadata } } - public int Order + public virtual int Order { get { diff --git a/MediaBrowser.LocalMetadata/Providers/SeriesXmlProvider.cs b/MediaBrowser.LocalMetadata/Providers/SeriesXmlProvider.cs index 8f9d21eae8..0893f192fa 100644 --- a/MediaBrowser.LocalMetadata/Providers/SeriesXmlProvider.cs +++ b/MediaBrowser.LocalMetadata/Providers/SeriesXmlProvider.cs @@ -31,7 +31,7 @@ namespace MediaBrowser.LocalMetadata.Providers return directoryService.GetFile(Path.Combine(info.Path, "series.xml")); } - public int Order + public override int Order { get { diff --git a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs index d7ef493c2c..71306e0ec0 100644 --- a/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs +++ b/MediaBrowser.MediaEncoding/Encoder/FontConfigLoader.cs @@ -58,7 +58,7 @@ namespace MediaBrowser.MediaEncoding.Encoder else { // Kick this off, but no need to wait on it - Task.Run(async () => + var task = Task.Run(async () => { await DownloadFontFile(fontsDirectory, fontFilename, new Progress()).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs index 24750de94c..4e913cf994 100644 --- a/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs +++ b/MediaBrowser.Server.Implementations/Connect/ConnectManager.cs @@ -151,7 +151,7 @@ namespace MediaBrowser.Server.Implementations.Connect { DiscoveredWanIpAddress = address; - UpdateConnectInfo(); + var task = UpdateConnectInfo(); } private async Task UpdateConnectInfo() diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 779afdcf27..cc165da6a7 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1620,7 +1620,7 @@ namespace MediaBrowser.Server.Implementations.Dto { size = _imageProcessor.GetImageSize(imageInfo); } - catch (Exception ex) + catch { //_logger.ErrorException("Failed to determine primary image aspect ratio for {0}", ex, path); return null; diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs index 46ddf3dd8c..a36583a412 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ActivityLogEntryPoint.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints private readonly IInstallationManager _installationManager; //private readonly ILogManager _logManager; - private readonly ILogger _logger; + //private readonly ILogger _logger; private readonly ISessionManager _sessionManager; private readonly ITaskManager _taskManager; private readonly IActivityManager _activityManager; diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index 64e3c56a63..280bec65ba 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints CreateRules(device); } - catch (Exception ex) + catch { // I think it could be a good idea to log the exception because // you are using permanent portmapping here (never expire) and that means that next time diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs b/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs index b616b7761a..2bb0101330 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UserDataChangeNotifier.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints var changes = _changedItems.ToList(); _changedItems.Clear(); - SendNotifications(changes, CancellationToken.None); + var task = SendNotifications(changes, CancellationToken.None); if (UpdateTimer != null) { diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 4121c5e5e6..5cf0a246fe 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -251,7 +251,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer httpRes.Close(); } - catch (Exception errorEx) + catch { //_logger.ErrorException("Error this.ProcessRequest(context)(Exception while writing error to the response)", errorEx); } diff --git a/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs index 71cd20743a..488c630fe4 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs @@ -191,7 +191,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer } } } - catch (IOException ex) + catch (IOException) { throw; } diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index a36eae8d22..ee8ab7c254 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -55,8 +55,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV public static EmbyTV Current; - public event EventHandler DataSourceChanged; - public event EventHandler RecordingStatusChanged; + public event EventHandler DataSourceChanged { add { } remove { } } + public event EventHandler RecordingStatusChanged { add { } remove { } } private readonly ConcurrentDictionary _activeRecordings = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs index 79b26468e6..7fe271bea4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/ItemDataProvider.cs @@ -52,7 +52,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV catch (FileNotFoundException) { } - catch (DirectoryNotFoundException ex) + catch (DirectoryNotFoundException) { } catch (IOException ex) diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index 69b6fb5a94..fd4775938a 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -431,7 +431,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun list.Add(await GetMediaSource(info, hdhrId, "mobile").ConfigureAwait(false)); } } - catch (Exception ex) + catch { } diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs index 71b3f8a184..0f8682b7cc 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs @@ -649,7 +649,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp #region Public Events - public event PropertyChangedEventHandler PropertyChanged; + ////public event PropertyChangedEventHandler PropertyChanged; #endregion diff --git a/MediaBrowser.Server.Implementations/Notifications/SqliteNotificationsRepository.cs b/MediaBrowser.Server.Implementations/Notifications/SqliteNotificationsRepository.cs index be8c6d48d6..f30ba3e542 100644 --- a/MediaBrowser.Server.Implementations/Notifications/SqliteNotificationsRepository.cs +++ b/MediaBrowser.Server.Implementations/Notifications/SqliteNotificationsRepository.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Server.Implementations.Notifications public event EventHandler NotificationAdded; public event EventHandler NotificationsMarkedRead; - public event EventHandler NotificationUpdated; + ////public event EventHandler NotificationUpdated; public async Task Initialize() { diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 3f1f98cd00..ce99f0a240 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -606,7 +606,7 @@ namespace MediaBrowser.Server.Startup.Common { return new ImageMagickEncoder(LogManager.GetLogger("ImageMagick"), ApplicationPaths, HttpClient, FileSystemManager, ServerConfigurationManager); } - catch (Exception ex) + catch { Logger.Error("Error loading ImageMagick. Will revert to GDI."); } @@ -616,7 +616,7 @@ namespace MediaBrowser.Server.Startup.Common { return new GDIImageEncoder(FileSystemManager, LogManager.GetLogger("GDI")); } - catch (Exception ex) + catch { Logger.Error("Error loading GDI. Will revert to NullImageEncoder."); } @@ -1412,7 +1412,7 @@ namespace MediaBrowser.Server.Startup.Common { return new Uri(externalDns).Host; } - catch (Exception e) + catch { return externalDns; } From 319a956b3870e162b3072b52ea8c7310d5091bc6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 6 Aug 2016 00:38:01 -0400 Subject: [PATCH 4/5] update validators --- MediaBrowser.Api/VideosService.cs | 18 +++++++--- .../Library/ILibraryManager.cs | 1 + .../Persistence/IItemRepository.cs | 1 + .../Library/LibraryManager.cs | 11 ++++++ .../Library/Validators/ArtistsValidator.cs | 34 +++++++++++-------- .../Library/Validators/GameGenresValidator.cs | 17 +++++----- .../Library/Validators/GenresValidator.cs | 17 +++++----- .../Validators/MusicGenresValidator.cs | 18 +++++----- .../Library/Validators/StudiosValidator.cs | 16 ++++----- .../Persistence/SqliteItemRepository.cs | 30 ++++++++++------ 10 files changed, 99 insertions(+), 64 deletions(-) diff --git a/MediaBrowser.Api/VideosService.cs b/MediaBrowser.Api/VideosService.cs index c8dbb7bb26..4a5eb1eab7 100644 --- a/MediaBrowser.Api/VideosService.cs +++ b/MediaBrowser.Api/VideosService.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Model.Dto; namespace MediaBrowser.Api { @@ -81,11 +82,18 @@ namespace MediaBrowser.Api var dtoOptions = GetDtoOptions(request); - var video = (Video)item; - - var items = video.GetAdditionalParts() - .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video)) - .ToArray(); + var video = item as Video; + BaseItemDto[] items; + if (video != null) + { + items = video.GetAdditionalParts() + .Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, video)) + .ToArray(); + } + else + { + items = new BaseItemDto[] { }; + } var result = new ItemsResult { diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 70bd3f081c..ff7f2fe678 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -562,5 +562,6 @@ namespace MediaBrowser.Controller.Library QueryResult> GetStudios(InternalItemsQuery query); QueryResult> GetArtists(InternalItemsQuery query); QueryResult> GetAlbumArtists(InternalItemsQuery query); + QueryResult> GetAllArtists(InternalItemsQuery query); } } \ No newline at end of file diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index 78138999c5..437f0e157a 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -169,6 +169,7 @@ namespace MediaBrowser.Controller.Persistence QueryResult> GetStudios(InternalItemsQuery query); QueryResult> GetArtists(InternalItemsQuery query); QueryResult> GetAlbumArtists(InternalItemsQuery query); + QueryResult> GetAllArtists(InternalItemsQuery query); } } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 7af495f5a0..055fde504b 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1385,6 +1385,17 @@ namespace MediaBrowser.Server.Implementations.Library return ItemRepository.GetMusicGenres(query); } + public QueryResult> GetAllArtists(InternalItemsQuery query) + { + if (query.User != null) + { + AddUserToQuery(query, query.User); + } + + SetTopParentOrAncestorIds(query); + return ItemRepository.GetAllArtists(query); + } + public QueryResult> GetArtists(InternalItemsQuery query) { if (query.User != null) diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index 2b68f98caf..353be1a44f 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Server.Implementations.Library.Validators { @@ -43,36 +44,39 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { - var allSongs = _libraryManager.RootFolder - .GetRecursiveChildren(i => !i.IsFolder && i is IHasArtist) - .Cast() + var items = _libraryManager.GetAllArtists(new InternalItemsQuery()) + .Items + .Select(i => i.Item1) .ToList(); - var allArtists = _libraryManager.GetArtists(allSongs).ToList(); - var numComplete = 0; - var numArtists = allArtists.Count; + var count = items.Count; - foreach (var artistItem in allArtists) + foreach (var item in items) { - cancellationToken.ThrowIfCancellationRequested(); - try { - await artistItem.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } - catch (IOException ex) + catch (OperationCanceledException) { - _logger.ErrorException("Error validating Artist {0}", ex, artistItem.Name); + // Don't clutter the log + break; + } + catch (Exception ex) + { + _logger.ErrorException("Error refreshing {0}", ex, item.Name); } - // Update progress numComplete++; double percent = numComplete; - percent /= numArtists; + percent /= count; + percent *= 100; - progress.Report(100 * percent); + progress.Report(percent); } + + progress.Report(100); } } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs index a149da6510..72864790b8 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GameGenresValidator.cs @@ -34,21 +34,22 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { - var items = _libraryManager.RootFolder.GetRecursiveChildren(i => i is Game) - .SelectMany(i => i.Genres) - .DistinctNames() + var items = _libraryManager.GetGameGenres(new InternalItemsQuery + { + IncludeItemTypes = new[] { typeof(Game).Name } + }) + .Items + .Select(i => i.Item1) .ToList(); var numComplete = 0; var count = items.Count; - foreach (var name in items) + foreach (var item in items) { try { - var itemByName = _libraryManager.GetGameGenre(name); - - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -57,7 +58,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error refreshing {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, item.Name); } numComplete++; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs index fac5cfc356..6a62d7fe47 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/GenresValidator.cs @@ -35,21 +35,22 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { - var items = _libraryManager.RootFolder.GetRecursiveChildren(i => !(i is IHasMusicGenres) && !(i is Game)) - .SelectMany(i => i.Genres) - .DistinctNames() + var items = _libraryManager.GetGenres(new InternalItemsQuery + { + ExcludeItemTypes = new[] { typeof(Audio).Name, typeof(MusicArtist).Name, typeof(MusicAlbum).Name, typeof(MusicVideo).Name, typeof(Game).Name } + }) + .Items + .Select(i => i.Item1) .ToList(); var numComplete = 0; var count = items.Count; - foreach (var name in items) + foreach (var item in items) { try { - var itemByName = _libraryManager.GetGenre(name); - - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -58,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error refreshing {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, item.Name); } numComplete++; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs index 81433e5b32..2668d84e95 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/MusicGenresValidator.cs @@ -5,6 +5,7 @@ using System; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Server.Implementations.Library.Validators { @@ -34,21 +35,22 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { - var items = _libraryManager.RootFolder.GetRecursiveChildren(i => i is IHasMusicGenres) - .SelectMany(i => i.Genres) - .DistinctNames() + var items = _libraryManager.GetMusicGenres(new InternalItemsQuery + { + IncludeItemTypes = new[] { typeof(Audio).Name, typeof(MusicArtist).Name, typeof(MusicAlbum).Name, typeof(MusicVideo).Name } + }) + .Items + .Select(i => i.Item1) .ToList(); var numComplete = 0; var count = items.Count; - foreach (var name in items) + foreach (var item in items) { try { - var itemByName = _libraryManager.GetMusicGenre(name); - - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -57,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error refreshing {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, item.Name); } numComplete++; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs index 259878566b..722b74891e 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/StudiosValidator.cs @@ -1,10 +1,10 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Model.Logging; using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Server.Implementations.Library.Validators { @@ -34,21 +34,19 @@ namespace MediaBrowser.Server.Implementations.Library.Validators /// Task. public async Task Run(IProgress progress, CancellationToken cancellationToken) { - var items = _libraryManager.RootFolder.GetRecursiveChildren(i => true) - .SelectMany(i => i.Studios) - .DistinctNames() + var items = _libraryManager.GetStudios(new InternalItemsQuery()) + .Items + .Select(i => i.Item1) .ToList(); var numComplete = 0; var count = items.Count; - foreach (var name in items) + foreach (var item in items) { try { - var itemByName = _libraryManager.GetStudio(name); - - await itemByName.RefreshMetadata(cancellationToken).ConfigureAwait(false); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (OperationCanceledException) { @@ -57,7 +55,7 @@ namespace MediaBrowser.Server.Implementations.Library.Validators } catch (Exception ex) { - _logger.ErrorException("Error refreshing {0}", ex, name); + _logger.ErrorException("Error refreshing {0}", ex, item.Name); } numComplete++; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 2ef878a20c..21785bcbd2 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -3817,37 +3817,42 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + public QueryResult> GetAllArtists(InternalItemsQuery query) + { + return GetItemValues(query, new[] { 0, 1 }, typeof(MusicArtist).FullName); + } + public QueryResult> GetArtists(InternalItemsQuery query) { - return GetItemValues(query, 0, typeof(MusicArtist).FullName); + return GetItemValues(query, new[] { 0 }, typeof(MusicArtist).FullName); } public QueryResult> GetAlbumArtists(InternalItemsQuery query) { - return GetItemValues(query, 1, typeof(MusicArtist).FullName); + return GetItemValues(query, new[] { 1 }, typeof(MusicArtist).FullName); } public QueryResult> GetStudios(InternalItemsQuery query) { - return GetItemValues(query, 3, typeof(Studio).FullName); + return GetItemValues(query, new[] { 3 }, typeof(Studio).FullName); } public QueryResult> GetGenres(InternalItemsQuery query) { - return GetItemValues(query, 2, typeof(Genre).FullName); + return GetItemValues(query, new[] { 2 }, typeof(Genre).FullName); } public QueryResult> GetGameGenres(InternalItemsQuery query) { - return GetItemValues(query, 2, typeof(GameGenre).FullName); + return GetItemValues(query, new[] { 2 }, typeof(GameGenre).FullName); } public QueryResult> GetMusicGenres(InternalItemsQuery query) { - return GetItemValues(query, 2, typeof(MusicGenre).FullName); + return GetItemValues(query, new[] { 2 }, typeof(MusicGenre).FullName); } - private QueryResult> GetItemValues(InternalItemsQuery query, int itemValueType, string returnType) + private QueryResult> GetItemValues(InternalItemsQuery query, int[] itemValueTypes, string returnType) { if (query == null) { @@ -3863,6 +3868,10 @@ namespace MediaBrowser.Server.Implementations.Persistence var now = DateTime.UtcNow; + var typeClause = itemValueTypes.Length == 1 ? + ("Type=" + itemValueTypes[0].ToString(CultureInfo.InvariantCulture)) : + ("Type in (" + string.Join(",", itemValueTypes.Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray()) + ")"); + using (var cmd = _connection.CreateCommand()) { var itemCountColumns = new List>(); @@ -3887,7 +3896,7 @@ namespace MediaBrowser.Server.Implementations.Persistence }; var whereClauses = GetWhereClauses(typeSubQuery, cmd, "itemTypes"); - whereClauses.Add("guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND Type=@ItemValueType)"); + whereClauses.Add("guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND " + typeClause + ")"); var typeWhereText = whereClauses.Count == 0 ? string.Empty : @@ -3929,12 +3938,12 @@ namespace MediaBrowser.Server.Implementations.Persistence if (typesToCount.Count == 0) { - whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; + whereText += " And CleanName In (Select CleanValue from ItemValues where " + typeClause + " AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; } else { //whereText += " And itemTypes not null"; - whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; + whereText += " And CleanName In (Select CleanValue from ItemValues where " + typeClause + " AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; } var outerQuery = new InternalItemsQuery(query.User) @@ -3964,7 +3973,6 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.CommandText += " group by PresentationUniqueKey"; cmd.Parameters.Add(cmd, "@SelectType", DbType.String).Value = returnType; - cmd.Parameters.Add(cmd, "@ItemValueType", DbType.Int32).Value = itemValueType; if (EnableJoinUserData(query)) { From 0706bd5237125c8b95a7b8fa1576aa061703a397 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 6 Aug 2016 00:48:00 -0400 Subject: [PATCH 5/5] update DirectoryService --- MediaBrowser.Api/ItemRefreshService.cs | 7 +++++-- .../Entities/AggregateFolder.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 2 +- .../Entities/CollectionFolder.cs | 2 +- MediaBrowser.Controller/Entities/Folder.cs | 2 +- MediaBrowser.Controller/Entities/User.cs | 2 +- .../Providers/DirectoryService.cs | 18 +++++++++++++----- .../Providers/MetadataRefreshOptions.cs | 3 ++- .../Manager/ProviderManager.cs | 4 ++-- .../Subtitles/SubtitleManager.cs | 2 +- .../TV/MissingEpisodeProvider.cs | 2 +- 11 files changed, 29 insertions(+), 17 deletions(-) diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 5aab15dff1..a918e841fb 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -5,6 +5,7 @@ using MediaBrowser.Controller.Providers; using ServiceStack; using System.Threading; using CommonIO; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Api { @@ -39,12 +40,14 @@ namespace MediaBrowser.Api private readonly ILibraryManager _libraryManager; private readonly IProviderManager _providerManager; private readonly IFileSystem _fileSystem; + private readonly ILogger _logger; - public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager, IFileSystem fileSystem) + public ItemRefreshService(ILibraryManager libraryManager, IProviderManager providerManager, IFileSystem fileSystem, ILogger logger) { _libraryManager = libraryManager; _providerManager = providerManager; _fileSystem = fileSystem; + _logger = logger; } /// @@ -69,7 +72,7 @@ namespace MediaBrowser.Api private MetadataRefreshOptions GetRefreshOptions(BaseRefreshRequest request) { - return new MetadataRefreshOptions(new DirectoryService(_fileSystem)) + return new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)) { MetadataRefreshMode = request.MetadataRefreshMode, ImageRefreshMode = request.ImageRefreshMode, diff --git a/MediaBrowser.Controller/Entities/AggregateFolder.cs b/MediaBrowser.Controller/Entities/AggregateFolder.cs index 588a65e98d..7b42310101 100644 --- a/MediaBrowser.Controller/Entities/AggregateFolder.cs +++ b/MediaBrowser.Controller/Entities/AggregateFolder.cs @@ -76,7 +76,7 @@ namespace MediaBrowser.Controller.Entities { var locations = PhysicalLocations.ToList(); - var newLocations = CreateResolveArgs(new DirectoryService(BaseItem.FileSystem), false).PhysicalLocations.ToList(); + var newLocations = CreateResolveArgs(new DirectoryService(Logger, FileSystem), false).PhysicalLocations.ToList(); if (!locations.SequenceEqual(newLocations)) { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index c7a6b75ff2..8d00f38beb 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1003,7 +1003,7 @@ namespace MediaBrowser.Controller.Entities public Task RefreshMetadata(CancellationToken cancellationToken) { - return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken); + return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken); } /// diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 35dfd52e9d..8bf9919f25 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -82,7 +82,7 @@ namespace MediaBrowser.Controller.Entities { var locations = PhysicalLocations.ToList(); - var newLocations = CreateResolveArgs(new DirectoryService(BaseItem.FileSystem), false).PhysicalLocations.ToList(); + var newLocations = CreateResolveArgs(new DirectoryService(Logger, FileSystem), false).PhysicalLocations.ToList(); if (!locations.SequenceEqual(newLocations)) { diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 6a7e279be8..bb3d4f73df 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -278,7 +278,7 @@ namespace MediaBrowser.Controller.Entities public Task ValidateChildren(IProgress progress, CancellationToken cancellationToken) { - return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(FileSystem))); + return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))); } /// diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index 5c68308f5c..46da469fa5 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Entities Name = newName; - return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)) + return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)) { ReplaceAllMetadata = true, ImageRefreshMode = ImageRefreshMode.FullRefresh, diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index e7e3323c2b..62d424696b 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -22,7 +22,7 @@ namespace MediaBrowser.Controller.Providers _fileSystem = fileSystem; } - public DirectoryService(IFileSystem fileSystem) + public DirectoryService(IFileSystem fileSystem) : this(new NullLogger(), fileSystem) { } @@ -108,12 +108,20 @@ namespace MediaBrowser.Controller.Providers return null; } - var dict = GetFileSystemDictionary(directory, false); + try + { + var dict = GetFileSystemDictionary(directory, false); - FileSystemMetadata entry; - dict.TryGetValue(path, out entry); + FileSystemMetadata entry; + dict.TryGetValue(path, out entry); - return entry; + return entry; + } + catch (Exception ex) + { + _logger.ErrorException("Error in GetFileSystemDictionary. Directory: :{0}. Original path: {1}", ex, directory, path); + return null; + } } public IEnumerable GetDirectories(string path) diff --git a/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs b/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs index 9427b2afd7..87c3b36a27 100644 --- a/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs +++ b/MediaBrowser.Controller/Providers/MetadataRefreshOptions.cs @@ -1,5 +1,6 @@ using System.Linq; using CommonIO; +using MediaBrowser.Model.Logging; using MediaBrowser.Model.Providers; namespace MediaBrowser.Controller.Providers @@ -19,7 +20,7 @@ namespace MediaBrowser.Controller.Providers public bool ForceSave { get; set; } public MetadataRefreshOptions(IFileSystem fileSystem) - : this(new DirectoryService(fileSystem)) + : this(new DirectoryService(new NullLogger(), fileSystem)) { } diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 0f0745d1bc..25b9b4fd5e 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -298,7 +298,7 @@ namespace MediaBrowser.Providers.Manager { var options = GetMetadataOptions(item); - return GetImageProviders(item, options, new ImageRefreshOptions(new DirectoryService(_fileSystem)), includeDisabled).OfType(); + return GetImageProviders(item, options, new ImageRefreshOptions(new DirectoryService(_logger, _fileSystem)), includeDisabled).OfType(); } private bool CanRefresh(IMetadataProvider provider, IHasMetadata item, MetadataOptions options, bool includeDisabled, bool checkIsOwnedItem) @@ -488,7 +488,7 @@ namespace MediaBrowser.Providers.Manager ItemType = typeof(T).Name }; - var imageProviders = GetImageProviders(dummy, options, new ImageRefreshOptions(new DirectoryService(_fileSystem)), true).ToList(); + var imageProviders = GetImageProviders(dummy, options, new ImageRefreshOptions(new DirectoryService(_logger, _fileSystem)), true).ToList(); AddMetadataPlugins(summary.Plugins, dummy, options); AddImagePlugins(summary.Plugins, dummy, imageProviders); diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs index 764cb73177..a57e7d2c0c 100644 --- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs +++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs @@ -254,7 +254,7 @@ namespace MediaBrowser.Providers.Subtitles _monitor.ReportFileSystemChangeComplete(path, false); } - return _libraryManager.GetItemById(itemId).RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)) + return _libraryManager.GetItemById(itemId).RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)) { ImageRefreshMode = ImageRefreshMode.ValidationOnly, MetadataRefreshMode = MetadataRefreshMode.ValidationOnly diff --git a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs index afa1abbbb9..a12402f4ff 100644 --- a/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/MissingEpisodeProvider.cs @@ -133,7 +133,7 @@ namespace MediaBrowser.Providers.TV { foreach (var series in group) { - var directoryService = new DirectoryService(_fileSystem); + var directoryService = new DirectoryService(_logger, _fileSystem); await series.RefreshMetadata(new MetadataRefreshOptions(directoryService), cancellationToken).ConfigureAwait(false);