diff options
| author | Tim Hobbs <jesus.tesh@gmail.com> | 2014-03-17 15:47:22 -0700 |
|---|---|---|
| committer | Tim Hobbs <jesus.tesh@gmail.com> | 2014-03-17 15:47:22 -0700 |
| commit | cf43180a2dcab023ba6a48f37920615d7e87c599 (patch) | |
| tree | 1b94ff05caf34974161595823898b8b32e1f6d24 /MediaBrowser.Server.Implementations | |
| parent | 7a0963129126679aad8b64cc8a36474edaca7170 (diff) | |
| parent | 78acab691693d6adfac67bcf3f0617e336f801a6 (diff) | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'MediaBrowser.Server.Implementations')
7 files changed, 201 insertions, 58 deletions
diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 9a196cc47..c18856293 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Implementations.Collections _iLibraryMonitor = iLibraryMonitor; } - public async Task CreateCollection(CollectionCreationOptions options) + public async Task<BoxSet> CreateCollection(CollectionCreationOptions options) { var name = options.Name; @@ -64,6 +64,13 @@ namespace MediaBrowser.Server.Implementations.Collections await collection.RefreshMetadata(new MetadataRefreshOptions(), CancellationToken.None) .ConfigureAwait(false); + + if (options.ItemIdList.Count > 0) + { + await AddToCollection(collection.Id, options.ItemIdList); + } + + return collection; } finally { @@ -104,6 +111,7 @@ namespace MediaBrowser.Server.Implementations.Collections } var list = new List<LinkedChild>(); + var currentLinkedChildren = collection.GetLinkedChildren().ToList(); foreach (var itemId in ids) { @@ -114,7 +122,7 @@ namespace MediaBrowser.Server.Implementations.Collections throw new ArgumentException("No item exists with the supplied Id"); } - if (collection.LinkedChildren.Any(i => i.ItemId.HasValue && i.ItemId == itemId)) + if (currentLinkedChildren.Any(i => i.Id == itemId)) { throw new ArgumentException("Item already exists in collection"); } @@ -126,6 +134,18 @@ namespace MediaBrowser.Server.Implementations.Collections ItemType = item.GetType().Name, Type = LinkedChildType.Manual }); + + var supportsGrouping = item as ISupportsBoxSetGrouping; + + if (supportsGrouping != null) + { + var boxsetIdList = supportsGrouping.BoxSetIdList.ToList(); + if (!boxsetIdList.Contains(collectionId)) + { + boxsetIdList.Add(collectionId); + } + supportsGrouping.BoxSetIdList = boxsetIdList; + } } collection.LinkedChildren.AddRange(list); @@ -156,6 +176,16 @@ namespace MediaBrowser.Server.Implementations.Collections } list.Add(child); + + var childItem = _libraryManager.GetItemById(itemId); + var supportsGrouping = childItem as ISupportsBoxSetGrouping; + + if (supportsGrouping != null) + { + var boxsetIdList = supportsGrouping.BoxSetIdList.ToList(); + boxsetIdList.Remove(collectionId); + supportsGrouping.BoxSetIdList = boxsetIdList; + } } var shortcutFiles = Directory diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index fadf4c900..19d834c20 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1082,6 +1082,12 @@ namespace MediaBrowser.Server.Implementations.Dto dto.IsHD = video.IsHD; dto.PartCount = video.AdditionalPartIds.Count + 1; + dto.AlternateVersionCount = video.AlternateVersionCount; + + if (video.PrimaryVersionId.HasValue) + { + dto.PrimaryVersionId = video.PrimaryVersionId.Value.ToString("N"); + } if (fields.Contains(ItemFields.Chapters)) { diff --git a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs index b2f0a2769..65bbb35ba 100644 --- a/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs +++ b/MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs @@ -267,7 +267,7 @@ namespace MediaBrowser.Server.Implementations.IO } else { - Logger.Info("Unable to add directory watcher for {0}. It already exists in the dictionary." + path); + Logger.Info("Unable to add directory watcher for {0}. It already exists in the dictionary.", path); newWatcher.Dispose(); } diff --git a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs index 16c0d1a27..b11457ec5 100644 --- a/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs +++ b/MediaBrowser.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using MediaBrowser.Model.Logging; namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { @@ -20,11 +21,13 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { private readonly IServerApplicationPaths _applicationPaths; private readonly ILibraryManager _libraryManager; + private readonly ILogger _logger; - public MovieResolver(IServerApplicationPaths appPaths, ILibraryManager libraryManager) + public MovieResolver(IServerApplicationPaths appPaths, ILibraryManager libraryManager, ILogger logger) { _applicationPaths = appPaths; _libraryManager = libraryManager; + _logger = logger; } /// <summary> @@ -76,29 +79,29 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies { if (string.Equals(collectionType, CollectionType.Trailers, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false); + return FindMovie<Trailer>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false, false); } if (string.Equals(collectionType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false); + return FindMovie<MusicVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, false, false); } if (string.Equals(collectionType, CollectionType.AdultVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); + return FindMovie<AdultVideo>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, false); } if (string.Equals(collectionType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); + return FindMovie<Video>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, false); } - + if (string.IsNullOrEmpty(collectionType) || string.Equals(collectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true); + return FindMovie<Movie>(args.Path, args.Parent, args.FileSystemChildren, args.DirectoryService, true, true); } return null; @@ -187,7 +190,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies /// <param name="directoryService">The directory service.</param> /// <param name="supportMultiFileItems">if set to <c>true</c> [support multi file items].</param> /// <returns>Movie.</returns> - private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems) + private T FindMovie<T>(string path, Folder parent, IEnumerable<FileSystemInfo> fileSystemEntries, IDirectoryService directoryService, bool supportMultiFileItems, bool supportsAlternateVersions) where T : Video, new() { var movies = new List<T>(); @@ -218,7 +221,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies }; } - if (EntityResolutionHelper.IsMultiPartFile(filename)) + if (EntityResolutionHelper.IsMultiPartFolder(filename)) { multiDiscFolders.Add(child); } @@ -248,9 +251,27 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies } } - if (movies.Count > 1 && supportMultiFileItems) + if (movies.Count > 1) { - return GetMultiFileMovie(movies); + if (supportMultiFileItems) + { + var result = GetMultiFileMovie(movies); + + if (result != null) + { + return result; + } + } + if (supportsAlternateVersions) + { + var result = GetMovieWithAlternateVersions(movies); + + if (result != null) + { + return result; + } + } + return null; } if (movies.Count == 1) @@ -356,12 +377,47 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies var firstMovie = sortedMovies[0]; // They must all be part of the sequence if we're going to consider it a multi-part movie - // Only support up to 8 (matches Plex), to help avoid incorrect detection - if (sortedMovies.All(i => EntityResolutionHelper.IsMultiPartFile(i.Path)) && sortedMovies.Count <= 8) + if (sortedMovies.All(i => EntityResolutionHelper.IsMultiPartFile(i.Path))) { - firstMovie.IsMultiPart = true; + // Only support up to 8 (matches Plex), to help avoid incorrect detection + if (sortedMovies.Count <= 8) + { + firstMovie.IsMultiPart = true; + + _logger.Info("Multi-part video found: " + firstMovie.Path); - return firstMovie; + return firstMovie; + } + } + + return null; + } + + private T GetMovieWithAlternateVersions<T>(IEnumerable<T> movies) + where T : Video, new() + { + var sortedMovies = movies.OrderBy(i => i.Path.Length).ToList(); + + // Cap this at five to help avoid incorrect matching + if (sortedMovies.Count > 5) + { + return null; + } + + var firstMovie = sortedMovies[0]; + + var filenamePrefix = Path.GetFileNameWithoutExtension(firstMovie.Path); + + if (!string.IsNullOrWhiteSpace(filenamePrefix)) + { + if (sortedMovies.Skip(1).All(i => Path.GetFileNameWithoutExtension(i.Path).StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase))) + { + firstMovie.HasLocalAlternateVersions = true; + + _logger.Info("Multi-version video found: " + firstMovie.Path); + + return firstMovie; + } } return null; diff --git a/MediaBrowser.Server.Implementations/Library/Validators/BoxSetPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/BoxSetPostScanTask.cs new file mode 100644 index 000000000..f02c907c6 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/Validators/BoxSetPostScanTask.cs @@ -0,0 +1,50 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Library; +using System; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.Library.Validators +{ + public class BoxSetPostScanTask : ILibraryPostScanTask + { + private readonly ILibraryManager _libraryManager; + + public BoxSetPostScanTask(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + + public Task Run(IProgress<double> progress, CancellationToken cancellationToken) + { + var items = _libraryManager.RootFolder.RecursiveChildren.ToList(); + + var boxsets = items.OfType<BoxSet>().ToList(); + + var numComplete = 0; + + foreach (var boxset in boxsets) + { + foreach (var child in boxset.GetLinkedChildren().OfType<ISupportsBoxSetGrouping>()) + { + var boxsetIdList = child.BoxSetIdList.ToList(); + if (!boxsetIdList.Contains(boxset.Id)) + { + boxsetIdList.Add(boxset.Id); + } + child.BoxSetIdList = boxsetIdList; + } + + numComplete++; + double percent = numComplete; + percent /= boxsets.Count; + progress.Report(percent * 100); + } + + progress.Report(100); + return Task.FromResult(true); + } + } +} diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index c44b60845..871565133 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -165,6 +165,7 @@ <Compile Include="Library\UserManager.cs" /> <Compile Include="Library\Validators\ArtistsPostScanTask.cs" /> <Compile Include="Library\Validators\ArtistsValidator.cs" /> + <Compile Include="Library\Validators\BoxSetPostScanTask.cs" /> <Compile Include="Library\Validators\CountHelpers.cs" /> <Compile Include="Library\Validators\GameGenresPostScanTask.cs" /> <Compile Include="Library\Validators\GameGenresValidator.cs" /> diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 71d95b97b..3acc5e892 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -622,42 +622,27 @@ namespace MediaBrowser.Server.Implementations.Session return session; } - /// <summary> - /// Sends the system command. - /// </summary> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public Task SendSystemCommand(Guid sessionId, SystemCommand command, CancellationToken cancellationToken) + public Task SendSystemCommand(Guid controllingSessionId, Guid sessionId, SystemCommand command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendSystemCommand(command, cancellationToken); } - /// <summary> - /// Sends the message command. - /// </summary> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public Task SendMessageCommand(Guid sessionId, MessageCommand command, CancellationToken cancellationToken) + public Task SendMessageCommand(Guid controllingSessionId, Guid sessionId, MessageCommand command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendMessageCommand(command, cancellationToken); } - /// <summary> - /// Sends the play command. - /// </summary> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public Task SendPlayCommand(Guid sessionId, PlayRequest command, CancellationToken cancellationToken) + public Task SendPlayCommand(Guid controllingSessionId, Guid sessionId, PlayRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); @@ -690,31 +675,27 @@ namespace MediaBrowser.Server.Implementations.Session } } + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + if (controllingSession.UserId.HasValue) + { + command.ControllingUserId = controllingSession.UserId.Value.ToString("N"); + } + return session.SessionController.SendPlayCommand(command, cancellationToken); } - /// <summary> - /// Sends the browse command. - /// </summary> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public Task SendBrowseCommand(Guid sessionId, BrowseRequest command, CancellationToken cancellationToken) + public Task SendBrowseCommand(Guid controllingSessionId, Guid sessionId, BrowseRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + return session.SessionController.SendBrowseCommand(command, cancellationToken); } - /// <summary> - /// Sends the playstate command. - /// </summary> - /// <param name="sessionId">The session id.</param> - /// <param name="command">The command.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task.</returns> - public Task SendPlaystateCommand(Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken) + public Task SendPlaystateCommand(Guid controllingSessionId, Guid sessionId, PlaystateRequest command, CancellationToken cancellationToken) { var session = GetSessionForRemoteControl(sessionId); @@ -723,9 +704,28 @@ namespace MediaBrowser.Server.Implementations.Session throw new ArgumentException(string.Format("Session {0} is unable to seek.", session.Id)); } + var controllingSession = GetSession(controllingSessionId); + AssertCanControl(session, controllingSession); + if (controllingSession.UserId.HasValue) + { + command.ControllingUserId = controllingSession.UserId.Value.ToString("N"); + } + return session.SessionController.SendPlaystateCommand(command, cancellationToken); } + private void AssertCanControl(SessionInfo session, SessionInfo controllingSession) + { + if (session == null) + { + throw new ArgumentNullException("session"); + } + if (controllingSession == null) + { + throw new ArgumentNullException("controllingSession"); + } + } + /// <summary> /// Sends the restart required message. /// </summary> |
