diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-07 15:46:24 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-06-07 15:46:24 -0400 |
| commit | e210825e54d2199028570489ee4f3d2834676021 (patch) | |
| tree | 506fde69bd181a4993cfe9d10c03432be07c7105 /MediaBrowser.Server.Implementations/Library | |
| parent | 2b14be8643b8ca483dbd77386b7a0c77e40f3191 (diff) | |
update translations
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
3 files changed, 203 insertions, 14 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 12e4c9403..4dad71465 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1,11 +1,11 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Progress; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; @@ -18,6 +18,7 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Server.Implementations.Library.Validators; using MediaBrowser.Server.Implementations.ScheduledTasks; +using MoreLinq; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -26,7 +27,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MoreLinq; using SortOrder = MediaBrowser.Model.Entities.SortOrder; namespace MediaBrowser.Server.Implementations.Library @@ -920,7 +920,7 @@ namespace MediaBrowser.Server.Implementations.Library { // Ensure the location is unavailable. Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.ArtistsPath); - + return new ArtistsValidator(this, _userManager, _logger).Run(progress, cancellationToken); } @@ -934,7 +934,7 @@ namespace MediaBrowser.Server.Implementations.Library { // Ensure the location is unavailable. Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.MusicGenrePath); - + return new MusicGenresValidator(this, _logger).Run(progress, cancellationToken); } @@ -948,7 +948,7 @@ namespace MediaBrowser.Server.Implementations.Library { // Ensure the location is unavailable. Directory.CreateDirectory(ConfigurationManager.ApplicationPaths.GameGenrePath); - + return new GameGenresValidator(this, _userManager, _logger).Run(progress, cancellationToken); } @@ -1056,14 +1056,6 @@ namespace MediaBrowser.Server.Implementations.Library innerProgress.RegisterAction(pct => progress.Report(75 + pct * .25)); - foreach (var user in _userManager.Users) - { - foreach (var view in user.GetViews().ToList()) - { - await view.RefreshMetadata(cancellationToken).ConfigureAwait(false); - } - } - // Run post-scan tasks await RunPostScanTasks(innerProgress, cancellationToken).ConfigureAwait(false); @@ -1503,5 +1495,38 @@ namespace MediaBrowser.Server.Implementations.Library }) .Distinct(StringComparer.OrdinalIgnoreCase); } + + public async Task<UserView> GetNamedView(string name, string type, string sortName, CancellationToken cancellationToken) + { + var id = "namedview_2_" + name; + var guid = id.GetMD5(); + + var item = GetItemById(guid) as UserView; + + if (item == null) + { + var path = Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, + "views", + _fileSystem.GetValidFilename(name)); + + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + item = new UserView + { + Path = path, + Id = guid, + DateCreated = DateTime.UtcNow, + Name = name, + ViewType = type, + ForcedSortName = sortName + }; + + await CreateItem(item, cancellationToken).ConfigureAwait(false); + + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + + return item; + } } } diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs new file mode 100644 index 000000000..b9a96bfc9 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -0,0 +1,129 @@ +using MediaBrowser.Common.IO; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Controller.Localization; +using MediaBrowser.Model.Channels; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Library; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.Library +{ + public class UserViewManager : IUserViewManager + { + private readonly ILibraryManager _libraryManager; + private readonly ILocalizationManager _localizationManager; + private readonly IFileSystem _fileSystem; + private readonly IUserManager _userManager; + + private readonly IChannelManager _channelManager; + private readonly ILiveTvManager _liveTvManager; + + public UserViewManager(ILibraryManager libraryManager, ILocalizationManager localizationManager, IFileSystem fileSystem, IUserManager userManager, IChannelManager channelManager, ILiveTvManager liveTvManager) + { + _libraryManager = libraryManager; + _localizationManager = localizationManager; + _fileSystem = fileSystem; + _userManager = userManager; + _channelManager = channelManager; + _liveTvManager = liveTvManager; + } + + public async Task<IEnumerable<Folder>> GetUserViews(UserViewQuery query, CancellationToken cancellationToken) + { + var user = _userManager.GetUserById(new Guid(query.UserId)); + + var folders = user.RootFolder + .GetChildren(user, true) + .OfType<Folder>() + .ToList(); + + var list = new List<Folder>(); + + var excludeFolderIds = user.Configuration.ExcludeFoldersFromGrouping.Select(i => new Guid(i)).ToList(); + + var standaloneFolders = folders.Where(i => UserView.IsExcludedFromGrouping(i) || excludeFolderIds.Contains(i.Id)).ToList(); + + list.AddRange(standaloneFolders); + + var recursiveChildren = folders + .Except(standaloneFolders) + .SelectMany(i => i.GetRecursiveChildren(user, false)) + .ToList(); + + if (recursiveChildren.OfType<Series>().Any()) + { + list.Add(await GetUserView(CollectionType.TvShows, user, cancellationToken).ConfigureAwait(false)); + } + + if (recursiveChildren.OfType<MusicAlbum>().Any() || + recursiveChildren.OfType<MusicVideo>().Any()) + { + list.Add(await GetUserView(CollectionType.Music, user, cancellationToken).ConfigureAwait(false)); + } + + if (recursiveChildren.OfType<Movie>().Any()) + { + list.Add(await GetUserView(CollectionType.Movies, user, cancellationToken).ConfigureAwait(false)); + } + + if (recursiveChildren.OfType<Game>().Any()) + { + list.Add(await GetUserView(CollectionType.Games, user, cancellationToken).ConfigureAwait(false)); + } + + if (recursiveChildren.OfType<BoxSet>().Any()) + { + list.Add(await GetUserView(CollectionType.BoxSets, user, cancellationToken).ConfigureAwait(false)); + } + + if (query.IncludeExternalContent) + { + var channelsTask = Task.Run(() => _channelManager.GetChannels(new ChannelQuery + { + Limit = 0, + UserId = query.UserId + + }, cancellationToken), cancellationToken); + + // Avoid implicitly captured closure. + var token = cancellationToken; + var liveTvTask = Task.Run(() => _liveTvManager.GetLiveTvInfo(token), cancellationToken); + + await Task.WhenAll(channelsTask, liveTvTask).ConfigureAwait(false); + + var channelResult = channelsTask.Result; + + if (channelResult.TotalRecordCount > 0) + { + list.Add(await _channelManager.GetInternalChannelFolder(query.UserId, cancellationToken).ConfigureAwait(false)); + } + + var liveTvInfo = liveTvTask.Result; + + if (liveTvInfo.EnabledUsers.Contains(query.UserId)) + { + list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false)); + } + } + + return list.OrderBy(i => i.SortName); + } + + private Task<UserView> GetUserView(string type, User user, CancellationToken cancellationToken) + { + var name = _localizationManager.GetLocalizedString("ViewType" + type); + + return _libraryManager.GetNamedView(name, type, string.Empty, cancellationToken); + } + } +} diff --git a/MediaBrowser.Server.Implementations/Library/Validators/UserViewPostScanTask.cs b/MediaBrowser.Server.Implementations/Library/Validators/UserViewPostScanTask.cs new file mode 100644 index 000000000..30ebcc3b8 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Library/Validators/UserViewPostScanTask.cs @@ -0,0 +1,35 @@ +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Library; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Server.Implementations.Library.Validators +{ + public class UserViewPostScanTask : ILibraryPostScanTask + { + private readonly IUserManager _userManager; + private readonly IUserViewManager _userViewManager; + + public UserViewPostScanTask(IUserManager userManager, IUserViewManager userViewManager) + { + _userManager = userManager; + _userViewManager = userViewManager; + } + + public async Task Run(IProgress<double> progress, CancellationToken cancellationToken) + { + foreach (var user in _userManager.Users) + { + foreach (var view in await _userViewManager.GetUserViews(new UserViewQuery + { + UserId = user.Id.ToString("N") + + }, cancellationToken).ConfigureAwait(false)) + { + await view.RefreshMetadata(cancellationToken).ConfigureAwait(false); + } + } + } + } +} |
