diff options
| author | Luke <luke.pulverenti@gmail.com> | 2016-05-04 12:34:15 -0400 |
|---|---|---|
| committer | Luke <luke.pulverenti@gmail.com> | 2016-05-04 12:34:15 -0400 |
| commit | de78c341026d1816e1470c9b1ff8ca765391f166 (patch) | |
| tree | dcc41df5793d22eaa8ba1e45f1632c7328f3ea3d /MediaBrowser.Server.Implementations | |
| parent | b01c12ca9ccb3df52321df84b21a1695ee17b750 (diff) | |
| parent | 107d1fc4f136813eed648dda5d18f433ed9302e2 (diff) | |
Merge pull request #1708 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Server.Implementations')
3 files changed, 132 insertions, 6 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 87fdc56b3..f6e2ddb8e 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -952,10 +952,15 @@ namespace MediaBrowser.Server.Implementations.Library if (isArtist) { - var existing = RootFolder - .GetRecursiveChildren(i => i is T && NameExtensions.AreEqual(i.Name, name)) - .Cast<T>() - .FirstOrDefault(); + var existing = GetItemList(new InternalItemsQuery + { + IncludeItemTypes = new[] { typeof(T).Name }, + Name = name + + }).Cast<MusicArtist>() + .Where(i => !i.IsAccessedByName) + .Cast<T>() + .FirstOrDefault(); if (existing != null) { @@ -2558,5 +2563,107 @@ namespace MediaBrowser.Server.Implementations.Library throw new InvalidOperationException(); } + + public void AddVirtualFolder(string name, string collectionType, string[] mediaPaths, bool refreshLibrary) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentNullException("name"); + } + + name = _fileSystem.GetValidFilename(name); + + var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; + + var virtualFolderPath = Path.Combine(rootFolderPath, name); + while (_fileSystem.DirectoryExists(virtualFolderPath)) + { + name += "1"; + virtualFolderPath = Path.Combine(rootFolderPath, name); + } + + if (mediaPaths != null) + { + var invalidpath = mediaPaths.FirstOrDefault(i => !_fileSystem.DirectoryExists(i)); + if (invalidpath != null) + { + throw new ArgumentException("The specified path does not exist: " + invalidpath + "."); + } + } + + _libraryMonitorFactory().Stop(); + + try + { + _fileSystem.CreateDirectory(virtualFolderPath); + + if (!string.IsNullOrEmpty(collectionType)) + { + var path = Path.Combine(virtualFolderPath, collectionType + ".collection"); + + using (File.Create(path)) + { + + } + } + + if (mediaPaths != null) + { + foreach (var path in mediaPaths) + { + AddMediaPath(name, path); + } + } + } + finally + { + Task.Run(() => + { + // No need to start if scanning the library because it will handle it + if (refreshLibrary) + { + ValidateMediaLibrary(new Progress<double>(), CancellationToken.None); + } + else + { + // Need to add a delay here or directory watchers may still pick up the changes + var task = Task.Delay(1000); + // Have to block here to allow exceptions to bubble + Task.WaitAll(task); + + _libraryMonitorFactory().Start(); + } + }); + } + } + + private const string ShortcutFileExtension = ".mblink"; + public void AddMediaPath(string virtualFolderName, string path) + { + if (string.IsNullOrWhiteSpace(path)) + { + throw new ArgumentNullException("path"); + } + + if (!_fileSystem.DirectoryExists(path)) + { + throw new DirectoryNotFoundException("The path does not exist."); + } + + var rootFolderPath = ConfigurationManager.ApplicationPaths.DefaultUserViewsPath; + var virtualFolderPath = Path.Combine(rootFolderPath, virtualFolderName); + + var shortcutFilename = _fileSystem.GetFileNameWithoutExtension(path); + + var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension); + + while (_fileSystem.FileExists(lnk)) + { + shortcutFilename += "1"; + lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension); + } + + _fileSystem.CreateShortcut(lnk, path); + } } }
\ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index e26a56ec0..291ef7375 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1966,9 +1966,14 @@ namespace MediaBrowser.Server.Implementations.Persistence // cmd.Parameters.Add(cmd, "@MaxPlayers", DbType.Int32).Value = query.MaxPlayers.Value; //} + if (query.IndexNumber.HasValue) + { + whereClauses.Add("IndexNumber=@IndexNumber"); + cmd.Parameters.Add(cmd, "@IndexNumber", DbType.Int32).Value = query.IndexNumber.Value; + } if (query.ParentIndexNumber.HasValue) { - whereClauses.Add("ParentIndexNumber=@MinEndDate"); + whereClauses.Add("ParentIndexNumber=@ParentIndexNumber"); cmd.Parameters.Add(cmd, "@ParentIndexNumber", DbType.Int32).Value = query.ParentIndexNumber.Value; } if (query.MinEndDate.HasValue) @@ -2065,6 +2070,19 @@ namespace MediaBrowser.Server.Implementations.Persistence cmd.Parameters.Add(cmd, "@PersonName", DbType.String).Value = query.Person; } + if (!string.IsNullOrWhiteSpace(query.Name)) + { + if (_config.Configuration.SchemaVersion >= 66) + { + whereClauses.Add("CleanName=@Name"); + } + else + { + whereClauses.Add("Name=@Name"); + } + cmd.Parameters.Add(cmd, "@Name", DbType.String).Value = query.Name; + } + if (!string.IsNullOrWhiteSpace(query.NameContains)) { if (_config.Configuration.SchemaVersion >= 66) diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 911dbb0cb..161f771a9 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -153,7 +153,8 @@ namespace MediaBrowser.Server.Implementations.UserViews CollectionType.HomeVideos, CollectionType.BoxSets, CollectionType.Playlists, - CollectionType.Photos + CollectionType.Photos, + string.Empty }; return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); |
