From 4309455c37c25eb7b4ab89920358d7cced1ebddc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Mar 2015 01:29:39 -0400 Subject: [PATCH 01/11] update server sync --- .../MediaBrowser.Controller.csproj | 1 + .../Sync/IServerSyncProvider.cs | 2 +- .../Sync/SendFileResult.cs | 18 +++++++++++++++ .../Sync/MediaSync.cs | 17 +++++++++++--- .../Sync/SyncJobProcessor.cs | 4 ++++ .../Sync/SyncedMediaSourceProvider.cs | 23 +------------------ Nuget/MediaBrowser.Common.Internal.nuspec | 4 ++-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 ++-- 10 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 MediaBrowser.Controller/Sync/SendFileResult.cs diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index f046c76fc9..704637773e 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -350,6 +350,7 @@ + diff --git a/MediaBrowser.Controller/Sync/IServerSyncProvider.cs b/MediaBrowser.Controller/Sync/IServerSyncProvider.cs index 98ea2ce06e..422349b80e 100644 --- a/MediaBrowser.Controller/Sync/IServerSyncProvider.cs +++ b/MediaBrowser.Controller/Sync/IServerSyncProvider.cs @@ -18,7 +18,7 @@ namespace MediaBrowser.Controller.Sync /// The progress. /// The cancellation token. /// Task. - Task SendFile(Stream stream, string remotePath, SyncTarget target, IProgress progress, CancellationToken cancellationToken); + Task SendFile(Stream stream, string remotePath, SyncTarget target, IProgress progress, CancellationToken cancellationToken); /// /// Deletes the file. diff --git a/MediaBrowser.Controller/Sync/SendFileResult.cs b/MediaBrowser.Controller/Sync/SendFileResult.cs new file mode 100644 index 0000000000..62753444a4 --- /dev/null +++ b/MediaBrowser.Controller/Sync/SendFileResult.cs @@ -0,0 +1,18 @@ +using MediaBrowser.Model.MediaInfo; + +namespace MediaBrowser.Controller.Sync +{ + public class SendFileResult + { + /// + /// Gets or sets the path. + /// + /// The path. + public string Path { get; set; } + /// + /// Gets or sets the protocol. + /// + /// The protocol. + public MediaProtocol Protocol { get; set; } + } +} diff --git a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs index 8391dbd7a2..48f682f98a 100644 --- a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs +++ b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs @@ -152,7 +152,18 @@ namespace MediaBrowser.Server.Implementations.Sync try { - await SendFile(provider, internalSyncJobItem.OutputPath, localItem, target, cancellationToken).ConfigureAwait(false); + var sendFileResult = await SendFile(provider, internalSyncJobItem.OutputPath, localItem, target, cancellationToken).ConfigureAwait(false); + + if (localItem.Item.MediaSources != null) + { + var mediaSource = localItem.Item.MediaSources.FirstOrDefault(); + if (mediaSource != null) + { + mediaSource.Path = sendFileResult.Path; + mediaSource.Protocol = sendFileResult.Protocol; + mediaSource.SupportsTranscoding = false; + } + } // Create db record await dataProvider.AddOrUpdate(target, localItem).ConfigureAwait(false); @@ -203,11 +214,11 @@ namespace MediaBrowser.Server.Implementations.Sync } } - private async Task SendFile(IServerSyncProvider provider, string inputPath, LocalItem item, SyncTarget target, CancellationToken cancellationToken) + private async Task SendFile(IServerSyncProvider provider, string inputPath, LocalItem item, SyncTarget target, CancellationToken cancellationToken) { using (var stream = _fileSystem.GetFileStream(inputPath, FileMode.Open, FileAccess.Read, FileShare.Read, true)) { - await provider.SendFile(stream, item.LocalPath, target, new Progress(), cancellationToken).ConfigureAwait(false); + return await provider.SendFile(stream, item.LocalPath, target, new Progress(), cancellationToken).ConfigureAwait(false); } } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs index 2dbf8fc1b6..8fb4b5a3ad 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncJobProcessor.cs @@ -581,6 +581,8 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.MediaSource = mediaSource; } + jobItem.MediaSource.SupportsTranscoding = false; + if (externalSubs.Count > 0) { // Save the job item now since conversion could take a while @@ -757,6 +759,8 @@ namespace MediaBrowser.Server.Implementations.Sync jobItem.MediaSource = mediaSource; } + jobItem.MediaSource.SupportsTranscoding = false; + jobItem.Progress = 50; jobItem.Status = SyncJobItemStatus.ReadyToTransfer; await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs index 0422e97919..93a466c526 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs @@ -3,11 +3,9 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Sync; using MediaBrowser.Model.Dto; -using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Sync; using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -58,7 +56,7 @@ namespace MediaBrowser.Server.Implementations.Sync foreach (var localItem in localItems) { - list.AddRange(GetPlayableMediaSources(localItem)); + list.AddRange(localItem.Item.MediaSources); } } } @@ -66,24 +64,5 @@ namespace MediaBrowser.Server.Implementations.Sync return list; } - - private IEnumerable GetPlayableMediaSources(LocalItem item) - { - return item.Item.MediaSources - .Where(IsMediaSourcePlayable); - } - - private bool IsMediaSourcePlayable(MediaSourceInfo mediaSource) - { - if (mediaSource.Protocol == MediaProtocol.File) - { - if (!File.Exists(mediaSource.Path)) - { - return false; - } - } - - return true; - } } } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 757a2c44c7..1fd0330406 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.584 + 3.0.585 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index f70af82b53..ccdf22b667 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.584 + 3.0.585 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 13a9c8f62f..4d3821d260 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.584 + 3.0.585 MediaBrowser.Model - Signed Edition Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 9cad3b441c..42246916f8 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.584 + 3.0.585 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - + From a92723fde3fc44410c782ee93d36c749ae8d6f82 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Mar 2015 11:54:20 -0400 Subject: [PATCH 02/11] add AlbumArtists to item dto's --- MediaBrowser.Api/ItemUpdateService.cs | 5 ++++- MediaBrowser.Api/UserLibrary/ItemsService.cs | 16 -------------- .../Entities/InternalItemsQuery.cs | 2 -- .../Entities/UserViewBuilder.cs | 11 ---------- .../MediaBrowser.Model.Portable.csproj | 3 +++ .../MediaBrowser.Model.net35.csproj | 3 +++ MediaBrowser.Model/Dto/BaseItemDto.cs | 6 +++++ MediaBrowser.Model/Dto/NameIdPair.cs | 17 ++++++++++++++ MediaBrowser.Model/LiveTv/RecordingInfoDto.cs | 4 ++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.Model/Querying/ItemQuery.cs | 6 ----- .../Dto/DtoService.cs | 22 +++++++++++++++++++ .../Localization/Server/server.json | 1 + .../Sync/SyncManager.cs | 8 +++++++ .../Sync/SyncRepository.cs | 2 +- 15 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 MediaBrowser.Model/Dto/NameIdPair.cs diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 6517d738b9..bdcad73b0d 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -394,7 +394,10 @@ namespace MediaBrowser.Api if (song != null) { song.Album = request.Album; - song.AlbumArtists = string.IsNullOrWhiteSpace(request.AlbumArtist) ? new List() : new List { request.AlbumArtist }; + song.AlbumArtists = request + .AlbumArtists + .Select(i => i.Name) + .ToList(); song.Artists = request.Artists.ToList(); } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 9b5ef3a981..0b636e93b4 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -46,9 +46,6 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "PersonTypes", Description = "Optional. If specified, along with Person, results will be filtered to include only those containing the specified person and PersonType. Allows multiple, comma-delimited", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string PersonTypes { get; set; } - [ApiMember(Name = "AllGenres", Description = "Optional. If specified, results will be filtered based on genre. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string AllGenres { get; set; } - /// /// Limit results to items containing specific studios /// @@ -226,11 +223,6 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "CollapseBoxSetItems", Description = "Whether or not to hide items behind their boxsets.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool? CollapseBoxSetItems { get; set; } - public string[] GetAllGenres() - { - return (AllGenres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); - } - public string[] GetStudios() { return (Studios ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); @@ -471,7 +463,6 @@ namespace MediaBrowser.Api.UserLibrary Tags = request.GetTags(), OfficialRatings = request.GetOfficialRatings(), Genres = request.GetGenres(), - AllGenres = request.GetAllGenres(), Studios = request.GetStudios(), Person = request.Person, PersonTypes = request.GetPersonTypes(), @@ -930,13 +921,6 @@ namespace MediaBrowser.Api.UserLibrary return false; } - // Apply genre filter - var allGenres = request.GetAllGenres(); - if (allGenres.Length > 0 && !allGenres.All(v => i.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))) - { - return false; - } - // Filter by VideoType if (!string.IsNullOrEmpty(request.VideoTypes)) { diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index e99c11e87d..ccd499a579 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -30,7 +30,6 @@ namespace MediaBrowser.Controller.Entities public string[] IncludeItemTypes { get; set; } public string[] ExcludeItemTypes { get; set; } public string[] Genres { get; set; } - public string[] AllGenres { get; set; } public bool? IsMissing { get; set; } public bool? IsUnaired { get; set; } @@ -80,7 +79,6 @@ namespace MediaBrowser.Controller.Entities MediaTypes = new string[] { }; IncludeItemTypes = new string[] { }; ExcludeItemTypes = new string[] { }; - AllGenres = new string[] { }; Genres = new string[] { }; Studios = new string[] { }; ImageTypes = new ImageType[] { }; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index 35ada4aef0..c8f9339da3 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -935,11 +935,6 @@ namespace MediaBrowser.Controller.Entities return false; } - if (request.AllGenres.Length > 0) - { - return false; - } - if (request.Genres.Length > 0) { return false; @@ -1569,12 +1564,6 @@ namespace MediaBrowser.Controller.Entities return false; } - // Apply genre filter - if (query.AllGenres.Length > 0 && !query.AllGenres.All(v => item.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))) - { - return false; - } - // Filter by VideoType if (query.VideoTypes.Length > 0) { diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 2e61ed89cb..b72a895ca2 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -491,6 +491,9 @@ Dto\MetadataEditorInfo.cs + + Dto\NameIdPair.cs + Dto\NameValuePair.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index ba4ac22e7c..7a28f6de83 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -459,6 +459,9 @@ Dto\MetadataEditorInfo.cs + + Dto\NameIdPair.cs + Dto\NameValuePair.cs diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 113a4c6f44..66066e392d 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -507,6 +507,12 @@ namespace MediaBrowser.Model.Dto /// The album artist. public string AlbumArtist { get; set; } + /// + /// Gets or sets the album artists. + /// + /// The album artists. + public List AlbumArtists { get; set; } + /// /// Gets or sets the name of the season. /// diff --git a/MediaBrowser.Model/Dto/NameIdPair.cs b/MediaBrowser.Model/Dto/NameIdPair.cs new file mode 100644 index 0000000000..d3931516cd --- /dev/null +++ b/MediaBrowser.Model/Dto/NameIdPair.cs @@ -0,0 +1,17 @@ + +namespace MediaBrowser.Model.Dto +{ + public class NameIdPair + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + /// + /// Gets or sets the identifier. + /// + /// The identifier. + public string Id { get; set; } + } +} diff --git a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs index a6cd85d8d3..d6d6980381 100644 --- a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs @@ -273,6 +273,10 @@ namespace MediaBrowser.Model.LiveTv /// The type. public string Type { get; set; } + /// + /// Gets or sets the media sources. + /// + /// The media sources. public List MediaSources { get; set; } public RecordingInfoDto() diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 14ec093ec6..fd50e598a9 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -139,6 +139,7 @@ + diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index 0f929fa9bb..a40eca5b5a 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -92,12 +92,6 @@ namespace MediaBrowser.Model.Querying /// The genres. public string[] Genres { get; set; } - /// - /// Limit results to items containing specific genres - /// - /// The genres. - public string[] AllGenres { get; set; } - /// /// Limit results to items containing specific studios /// diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index f9b7470b2c..8086033ebb 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -1175,6 +1175,28 @@ namespace MediaBrowser.Server.Implementations.Dto if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); + + dto.AlbumArtists = hasAlbumArtist + .AlbumArtists + .Select(i => + { + try + { + var artist = _libraryManager.GetArtist(i); + return new NameIdPair + { + Name = artist.Name, + Id = artist.Id.ToString("N") + }; + } + catch (Exception ex) + { + _logger.ErrorException("Error getting album artist", ex); + return null; + } + }) + .Where(i => i != null) + .ToList(); } // Add video info diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 9464309b70..4935170046 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -1172,6 +1172,7 @@ "LabelIfYouWishToContinueWithDeletion": "If you wish to continue, please confirm by entering the value of:", "ButtonIdentify": "Identify", "LabelAlbumArtist": "Album artist:", + "LabelAlbumArtists": "Album artists:", "LabelAlbum": "Album:", "LabelCommunityRating": "Community rating:", "LabelVoteCount": "Vote count:", diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index a974a7675a..0bf9a2e23a 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -136,6 +136,14 @@ namespace MediaBrowser.Server.Implementations.Sync var jobId = Guid.NewGuid().ToString("N"); + if (string.IsNullOrWhiteSpace(request.Quality)) + { + request.Quality = GetQualityOptions(request.TargetId) + .Where(i => i.IsDefault) + .Select(i => i.Id) + .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); + } + var job = new SyncJob { Id = jobId, diff --git a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs index 45b35523a6..9d820eaa2b 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncRepository.cs @@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Sync string[] queries = { - "create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT NOT NULL, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)", + "create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Quality TEXT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)", "create index if not exists idx_SyncJobs on SyncJobs(Id)", "create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT)", From 96ec4cef77d98b0cad42a7b105e025df3543784d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 13 Mar 2015 13:25:28 -0400 Subject: [PATCH 03/11] add ArtistItems to api output --- MediaBrowser.Api/ItemRefreshService.cs | 2 +- MediaBrowser.Api/ItemUpdateService.cs | 26 +++++++---- MediaBrowser.Api/Music/AlbumsService.cs | 10 ++--- MediaBrowser.Api/SearchService.cs | 2 +- MediaBrowser.Api/UserLibrary/ItemsService.cs | 45 +++++++++++++------ .../Entities/Audio/Audio.cs | 10 ----- .../Entities/Audio/IHasAlbumArtist.cs | 20 +++++++-- .../Entities/Audio/MusicAlbum.cs | 10 ----- .../Entities/Audio/MusicArtist.cs | 2 +- .../Entities/MusicVideo.cs | 10 ----- MediaBrowser.Controller/Playlists/Playlist.cs | 2 +- .../MediaBrowser.Model.Portable.csproj | 3 -- .../MediaBrowser.Model.net35.csproj | 3 -- MediaBrowser.Model/ApiClient/IApiClient.cs | 4 +- MediaBrowser.Model/Dto/BaseItemDto.cs | 6 +++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 - MediaBrowser.Model/Querying/ItemQuery.cs | 10 ++--- .../Querying/SimilarItemsByNameQuery.cs | 29 ------------ .../MediaInfo/FFProbeAudioInfo.cs | 2 +- .../Dto/DtoService.cs | 39 +++++++++++----- .../Library/MusicManager.cs | 2 +- 21 files changed, 117 insertions(+), 121 deletions(-) delete mode 100644 MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 78bc14ab09..6a7b4826c4 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -53,7 +53,7 @@ namespace MediaBrowser.Api var albums = _libraryManager.RootFolder .GetRecursiveChildren() .OfType() - .Where(i => i.HasArtist(item.Name)) + .Where(i => i.HasAnyArtist(item.Name)) .ToList(); var musicArtists = albums diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index bdcad73b0d..86689f5cf3 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -389,23 +389,33 @@ namespace MediaBrowser.Api game.PlayersSupported = request.Players; } - var song = item as Audio; - - if (song != null) + var hasAlbumArtists = item as IHasAlbumArtist; + if (hasAlbumArtists != null) { - song.Album = request.Album; - song.AlbumArtists = request + hasAlbumArtists.AlbumArtists = request .AlbumArtists .Select(i => i.Name) .ToList(); - song.Artists = request.Artists.ToList(); } - var musicVideo = item as MusicVideo; + var hasArtists = item as IHasArtist; + if (hasArtists != null) + { + hasArtists.Artists = request + .ArtistItems + .Select(i => i.Name) + .ToList(); + } + + var song = item as Audio; + if (song != null) + { + song.Album = request.Album; + } + var musicVideo = item as MusicVideo; if (musicVideo != null) { - musicVideo.Artists = request.Artists.ToList(); musicVideo.Album = request.Album; } diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs index 76c6c57764..a1c98addbe 100644 --- a/MediaBrowser.Api/Music/AlbumsService.cs +++ b/MediaBrowser.Api/Music/AlbumsService.cs @@ -77,15 +77,13 @@ namespace MediaBrowser.Api.Music var album1 = (MusicAlbum)item1; var album2 = (MusicAlbum)item2; - var artists1 = album1.GetRecursiveChildren(i => i is IHasArtist) - .Cast() - .SelectMany(i => i.AllArtists) + var artists1 = album1 + .AllArtists .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); - var artists2 = album2.GetRecursiveChildren(i => i is IHasArtist) - .Cast() - .SelectMany(i => i.AllArtists) + var artists2 = album2 + .AllArtists .Distinct(StringComparer.OrdinalIgnoreCase) .ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index ee48946d5d..2cca72593b 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -211,7 +211,7 @@ namespace MediaBrowser.Api result.SongCount = album.Tracks.Count(); result.Artists = album.Artists.ToArray(); - result.AlbumArtist = album.AlbumArtists.FirstOrDefault(); + result.AlbumArtist = album.AlbumArtist; } var song = item as Audio; diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 0b636e93b4..256ae3625c 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -60,6 +60,9 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "Artists", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Artists { get; set; } + [ApiMember(Name = "ArtistIds", Description = "Optional. If specified, results will be filtered based on artist. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string ArtistIds { get; set; } + [ApiMember(Name = "Albums", Description = "Optional. If specified, results will be filtered based on album. This allows multiple, pipe delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Albums { get; set; } @@ -600,6 +603,8 @@ namespace MediaBrowser.Api.UserLibrary private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, bool isPreFiltered, ILibraryManager libraryManager) { + var video = i as Video; + if (!isPreFiltered) { var mediaTypes = request.GetMediaTypes(); @@ -647,7 +652,6 @@ namespace MediaBrowser.Api.UserLibrary if (request.Is3D.HasValue) { var val = request.Is3D.Value; - var video = i as Video; if (video == null || val != video.Video3DFormat.HasValue) { @@ -658,7 +662,6 @@ namespace MediaBrowser.Api.UserLibrary if (request.IsHD.HasValue) { var val = request.IsHD.Value; - var video = i as Video; if (video == null || val != video.IsHD) { @@ -800,8 +803,6 @@ namespace MediaBrowser.Api.UserLibrary { var val = request.HasSubtitles.Value; - var video = i as Video; - if (video == null || val != video.HasSubtitles) { return false; @@ -922,15 +923,10 @@ namespace MediaBrowser.Api.UserLibrary } // Filter by VideoType - if (!string.IsNullOrEmpty(request.VideoTypes)) + var videoTypes = request.GetVideoTypes(); + if (video == null || !videoTypes.Contains(video.VideoType)) { - var types = request.VideoTypes.Split(','); - - var video = i as Video; - if (video == null || !types.Contains(video.VideoType.ToString(), StringComparer.OrdinalIgnoreCase)) - { - return false; - } + return false; } var imageTypes = request.GetImageTypes().ToList(); @@ -1014,6 +1010,29 @@ namespace MediaBrowser.Api.UserLibrary } } + // Artists + if (!string.IsNullOrEmpty(request.ArtistIds)) + { + var artistIds = request.ArtistIds.Split('|'); + + var audio = i as IHasArtist; + + if (!(audio != null && artistIds.Any(id => + { + try + { + return audio.HasAnyArtist(libraryManager.GetItemById(id).Name); + } + catch (Exception ex) + { + return false; + } + }))) + { + return false; + } + } + // Artists if (!string.IsNullOrEmpty(request.Artists)) { @@ -1021,7 +1040,7 @@ namespace MediaBrowser.Api.UserLibrary var audio = i as IHasArtist; - if (!(audio != null && artists.Any(audio.HasArtist))) + if (!(audio != null && artists.Any(audio.HasAnyArtist))) { return false; } diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index d868227d95..c033b144af 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -171,16 +171,6 @@ namespace MediaBrowser.Controller.Entities.Audio + (IndexNumber != null ? IndexNumber.Value.ToString("0000 - ") : "") + Name; } - /// - /// Determines whether the specified name has artist. - /// - /// The name. - /// true if the specified name has artist; otherwise, false. - public bool HasArtist(string name) - { - return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase); - } - /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs b/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs index a20f053232..56921409ae 100644 --- a/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/IHasAlbumArtist.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Entities.Audio { @@ -9,10 +11,20 @@ namespace MediaBrowser.Controller.Entities.Audio public interface IHasArtist { - bool HasArtist(string name); - List AllArtists { get; } - List Artists { get; } + List Artists { get; set; } + } + + public static class HasArtistExtensions + { + public static bool HasArtist(this IHasArtist hasArtist, string artist) + { + return hasArtist.Artists.Contains(artist, StringComparer.OrdinalIgnoreCase); + } + public static bool HasAnyArtist(this IHasArtist hasArtist, string artist) + { + return hasArtist.AllArtists.Contains(artist, StringComparer.OrdinalIgnoreCase); + } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index e3f523b5a7..dc3f13b01d 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -120,16 +120,6 @@ namespace MediaBrowser.Controller.Entities.Audio get { return Parent as MusicArtist ?? UnknwonArtist; } } - /// - /// Determines whether the specified artist has artist. - /// - /// The artist. - /// true if the specified artist has artist; otherwise, false. - public bool HasArtist(string artist) - { - return AllArtists.Contains(artist, StringComparer.OrdinalIgnoreCase); - } - public List Artists { get; set; } /// diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index fed9689b36..4185590ab3 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -213,7 +213,7 @@ namespace MediaBrowser.Controller.Entities.Audio return i => { var hasArtist = i as IHasArtist; - return hasArtist != null && hasArtist.HasArtist(Name); + return hasArtist != null && hasArtist.HasAnyArtist(Name); }; } } diff --git a/MediaBrowser.Controller/Entities/MusicVideo.cs b/MediaBrowser.Controller/Entities/MusicVideo.cs index 771c62fd6d..b2cad02de8 100644 --- a/MediaBrowser.Controller/Entities/MusicVideo.cs +++ b/MediaBrowser.Controller/Entities/MusicVideo.cs @@ -47,16 +47,6 @@ namespace MediaBrowser.Controller.Entities } } - /// - /// Determines whether the specified name has artist. - /// - /// The name. - /// true if the specified name has artist; otherwise, false. - public bool HasArtist(string name) - { - return AllArtists.Contains(name, StringComparer.OrdinalIgnoreCase); - } - /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/Playlists/Playlist.cs b/MediaBrowser.Controller/Playlists/Playlist.cs index 3479902cbd..fdc36db354 100644 --- a/MediaBrowser.Controller/Playlists/Playlist.cs +++ b/MediaBrowser.Controller/Playlists/Playlist.cs @@ -106,7 +106,7 @@ namespace MediaBrowser.Controller.Playlists Func filter = i => { var audio = i as Audio; - return audio != null && audio.HasArtist(musicArtist.Name); + return audio != null && audio.HasAnyArtist(musicArtist.Name); }; var items = user == null diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index b72a895ca2..74f927c7e2 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -980,9 +980,6 @@ Querying\SessionQuery.cs - - Querying\SimilarItemsByNameQuery.cs - Querying\SimilarItemsQuery.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 7a28f6de83..7f6f7bc132 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -942,9 +942,6 @@ Querying\SessionQuery.cs - - Querying\SimilarItemsByNameQuery.cs - Querying\SimilarItemsQuery.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 190f2100eb..0b55d0b45c 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -344,14 +344,14 @@ namespace MediaBrowser.Model.ApiClient /// /// The query. /// Task{ItemsResult}. - Task GetInstantMixFromArtistAsync(SimilarItemsByNameQuery query); + Task GetInstantMixFromArtistAsync(SimilarItemsQuery query); /// /// Gets the instant mix from music genre async. /// /// The query. /// Task{ItemsResult}. - Task GetInstantMixFromMusicGenreAsync(SimilarItemsByNameQuery query); + Task GetInstantMixFromMusicGenreAsync(SimilarItemsQuery query); /// /// Gets the similar movies async. diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 66066e392d..7a1c78112f 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -466,6 +466,12 @@ namespace MediaBrowser.Model.Dto /// The artists. public List Artists { get; set; } + /// + /// Gets or sets the artist items. + /// + /// The artist items. + public List ArtistItems { get; set; } + /// /// Gets or sets the album. /// diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index fd50e598a9..601ba6dc17 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -322,7 +322,6 @@ - diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index a40eca5b5a..1fde6d62da 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -39,11 +39,11 @@ namespace MediaBrowser.Model.Querying public string[] SortBy { get; set; } /// - /// Filter by artists + /// Gets or sets the artist ids. /// - /// The artists. - public string[] Artists { get; set; } - + /// The artist ids. + public string[] ArtistIds { get; set; } + /// /// The sort order to return results with /// @@ -306,7 +306,7 @@ namespace MediaBrowser.Model.Querying Years = new int[] { }; PersonTypes = new string[] { }; Ids = new string[] { }; - Artists = new string[] { }; + ArtistIds = new string[] { }; ImageTypes = new ImageType[] { }; AirDays = new DayOfWeek[] { }; diff --git a/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs b/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs deleted file mode 100644 index 7d0d4da317..0000000000 --- a/MediaBrowser.Model/Querying/SimilarItemsByNameQuery.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace MediaBrowser.Model.Querying -{ - public class SimilarItemsByNameQuery - { - /// - /// The user to localize search results for - /// - /// The user id. - public string UserId { get; set; } - - /// - /// Gets or sets the name. - /// - /// The name. - public string Name { get; set; } - - /// - /// The maximum number of items to return - /// - /// The limit. - public int? Limit { get; set; } - - /// - /// Fields to return within the items, in addition to basic information - /// - /// The fields. - public ItemFields[] Fields { get; set; } - } -} \ No newline at end of file diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs index 26d00d5444..ea191dd08f 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs @@ -387,7 +387,7 @@ namespace MediaBrowser.Providers.MediaInfo if (!string.IsNullOrEmpty(val)) { // Sometimes the artist name is listed here, account for that - var studios = Split(val, true).Where(i => !audio.HasArtist(i)); + var studios = Split(val, true).Where(i => !audio.HasAnyArtist(i)); foreach (var studio in studios) { diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 8086033ebb..3280cf264b 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -504,7 +504,6 @@ namespace MediaBrowser.Server.Implementations.Dto } dto.Album = item.Album; - dto.Artists = item.Artists; } private void SetGameProperties(BaseItemDto dto, Game item) @@ -1142,7 +1141,6 @@ namespace MediaBrowser.Server.Implementations.Dto if (audio != null) { dto.Album = audio.Album; - dto.Artists = audio.Artists; var albumParent = audio.FindParent(); @@ -1163,15 +1161,40 @@ namespace MediaBrowser.Server.Implementations.Dto if (album != null) { - dto.Artists = album.Artists; - dto.SoundtrackIds = album.SoundtrackIds .Select(i => i.ToString("N")) .ToArray(); } - var hasAlbumArtist = item as IHasAlbumArtist; + var hasArtist = item as IHasArtist; + if (hasArtist != null) + { + dto.Artists = hasArtist.Artists; + + dto.ArtistItems = hasArtist + .Artists + .Select(i => + { + try + { + var artist = _libraryManager.GetArtist(i); + return new NameIdPair + { + Name = artist.Name, + Id = artist.Id.ToString("N") + }; + } + catch (Exception ex) + { + _logger.ErrorException("Error getting artist", ex); + return null; + } + }) + .Where(i => i != null) + .ToList(); + } + var hasAlbumArtist = item as IHasAlbumArtist; if (hasAlbumArtist != null) { dto.AlbumArtist = hasAlbumArtist.AlbumArtists.FirstOrDefault(); @@ -1253,7 +1276,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add MovieInfo var movie = item as Movie; - if (movie != null) { if (fields.Contains(ItemFields.TmdbCollectionName)) @@ -1263,7 +1285,6 @@ namespace MediaBrowser.Server.Implementations.Dto } var hasSpecialFeatures = item as IHasSpecialFeatures; - if (hasSpecialFeatures != null) { var specialFeatureCount = hasSpecialFeatures.SpecialFeatureIds.Count; @@ -1276,7 +1297,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add EpisodeInfo var episode = item as Episode; - if (episode != null) { dto.IndexNumberEnd = episode.IndexNumberEnd; @@ -1318,7 +1338,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add SeriesInfo var series = item as Series; - if (series != null) { dto.AirDays = series.AirDays; @@ -1368,7 +1387,6 @@ namespace MediaBrowser.Server.Implementations.Dto // Add SeasonInfo var season = item as Season; - if (season != null) { series = season.Series; @@ -1402,7 +1420,6 @@ namespace MediaBrowser.Server.Implementations.Dto } var musicVideo = item as MusicVideo; - if (musicVideo != null) { SetMusicVideoProperties(dto, musicVideo); diff --git a/MediaBrowser.Server.Implementations/Library/MusicManager.cs b/MediaBrowser.Server.Implementations/Library/MusicManager.cs index 7733e7d379..3a854f2fe0 100644 --- a/MediaBrowser.Server.Implementations/Library/MusicManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MusicManager.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Server.Implementations.Library var genres = user.RootFolder .GetRecursiveChildren(user, i => i is Audio) .Cast