From d440e89c507ba1c764c24d53bfe85d747b7beb8b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 27 Jul 2015 01:03:34 -0400 Subject: update schedules direct page --- MediaBrowser.Controller/Entities/UserViewBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.Controller/Entities/UserViewBuilder.cs') diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index b2d359277..0733b65b1 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -66,7 +66,7 @@ namespace MediaBrowser.Controller.Entities { var result = await _channelManager.GetChannelsInternal(new ChannelQuery { - UserId = user.Id.ToString("N"), + UserId = user == null ? null : user.Id.ToString("N"), Limit = query.Limit, StartIndex = query.StartIndex -- cgit v1.2.3 From 8f75454d76c9c21018476fd278f91ae69f9268c0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 29 Jul 2015 16:31:15 -0400 Subject: update image processing --- Emby.Drawing/ImageMagick/StripCollageBuilder.cs | 4 ++-- MediaBrowser.Api/UserLibrary/ItemsService.cs | 1 - MediaBrowser.Api/UserLibrary/UserViewsService.cs | 2 +- MediaBrowser.Controller/Entities/ICollectionFolder.cs | 14 ++++++++++++++ MediaBrowser.Controller/Entities/UserViewBuilder.cs | 5 +---- .../Channels/ChannelManager.cs | 2 +- .../Collections/ManualCollectionsFolder.cs | 1 - MediaBrowser.Server.Implementations/Dto/DtoService.cs | 14 ++++++++------ .../Library/LibraryManager.cs | 2 +- .../Library/UserViewManager.cs | 19 +++++++++---------- .../LiveTv/EmbyTV/EmbyTV.cs | 15 +++++++++------ .../LiveTv/Listings/SchedulesDirect.cs | 13 ++++++++++--- .../Photos/BaseDynamicImageProvider.cs | 6 +++--- .../Playlists/ManualPlaylistsFolder.cs | 4 +--- 14 files changed, 60 insertions(+), 42 deletions(-) (limited to 'MediaBrowser.Controller/Entities/UserViewBuilder.cs') diff --git a/Emby.Drawing/ImageMagick/StripCollageBuilder.cs b/Emby.Drawing/ImageMagick/StripCollageBuilder.cs index a50a75ccd..7ed0f36e2 100644 --- a/Emby.Drawing/ImageMagick/StripCollageBuilder.cs +++ b/Emby.Drawing/ImageMagick/StripCollageBuilder.cs @@ -285,14 +285,14 @@ namespace Emby.Drawing.ImageMagick private MagickWand BuildThumbCollageWand(List paths, int width, int height) { - var inputPaths = ImageHelpers.ProjectPaths(paths, 8); + var inputPaths = ImageHelpers.ProjectPaths(paths, 4); using (var wandImages = new MagickWand(inputPaths.ToArray())) { var wand = new MagickWand(width, height); wand.OpenImage("gradient:#111111-#111111"); using (var draw = new DrawingWand()) { - var iSlice = Convert.ToInt32(width * .1166666667); + var iSlice = Convert.ToInt32(width * .1166666667 * 2); int iTrans = Convert.ToInt32(height * .25); int iHeight = Convert.ToInt32(height * .62); var horizontalImagePadding = Convert.ToInt32(width * 0.0125); diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 881cec7ba..b412a6480 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -2,7 +2,6 @@ using MediaBrowser.Controller.Dto; 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.Localization; diff --git a/MediaBrowser.Api/UserLibrary/UserViewsService.cs b/MediaBrowser.Api/UserLibrary/UserViewsService.cs index 43d8dbc16..a49ab8556 100644 --- a/MediaBrowser.Api/UserLibrary/UserViewsService.cs +++ b/MediaBrowser.Api/UserLibrary/UserViewsService.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Api.UserLibrary var views = user.RootFolder .GetChildren(user, true) .OfType() - .Where(i => IsEligibleForSpecialView(i)) + .Where(IsEligibleForSpecialView) .ToList(); var list = views diff --git a/MediaBrowser.Controller/Entities/ICollectionFolder.cs b/MediaBrowser.Controller/Entities/ICollectionFolder.cs index f46d7ed6f..b55ca0a17 100644 --- a/MediaBrowser.Controller/Entities/ICollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/ICollectionFolder.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities { @@ -14,4 +15,17 @@ namespace MediaBrowser.Controller.Entities Guid Id { get; } IEnumerable PhysicalLocations { get; } } + + public static class CollectionFolderExtensions + { + public static string GetViewType(this ICollectionFolder folder, User user) + { + if (user.Configuration.PlainFolderViews.Contains(folder.Id.ToString("N"), StringComparer.OrdinalIgnoreCase)) + { + return null; + } + + return folder.CollectionType; + } + } } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 0733b65b1..462f66e20 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -264,10 +264,7 @@ namespace MediaBrowser.Controller.Entities private async Task> FindPlaylists(Folder parent, User user, InternalItemsQuery query) { - var collectionFolders = user.RootFolder.GetChildren(user, true).Select(i => i.Id).ToList(); - - var list = _playlistManager.GetPlaylists(user.Id.ToString("N")) - .Where(i => i.GetChildren(user, true).Any(media => _libraryManager.GetCollectionFolders(media).Select(c => c.Id).Any(collectionFolders.Contains))); + var list = _playlistManager.GetPlaylists(user.Id.ToString("N")); return GetResult(list, parent, query); } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index 3e58e3bd5..179eb5629 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -476,7 +476,7 @@ namespace MediaBrowser.Server.Implementations.Channels public Channel GetChannel(string id) { - return (Channel)_libraryManager.GetItemById(new Guid(id)); + return _libraryManager.GetItemById(new Guid(id)) as Channel; } public IEnumerable GetAllChannelFeatures() diff --git a/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs index 8f5d8fe9b..d62918d56 100644 --- a/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs +++ b/MediaBrowser.Server.Implementations/Collections/ManualCollectionsFolder.cs @@ -1,5 +1,4 @@ using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Entities.Movies; using System.Linq; namespace MediaBrowser.Server.Implementations.Collections diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index aade00aa4..31f1b17dd 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -351,6 +351,14 @@ namespace MediaBrowser.Server.Implementations.Dto AttachBasicFields(dto, item, owner, options); + var collectionFolder = item as ICollectionFolder; + if (collectionFolder != null) + { + dto.CollectionType = user == null ? + collectionFolder.CollectionType : + collectionFolder.GetViewType(user); + } + var playlist = item as Playlist; if (playlist != null) { @@ -1066,12 +1074,6 @@ namespace MediaBrowser.Server.Implementations.Dto dto.DisplayOrder = hasDisplayOrder.DisplayOrder; } - var collectionFolder = item as ICollectionFolder; - if (collectionFolder != null) - { - dto.CollectionType = collectionFolder.CollectionType; - } - var userView = item as UserView; if (userView != null) { diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 497a198fd..40d93e8ef 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1615,7 +1615,7 @@ namespace MediaBrowser.Server.Implementations.Library .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); } - private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(.01); + private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); public async Task GetNamedView(User user, string name, diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 14c5c9a03..61b28a072 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -91,7 +91,7 @@ namespace MediaBrowser.Server.Implementations.Library list.AddRange(standaloneFolders); } - var parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.CollectionType)) + var parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user))) .ToList(); if (parents.Count > 0) @@ -99,7 +99,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(parents, list, CollectionType.TvShows, string.Empty, user, cancellationToken).ConfigureAwait(false)); } - parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.Music, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.CollectionType)) + parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Music, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user))) .ToList(); if (parents.Count > 0) @@ -107,7 +107,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(parents, list, CollectionType.Music, string.Empty, user, cancellationToken).ConfigureAwait(false)); } - parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.CollectionType)) + parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Movies, StringComparison.OrdinalIgnoreCase) || string.IsNullOrWhiteSpace(i.GetViewType(user))) .ToList(); if (parents.Count > 0) @@ -115,7 +115,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(parents, list, CollectionType.Movies, string.Empty, user, cancellationToken).ConfigureAwait(false)); } - parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.Games, StringComparison.OrdinalIgnoreCase)) + parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Games, StringComparison.OrdinalIgnoreCase)) .ToList(); if (parents.Count > 0) @@ -123,7 +123,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(parents, list, CollectionType.Games, string.Empty, user, cancellationToken).ConfigureAwait(false)); } - parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) + parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) .ToList(); if (parents.Count > 0) @@ -131,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.Library list.Add(await GetUserView(parents, list, CollectionType.BoxSets, string.Empty, user, cancellationToken).ConfigureAwait(false)); } - parents = foldersWithViewTypes.Where(i => string.Equals(i.CollectionType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) + parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) .ToList(); if (parents.Count > 0) @@ -204,8 +204,9 @@ namespace MediaBrowser.Server.Implementations.Library public async Task GetUserView(List parents, List currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken) { var name = _localizationManager.GetLocalizedString("ViewType" + viewType); + var enableUserSpecificViews = _config.Configuration.EnableUserSpecificUserViews; - if (parents.Count == 1 && parents.All(i => string.Equals(i.CollectionType, viewType, StringComparison.OrdinalIgnoreCase))) + if (parents.Count == 1 && parents.All(i => string.Equals((enableUserSpecificViews ? i.CollectionType : i.GetViewType(user)), viewType, StringComparison.OrdinalIgnoreCase))) { if (!string.IsNullOrWhiteSpace(parents[0].Name)) { @@ -221,7 +222,7 @@ namespace MediaBrowser.Server.Implementations.Library return await GetUserView(parentId, name, viewType, enableRichView, sortName, user, cancellationToken).ConfigureAwait(false); } - if (_config.Configuration.EnableUserSpecificUserViews) + if (enableUserSpecificViews) { viewType = enableRichView ? viewType : null; var view = await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false); @@ -233,8 +234,6 @@ namespace MediaBrowser.Server.Implementations.Library } return view; } - - return await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false); } return await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2319a6c2c..c323f8e0d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common; +using System.Globalization; +using MediaBrowser.Common; using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; @@ -453,11 +454,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } var mediaStreamInfo = await GetChannelStream(timer.ChannelId, null, CancellationToken.None); - var duration = (timer.EndDate - DateTime.UtcNow).TotalSeconds + timer.PostPaddingSeconds; + var duration = (timer.EndDate - DateTime.UtcNow).Add(TimeSpan.FromSeconds(timer.PostPaddingSeconds)); HttpRequestOptions httpRequestOptions = new HttpRequestOptions() { - Url = mediaStreamInfo.Path + "?duration=" + duration + Url = mediaStreamInfo.Path + "?duration=" + duration.TotalSeconds.ToString(CultureInfo.InvariantCulture) }; var info = GetProgramInfoFromCache(timer.ChannelId, timer.ProgramId); @@ -516,13 +517,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { httpRequestOptions.BufferContent = false; - httpRequestOptions.CancellationToken = cancellationToken; + var durationToken = new CancellationTokenSource(duration); + var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token).Token; + httpRequestOptions.CancellationToken = linkedToken; _logger.Info("Writing file to path: " + recordPath); using (var response = await _httpClient.SendAsync(httpRequestOptions, "GET")) { using (var output = File.Open(recordPath, FileMode.Create, FileAccess.Write, FileShare.Read)) { - await response.Content.CopyToAsync(output, 4096, cancellationToken); + await response.Content.CopyToAsync(output, 4096, linkedToken); } } @@ -530,7 +533,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } catch (OperationCanceledException) { - recording.Status = RecordingStatus.Cancelled; + recording.Status = RecordingStatus.Completed; } catch { diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index ffafe5979..655feedae 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Net; +using MediaBrowser.Common; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; @@ -20,19 +21,25 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings private readonly ILogger _logger; private readonly IJsonSerializer _jsonSerializer; private readonly IHttpClient _httpClient; - private const string UserAgent = "EmbyTV"; private readonly SemaphoreSlim _tokenSemaphore = new SemaphoreSlim(1, 1); + private readonly IApplicationHost _appHost; private const string ApiUrl = "https://json.schedulesdirect.org/20141201"; private readonly ConcurrentDictionary _channelPair = new ConcurrentDictionary(); - public SchedulesDirect(ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient) + public SchedulesDirect(ILogger logger, IJsonSerializer jsonSerializer, IHttpClient httpClient, IApplicationHost appHost) { _logger = logger; _jsonSerializer = jsonSerializer; _httpClient = httpClient; + _appHost = appHost; + } + + private string UserAgent + { + get { return "Emby/" + _appHost.ApplicationVersion; } } private List GetScheduleRequestDates(DateTime startDateUtc, DateTime endDateUtc) diff --git a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs index eb25c7d79..642753fa6 100644 --- a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs @@ -118,7 +118,7 @@ namespace MediaBrowser.Server.Implementations.Photos protected Task CreateThumbCollage(IHasImages primaryItem, List items, string outputPath, bool drawText) { - return CreateCollage(primaryItem, items, outputPath, 960, 540, drawText, primaryItem.Name); + return CreateCollage(primaryItem, items, outputPath, 640, 360, drawText, primaryItem.Name); } protected virtual IEnumerable GetStripCollageImagePaths(IHasImages primaryItem, IEnumerable items) @@ -130,12 +130,12 @@ namespace MediaBrowser.Server.Implementations.Photos protected Task CreatePosterCollage(IHasImages primaryItem, List items, string outputPath) { - return CreateCollage(primaryItem, items, outputPath, 600, 900, true, primaryItem.Name); + return CreateCollage(primaryItem, items, outputPath, 400, 600, true, primaryItem.Name); } protected Task CreateSquareCollage(IHasImages primaryItem, List items, string outputPath, bool drawText) { - return CreateCollage(primaryItem, items, outputPath, 800, 800, drawText, primaryItem.Name); + return CreateCollage(primaryItem, items, outputPath, 600, 600, drawText, primaryItem.Name); } protected Task CreateThumbCollage(IHasImages primaryItem, List items, string outputPath, int width, int height, bool drawText, string text) diff --git a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs index 2f3a1dd0c..3ec41b6dc 100644 --- a/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs +++ b/MediaBrowser.Server.Implementations/Playlists/ManualPlaylistsFolder.cs @@ -16,9 +16,7 @@ namespace MediaBrowser.Server.Implementations.Playlists public override bool IsVisible(User user) { - return base.IsVisible(user) && GetChildren(user, false) - .OfType() - .Any(i => i.IsVisible(user)); + return base.IsVisible(user) && GetChildren(user, false).Any(); } protected override IEnumerable GetEligibleChildrenForRecursiveChildren(User user) -- cgit v1.2.3 From 96346fc88ced93cc068ae9610900b3a1420f2130 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 5 Aug 2015 21:21:18 -0400 Subject: update globalize --- MediaBrowser.Api/UserLibrary/ArtistsService.cs | 41 ++--------- .../Entities/Audio/MusicAlbum.cs | 6 ++ .../Entities/UserViewBuilder.cs | 84 +++++----------------- MediaBrowser.Controller/Library/ILibraryManager.cs | 13 +++- .../Music/MusicBrainzAlbumProvider.cs | 2 +- .../Library/LibraryManager.cs | 83 +++++++++++++++------ .../Library/Validators/ArtistsValidator.cs | 10 +-- .../LiveTv/LiveTvManager.cs | 42 ++++++++--- .../UserViews/DynamicImageProvider.cs | 6 -- 9 files changed, 138 insertions(+), 149 deletions(-) (limited to 'MediaBrowser.Controller/Entities/UserViewBuilder.cs') diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs index 2393d0533..f027fe9df 100644 --- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs +++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs @@ -6,7 +6,6 @@ using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using ServiceStack; -using System; using System.Collections.Generic; using System.Linq; @@ -128,44 +127,14 @@ namespace MediaBrowser.Api.UserLibrary { if (request is GetAlbumArtists) { - return items - .Where(i => !i.IsFolder) - .OfType() - .SelectMany(i => i.AlbumArtists) - .DistinctNames() - .Select(name => - { - try - { - return LibraryManager.GetArtist(name); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting artist {0}", ex, name); - return null; - } - - }).Where(i => i != null); + return LibraryManager.GetAlbumArtists(items + .Where(i => !i.IsFolder) + .OfType()); } - return items + return LibraryManager.GetArtists(items .Where(i => !i.IsFolder) - .OfType() - .SelectMany(i => i.AllArtists) - .DistinctNames() - .Select(name => - { - try - { - return LibraryManager.GetArtist(name); - } - catch (Exception ex) - { - Logger.ErrorException("Error getting artist {0}", ex, name); - return null; - } - - }).Where(i => i != null); + .OfType()); } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index 8a77d7616..807beee52 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -54,6 +54,12 @@ namespace MediaBrowser.Controller.Entities.Audio get { return AlbumArtists.FirstOrDefault(); } } + [IgnoreDataMember] + public override bool SupportsPeople + { + get { return false; } + } + public List AlbumArtists { get; set; } /// diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 462f66e20..ba2820bc1 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -341,95 +341,43 @@ namespace MediaBrowser.Controller.Entities var items = GetRecursiveChildren(queryParent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) .Where(i => !i.IsFolder) .Where(i => i.Genres.Contains(displayParent.Name, StringComparer.OrdinalIgnoreCase)) - .OfType() - .SelectMany(i => i.AlbumArtists) - .DistinctNames() - .Select(i => - { - try - { - return _libraryManager.GetArtist(i); - } - catch - { - // Already logged at lower levels - return null; - } - }) - .Where(i => i != null); + .OfType(); - return GetResult(items, queryParent, query); + var artists = _libraryManager.GetAlbumArtists(items); + + return GetResult(artists, queryParent, query); } private QueryResult GetMusicAlbumArtists(Folder parent, User user, InternalItemsQuery query) { - var artists = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) + var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) .Where(i => !i.IsFolder) - .OfType() - .SelectMany(i => i.AlbumArtists) - .DistinctNames() - .Select(i => - { - try - { - return _libraryManager.GetArtist(i); - } - catch - { - // Already logged at lower levels - return null; - } - }) - .Where(i => i != null); + .OfType(); + + var artists = _libraryManager.GetAlbumArtists(items); return GetResult(artists, parent, query); } private QueryResult GetMusicArtists(Folder parent, User user, InternalItemsQuery query) { - var artists = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) + var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) .Where(i => !i.IsFolder) - .OfType() - .SelectMany(i => i.Artists) - .DistinctNames() - .Select(i => - { - try - { - return _libraryManager.GetArtist(i); - } - catch - { - // Already logged at lower levels - return null; - } - }) - .Where(i => i != null); + .OfType(); + var artists = _libraryManager.GetArtists(items); + return GetResult(artists, parent, query); } private QueryResult GetFavoriteArtists(Folder parent, User user, InternalItemsQuery query) { - var artists = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) + var items = GetRecursiveChildren(parent, user, new[] { CollectionType.Music, CollectionType.MusicVideos }) .Where(i => !i.IsFolder) - .OfType() - .SelectMany(i => i.AlbumArtists) - .DistinctNames() - .Select(i => - { - try - { - return _libraryManager.GetArtist(i); - } - catch - { - // Already logged at lower levels - return null; - } - }) - .Where(i => i != null && _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite); + .OfType(); + var artists = _libraryManager.GetAlbumArtists(items).Where(i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite); + return GetResult(artists, parent, query); } diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 77c07dfd4..9c52fd2dc 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -61,7 +61,18 @@ namespace MediaBrowser.Controller.Library /// The name. /// Task{Artist}. MusicArtist GetArtist(string name); - + /// + /// Gets the album artists. + /// + /// The items. + /// IEnumerable<MusicArtist>. + IEnumerable GetAlbumArtists(IEnumerable items); + /// + /// Gets the artists. + /// + /// The items. + /// IEnumerable<MusicArtist>. + IEnumerable GetArtists(IEnumerable items); /// /// Gets a Studio /// diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index 664eff004..6748c2ba5 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -280,7 +280,7 @@ namespace MediaBrowser.Providers.Music { // MusicBrainz is extremely adamant about limiting to one request per second - await Task.Delay(800, cancellationToken).ConfigureAwait(false); + await Task.Delay(1000, cancellationToken).ConfigureAwait(false); var doc = new XmlDocument(); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index e89c83397..c9a5cb731 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -939,26 +939,7 @@ namespace MediaBrowser.Server.Implementations.Library } } - var fileInfo = new DirectoryInfo(path); - - var isNew = false; - - if (!fileInfo.Exists) - { - try - { - fileInfo = Directory.CreateDirectory(path); - } - catch (UnauthorizedAccessException ex) - { - _logger.Error("Error creating directory {0}", ex, path); - throw new Exception(string.Format("Error creating directory {0}", path), ex); - } - - isNew = true; - } - - var item = isNew ? null : GetItemById(id) as T; + var item = GetItemById(id) as T; if (item == null) { @@ -966,8 +947,8 @@ namespace MediaBrowser.Server.Implementations.Library { Name = name, Id = id, - DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo), - DateModified = _fileSystem.GetLastWriteTimeUtc(fileInfo), + DateCreated = DateTime.UtcNow, + DateModified = DateTime.UtcNow, Path = path }; } @@ -980,6 +961,59 @@ namespace MediaBrowser.Server.Implementations.Library return item; } + public IEnumerable GetAlbumArtists(IEnumerable items) + { + var names = items + .SelectMany(i => i.AlbumArtists) + .DistinctNames() + .Select(i => + { + try + { + var artist = GetArtist(i); + + return artist; + } + catch + { + // Already logged at lower levels + return null; + } + }) + .Where(i => i != null); + + return names; + } + + public IEnumerable GetArtists(IEnumerable items) + { + var names = items + .SelectMany(i => i.AllArtists) + .DistinctNames() + .Select(i => + { + try + { + var artist = GetArtist(i); + + return artist; + } + catch + { + // Already logged at lower levels + return null; + } + }) + .Where(i => i != null); + + return names; + } + + private void SetPropertiesFromSongs(MusicArtist artist, IEnumerable items) + { + + } + /// /// Validate and refresh the People sub-set of the IBN. /// The items are stored in the db but not loaded into memory until actually requested by an operation. @@ -2118,6 +2152,11 @@ namespace MediaBrowser.Server.Implementations.Library public Task UpdatePeople(BaseItem item, List people) { + if (!item.SupportsPeople) + { + return Task.FromResult(true); + } + return ItemRepository.UpdatePeople(item.Id, people); } } diff --git a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs index c9440bb27..68d351b44 100644 --- a/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs +++ b/MediaBrowser.Server.Implementations/Library/Validators/ArtistsValidator.cs @@ -48,26 +48,22 @@ namespace MediaBrowser.Server.Implementations.Library.Validators .Cast() .ToList(); - var allArtists = allSongs.SelectMany(i => i.AllArtists) - .DistinctNames() - .ToList(); + var allArtists = _libraryManager.GetArtists(allSongs).ToList(); var numComplete = 0; var numArtists = allArtists.Count; - foreach (var artist in allArtists) + foreach (var artistItem in allArtists) { cancellationToken.ThrowIfCancellationRequested(); try { - var artistItem = _libraryManager.GetArtist(artist); - await artistItem.RefreshMetadata(cancellationToken).ConfigureAwait(false); } catch (IOException ex) { - _logger.ErrorException("Error validating Artist {0}", ex, artist); + _logger.ErrorException("Error validating Artist {0}", ex, artistItem.Name); } // Update progress diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 6861901ac..aa883ce75 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1398,14 +1398,40 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.EpisodeTitle = program.EpisodeTitle; dto.ChannelType = program.ChannelType; dto.Audio = program.Audio; - dto.IsHD = program.IsHD; - dto.IsMovie = program.IsMovie; - dto.IsSeries = program.IsSeries; - dto.IsSports = program.IsSports; - dto.IsLive = program.IsLive; - dto.IsNews = program.IsNews; - dto.IsKids = program.IsKids; - dto.IsPremiere = program.IsPremiere; + + if (program.IsHD.HasValue && program.IsHD.Value) + { + dto.IsHD = program.IsHD; + } + if (program.IsMovie) + { + dto.IsMovie = program.IsMovie; + } + if (program.IsSeries) + { + dto.IsSeries = program.IsSeries; + } + if (program.IsSports) + { + dto.IsSports = program.IsSports; + } + if (program.IsLive) + { + dto.IsLive = program.IsLive; + } + if (program.IsNews) + { + dto.IsNews = program.IsNews; + } + if (program.IsKids) + { + dto.IsKids = program.IsKids; + } + if (program.IsPremiere) + { + dto.IsPremiere = program.IsPremiere; + } + dto.OriginalAirDate = program.OriginalAirDate; if (channel != null) diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 0162b8802..ca2568a0f 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -155,12 +155,6 @@ namespace MediaBrowser.Server.Implementations.UserViews SpecialFolder.MovieMovies, SpecialFolder.MovieResume, - SpecialFolder.GameFavorites, - SpecialFolder.GameGenres, - SpecialFolder.GameSystems, - SpecialFolder.LatestGames, - SpecialFolder.RecentlyPlayedGames, - SpecialFolder.MusicArtists, SpecialFolder.MusicAlbumArtists, SpecialFolder.MusicAlbums, -- cgit v1.2.3 From 032891c9f3327ca626938ca175d7d4623e6a27d0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 14 Aug 2015 14:00:26 -0400 Subject: update user views --- .../Entities/UserViewBuilder.cs | 86 ++++++++++------------ MediaBrowser.Controller/Library/ILibraryManager.cs | 32 +++++++- .../Library/IUserViewManager.cs | 5 +- .../Channels/ChannelManager.cs | 3 +- .../Library/LibraryManager.cs | 83 ++++++++++++++++++++- .../Library/UserViewManager.cs | 12 +-- .../LiveTv/LiveTvManager.cs | 3 +- 7 files changed, 161 insertions(+), 63 deletions(-) (limited to 'MediaBrowser.Controller/Entities/UserViewBuilder.cs') diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index ba2820bc1..cee5dadd2 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -285,14 +285,14 @@ namespace MediaBrowser.Controller.Entities var list = new List(); - list.Add(await GetUserView(SpecialFolder.MusicLatest, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicPlaylists, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicAlbums, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, user, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicLatest, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicPlaylists, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicAlbums, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicAlbumArtists, "3", parent).ConfigureAwait(false)); //list.Add(await GetUserView(SpecialFolder.MusicArtists, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicSongs, user, "5", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicGenres, user, "6", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavorites, user, "7", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicSongs, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicGenres, "6", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavorites, "7", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -301,9 +301,9 @@ namespace MediaBrowser.Controller.Entities { var list = new List(); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, user, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteAlbums, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteArtists, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MusicFavoriteSongs, "2", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -329,7 +329,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.MusicGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -366,7 +366,7 @@ namespace MediaBrowser.Controller.Entities .OfType(); var artists = _libraryManager.GetArtists(items); - + return GetResult(artists, parent, query); } @@ -377,7 +377,7 @@ namespace MediaBrowser.Controller.Entities .OfType(); var artists = _libraryManager.GetAlbumArtists(items).Where(i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite); - + return GetResult(artists, parent, query); } @@ -443,12 +443,12 @@ namespace MediaBrowser.Controller.Entities var list = new List(); - list.Add(await GetUserView(SpecialFolder.MovieResume, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieLatest, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieMovies, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieCollections, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieFavorites, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.MovieGenres, user, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieResume, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieLatest, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieMovies, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieCollections, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieFavorites, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.MovieGenres, "5", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -554,7 +554,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.MovieGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.MovieGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -616,13 +616,13 @@ namespace MediaBrowser.Controller.Entities var list = new List(); - list.Add(await GetUserView(SpecialFolder.TvResume, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvNextUp, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvLatest, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvShowSeries, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvFavoriteSeries, user, "4", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvFavoriteEpisodes, user, "5", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.TvGenres, user, "6", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvResume, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvNextUp, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvLatest, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvShowSeries, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvFavoriteSeries, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvFavoriteEpisodes, "5", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.TvGenres, "6", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -637,11 +637,11 @@ namespace MediaBrowser.Controller.Entities var list = new List(); - list.Add(await GetUserView(SpecialFolder.LatestGames, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.RecentlyPlayedGames, user, "1", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameFavorites, user, "2", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameSystems, user, "3", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.GameGenres, user, "4", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LatestGames, "0", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.RecentlyPlayedGames, "1", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameFavorites, "2", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameSystems, "3", parent).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.GameGenres, "4", parent).ConfigureAwait(false)); return GetResult(list, parent, query); } @@ -739,7 +739,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.TvGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.TvGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -791,7 +791,7 @@ namespace MediaBrowser.Controller.Entities }) .Where(i => i != null) - .Select(i => GetUserView(i.Name, SpecialFolder.GameGenre, user, i.SortName, parent)); + .Select(i => GetUserView(i.Name, SpecialFolder.GameGenre, i.SortName, parent)); var genres = await Task.WhenAll(tasks).ConfigureAwait(false); @@ -1871,26 +1871,20 @@ namespace MediaBrowser.Controller.Entities var list = new List(); //list.Add(await GetUserSubView(SpecialFolder.LiveTvNowPlaying, user, "0", parent).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.LiveTvChannels, user, string.Empty, user.RootFolder).ConfigureAwait(false)); - list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, user, string.Empty, user.RootFolder).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LiveTvChannels, string.Empty, user.RootFolder).ConfigureAwait(false)); + list.Add(await GetUserView(SpecialFolder.LiveTvRecordingGroups, string.Empty, user.RootFolder).ConfigureAwait(false)); return GetResult(list, queryParent, query); } - private async Task GetUserView(string name, string type, User user, string sortName, BaseItem parent) + private Task GetUserView(string name, string type, string sortName, BaseItem parent) { - var view = await _userViewManager.GetUserSubView(name, parent.Id.ToString("N"), type, user, sortName, CancellationToken.None) - .ConfigureAwait(false); - - return view; + return _userViewManager.GetUserSubView(name, parent.Id.ToString("N"), type, sortName, CancellationToken.None); } - private async Task GetUserView(string type, User user, string sortName, BaseItem parent) + private Task GetUserView(string type, string sortName, BaseItem parent) { - var view = await _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, user, sortName, CancellationToken.None) - .ConfigureAwait(false); - - return view; + return _userViewManager.GetUserSubView(parent.Id.ToString("N"), type, sortName, CancellationToken.None); } public static bool IsYearMismatched(BaseItem item, ILibraryManager libraryManager) diff --git a/MediaBrowser.Controller/Library/ILibraryManager.cs b/MediaBrowser.Controller/Library/ILibraryManager.cs index 9c52fd2dc..6906a25fb 100644 --- a/MediaBrowser.Controller/Library/ILibraryManager.cs +++ b/MediaBrowser.Controller/Library/ILibraryManager.cs @@ -351,7 +351,37 @@ namespace MediaBrowser.Controller.Library Task GetNamedView(User user, string name, string viewType, - string sortName, + string sortName, + CancellationToken cancellationToken); + + /// + /// Gets the named view. + /// + /// The name. + /// Type of the view. + /// Name of the sort. + /// The cancellation token. + /// Task<UserView>. + Task GetNamedView(string name, + string viewType, + string sortName, + CancellationToken cancellationToken); + + /// + /// Gets the named view. + /// + /// The name. + /// The parent identifier. + /// Type of the view. + /// Name of the sort. + /// The unique identifier. + /// The cancellation token. + /// Task<UserView>. + Task GetNamedView(string name, + string parentId, + string viewType, + string sortName, + string uniqueId, CancellationToken cancellationToken); /// diff --git a/MediaBrowser.Controller/Library/IUserViewManager.cs b/MediaBrowser.Controller/Library/IUserViewManager.cs index f0b862c2d..5391d113e 100644 --- a/MediaBrowser.Controller/Library/IUserViewManager.cs +++ b/MediaBrowser.Controller/Library/IUserViewManager.cs @@ -12,10 +12,9 @@ namespace MediaBrowser.Controller.Library { Task> GetUserViews(UserViewQuery query, CancellationToken cancellationToken); - Task GetUserSubView(string name, string parentId, string type, User user, string sortName, - CancellationToken cancellationToken); + Task GetUserSubView(string name, string parentId, string type, string sortName, CancellationToken cancellationToken); - Task GetUserSubView(string category, string type, User user, string sortName, CancellationToken cancellationToken); + Task GetUserSubView(string category, string type, string sortName, CancellationToken cancellationToken); List>> GetLatestItems(LatestItemsQuery request); } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index fbecaa65d..cbbed856c 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -1407,9 +1407,8 @@ namespace MediaBrowser.Server.Implementations.Channels public async Task GetInternalChannelFolder(string userId, CancellationToken cancellationToken) { var name = _localization.GetLocalizedString("ViewTypeChannels"); - var user = _userManager.GetUserById(userId); - return await _libraryManager.GetNamedView(user, name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false); + return await _libraryManager.GetNamedView(name, "channels", "zz_" + name, cancellationToken).ConfigureAwait(false); } public async Task DownloadChannelItem(IChannelMediaItem item, string destination, diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index dfcc1370e..1d2e5e322 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1651,7 +1651,7 @@ namespace MediaBrowser.Server.Implementations.Library private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); - public async Task GetNamedView(User user, + public Task GetNamedView(User user, string name, string viewType, string sortName, @@ -1659,10 +1659,17 @@ namespace MediaBrowser.Server.Implementations.Library { if (ConfigurationManager.Configuration.EnableUserSpecificUserViews) { - return await GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken) - .ConfigureAwait(false); + return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); } + return GetNamedView(name, viewType, sortName, cancellationToken); + } + + public async Task GetNamedView(string name, + string viewType, + string sortName, + CancellationToken cancellationToken) + { var path = Path.Combine(ConfigurationManager.ApplicationPaths.ItemsByNamePath, "views"); @@ -1806,6 +1813,76 @@ namespace MediaBrowser.Server.Implementations.Library return item; } + public async Task GetNamedView(string name, + string parentId, + string viewType, + string sortName, + string uniqueId, + CancellationToken cancellationToken) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentNullException("name"); + } + + var idValues = "37_namedview_" + name + (parentId ?? string.Empty); + if (!string.IsNullOrWhiteSpace(uniqueId)) + { + idValues += uniqueId; + } + + var id = GetNewItemId(idValues, typeof(UserView)); + + var path = Path.Combine(ConfigurationManager.ApplicationPaths.InternalMetadataPath, "views", id.ToString("N")); + + var item = GetItemById(id) as UserView; + + var isNew = false; + + if (item == null) + { + Directory.CreateDirectory(path); + + item = new UserView + { + Path = path, + Id = id, + DateCreated = DateTime.UtcNow, + Name = name, + ViewType = viewType, + ForcedSortName = sortName + }; + + if (!string.IsNullOrWhiteSpace(parentId)) + { + item.ParentId = new Guid(parentId); + } + + await CreateItem(item, cancellationToken).ConfigureAwait(false); + + isNew = true; + } + + if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase)) + { + item.ViewType = viewType; + await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); + } + + var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + + if (refresh) + { + _providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions + { + // Need to force save to increment DateLastSaved + ForceSave = true + }); + } + + return item; + } + public bool IsVideoFile(string path) { var resolver = new VideoResolver(GetNamingOptions(), new PatternsLogger()); diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 61b28a072..c32dc0d41 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -167,8 +167,8 @@ namespace MediaBrowser.Server.Implementations.Library if (_liveTvManager.GetEnabledUsers().Select(i => i.Id.ToString("N")).Contains(query.UserId)) { - //list.Add(await _liveTvManager.GetInternalLiveTvFolder(query.UserId, cancellationToken).ConfigureAwait(false)); - list.Add(await GetUserView(new List(), list, CollectionType.LiveTv, string.Empty, user, cancellationToken).ConfigureAwait(false)); + var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.LiveTv); + list.Add(await _libraryManager.GetNamedView(name, CollectionType.LiveTv, string.Empty, cancellationToken).ConfigureAwait(false)); } } @@ -187,18 +187,18 @@ namespace MediaBrowser.Server.Implementations.Library .ThenBy(i => i.SortName); } - public Task GetUserSubView(string name, string parentId, string type, User user, string sortName, CancellationToken cancellationToken) + public Task GetUserSubView(string name, string parentId, string type, string sortName, CancellationToken cancellationToken) { var uniqueId = parentId + "subview" + type; - return _libraryManager.GetNamedView(user, name, parentId, type, sortName, uniqueId, cancellationToken); + return _libraryManager.GetNamedView(name, parentId, type, sortName, uniqueId, cancellationToken); } - public Task GetUserSubView(string parentId, string type, User user, string sortName, CancellationToken cancellationToken) + public Task GetUserSubView(string parentId, string type, string sortName, CancellationToken cancellationToken) { var name = _localizationManager.GetLocalizedString("ViewType" + type); - return GetUserSubView(name, parentId, type, user, sortName, cancellationToken); + return GetUserSubView(name, parentId, type, sortName, cancellationToken); } public async Task GetUserView(List parents, List currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 389eda904..cc3c06dd4 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -2204,8 +2204,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task GetInternalLiveTvFolder(string userId, CancellationToken cancellationToken) { var name = _localization.GetLocalizedString("ViewTypeLiveTV"); - var user = _userManager.GetUserById(userId); - return await _libraryManager.GetNamedView(user, name, "livetv", "zz_" + name, cancellationToken).ConfigureAwait(false); + return await _libraryManager.GetNamedView(name, "livetv", "zz_" + name, cancellationToken).ConfigureAwait(false); } public async Task SaveTunerHost(TunerHostInfo info) -- cgit v1.2.3