diff --git a/MediaBrowser.Api/Devices/DeviceService.cs b/MediaBrowser.Api/Devices/DeviceService.cs index 0d86d6a5c0..ab0a4a4b2a 100644 --- a/MediaBrowser.Api/Devices/DeviceService.cs +++ b/MediaBrowser.Api/Devices/DeviceService.cs @@ -1,22 +1,19 @@ using MediaBrowser.Controller.Devices; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Devices; +using MediaBrowser.Model.Querying; using MediaBrowser.Model.Session; using ServiceStack; using ServiceStack.Web; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Threading.Tasks; namespace MediaBrowser.Api.Devices { [Route("/Devices", "GET", Summary = "Gets all devices")] [Authenticated(Roles = "Admin")] - public class GetDevices : IReturn> + public class GetDevices : DeviceQuery, IReturn> { - [ApiMember(Name = "SupportsContentUploading", Description = "SupportsContentUploading", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public bool? SupportsContentUploading { get; set; } } [Route("/Devices", "DELETE", Summary = "Deletes a device")] @@ -109,16 +106,7 @@ namespace MediaBrowser.Api.Devices public object Get(GetDevices request) { - var devices = _deviceManager.GetDevices(); - - if (request.SupportsContentUploading.HasValue) - { - var val = request.SupportsContentUploading.Value; - - devices = devices.Where(i => _deviceManager.GetCapabilities(i.Id).SupportsContentUploading == val); - } - - return ToOptimizedResult(devices.ToList()); + return ToOptimizedResult(_deviceManager.GetDevices(request)); } public object Get(GetCameraUploads request) diff --git a/MediaBrowser.Api/IHasDtoOptions.cs b/MediaBrowser.Api/IHasDtoOptions.cs new file mode 100644 index 0000000000..f7fb57f014 --- /dev/null +++ b/MediaBrowser.Api/IHasDtoOptions.cs @@ -0,0 +1,49 @@ +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using System; +using System.Linq; + +namespace MediaBrowser.Api +{ + public interface IHasDtoOptions : IHasItemFields + { + bool? EnableImages { get; set; } + + int? ImageTypeLimit { get; set; } + + string EnableImageTypes { get; set; } + } + + public static class HasDtoOptionsExtensions + { + public static DtoOptions GetDtoOptions(this IHasDtoOptions request) + { + var options = new DtoOptions(); + + options.Fields = request.GetItemFields().ToList(); + options.EnableImages = request.EnableImages ?? true; + + if (request.ImageTypeLimit.HasValue) + { + options.ImageTypeLimit = request.ImageTypeLimit.Value; + } + + if (string.IsNullOrWhiteSpace(request.EnableImageTypes)) + { + if (options.EnableImages) + { + // Get everything + options.ImageTypes = Enum.GetNames(typeof(ImageType)) + .Select(i => (ImageType)Enum.Parse(typeof(ImageType), i, true)) + .ToList(); + } + } + else + { + options.ImageTypes = (request.EnableImageTypes ?? string.Empty).Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true)).ToList(); + } + + return options; + } + } +} diff --git a/MediaBrowser.Api/Images/ImageService.cs b/MediaBrowser.Api/Images/ImageService.cs index 9d7362f63a..0e4ccf0b17 100644 --- a/MediaBrowser.Api/Images/ImageService.cs +++ b/MediaBrowser.Api/Images/ImageService.cs @@ -567,7 +567,7 @@ namespace MediaBrowser.Api.Images private async Task GetImageResult(IHasImages item, ImageRequest request, ItemImageInfo image, - ImageOutputFormat format, + ImageFormat format, List enhancers, string contentType, TimeSpan? cacheDuration, @@ -612,11 +612,11 @@ namespace MediaBrowser.Api.Images }); } - private ImageOutputFormat GetOutputFormat(ImageRequest request, ItemImageInfo image, List enhancers) + private ImageFormat GetOutputFormat(ImageRequest request, ItemImageInfo image, List enhancers) { if (!string.IsNullOrWhiteSpace(request.Format)) { - ImageOutputFormat format; + ImageFormat format; if (Enum.TryParse(request.Format, true, out format)) { return format; @@ -627,28 +627,28 @@ namespace MediaBrowser.Api.Images var clientFormats = GetClientSupportedFormats(); - if (serverFormats.Contains(ImageOutputFormat.Webp) && - clientFormats.Contains(ImageOutputFormat.Webp)) + if (serverFormats.Contains(ImageFormat.Webp) && + clientFormats.Contains(ImageFormat.Webp)) { - return ImageOutputFormat.Webp; + return ImageFormat.Webp; } if (enhancers.Count > 0) { - return ImageOutputFormat.Png; + return ImageFormat.Png; } if (string.Equals(Path.GetExtension(image.Path), ".jpg", StringComparison.OrdinalIgnoreCase) || string.Equals(Path.GetExtension(image.Path), ".jpeg", StringComparison.OrdinalIgnoreCase)) { - return ImageOutputFormat.Jpg; + return ImageFormat.Jpg; } // We can't predict if there will be transparency or not, so play it safe - return ImageOutputFormat.Png; + return ImageFormat.Png; } - private ImageOutputFormat[] GetClientSupportedFormats() + private ImageFormat[] GetClientSupportedFormats() { if ((Request.AcceptTypes ?? new string[] { }).Contains("image/webp", StringComparer.OrdinalIgnoreCase)) { @@ -657,32 +657,32 @@ namespace MediaBrowser.Api.Images // Not displaying properly on iOS if (userAgent.IndexOf("cfnetwork", StringComparison.OrdinalIgnoreCase) == -1) { - return new[] { ImageOutputFormat.Webp, ImageOutputFormat.Jpg, ImageOutputFormat.Png }; + return new[] { ImageFormat.Webp, ImageFormat.Jpg, ImageFormat.Png }; } } - return new[] { ImageOutputFormat.Jpg, ImageOutputFormat.Png }; + return new[] { ImageFormat.Jpg, ImageFormat.Png }; } - private string GetMimeType(ImageOutputFormat format, string path) + private string GetMimeType(ImageFormat format, string path) { - if (format == ImageOutputFormat.Bmp) + if (format == ImageFormat.Bmp) { return Common.Net.MimeTypes.GetMimeType("i.bmp"); } - if (format == ImageOutputFormat.Gif) + if (format == ImageFormat.Gif) { return Common.Net.MimeTypes.GetMimeType("i.gif"); } - if (format == ImageOutputFormat.Jpg) + if (format == ImageFormat.Jpg) { return Common.Net.MimeTypes.GetMimeType("i.jpg"); } - if (format == ImageOutputFormat.Png) + if (format == ImageFormat.Png) { return Common.Net.MimeTypes.GetMimeType("i.png"); } - if (format == ImageOutputFormat.Webp) + if (format == ImageFormat.Webp) { return Common.Net.MimeTypes.GetMimeType("i.webp"); } diff --git a/MediaBrowser.Api/ItemLookupService.cs b/MediaBrowser.Api/ItemLookupService.cs index b19d6c6549..507d569708 100644 --- a/MediaBrowser.Api/ItemLookupService.cs +++ b/MediaBrowser.Api/ItemLookupService.cs @@ -37,12 +37,6 @@ namespace MediaBrowser.Api { } - [Route("/Items/RemoteSearch/Trailer", "POST")] - [Authenticated] - public class GetTrailerRemoteSearchResults : RemoteSearchQuery, IReturn> - { - } - [Route("/Items/RemoteSearch/AdultVideo", "POST")] [Authenticated] public class GetAdultVideoRemoteSearchResults : RemoteSearchQuery, IReturn> @@ -162,13 +156,6 @@ namespace MediaBrowser.Api return ToOptimizedResult(result); } - public object Post(GetTrailerRemoteSearchResults request) - { - var result = _providerManager.GetRemoteSearchResults(request, CancellationToken.None).Result; - - return ToOptimizedResult(result); - } - public object Post(GetMusicAlbumRemoteSearchResults request) { var result = _providerManager.GetRemoteSearchResults(request, CancellationToken.None).Result; diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index 06d8e0478e..5cb007f8fe 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -276,7 +276,7 @@ namespace MediaBrowser.Api.Library var fields = Enum.GetNames(typeof(ItemFields)) .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) .ToList(); - + var result = new ItemsResult { TotalRecordCount = items.Count, @@ -353,7 +353,7 @@ namespace MediaBrowser.Api.Library .ToList(); BaseItem parent = item.Parent; - + while (parent != null) { if (user != null) @@ -607,7 +607,7 @@ namespace MediaBrowser.Api.Library } } } - + var dtos = themeSongIds.Select(_libraryManager.GetItemById) .OrderBy(i => i.SortName) .Select(i => _dtoService.GetBaseItemDto(i, fields, user, item)); diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index dae3790990..286b807b66 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -77,6 +77,7 @@ + diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index ef86a46e8a..fc03ab466e 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -200,6 +200,19 @@ namespace MediaBrowser.Api.Movies .ToList(); } + if (item is Video) + { + var imdbId = item.GetProviderId(MetadataProviders.Imdb); + + // Use imdb id to try to filter duplicates of the same item + if (!string.IsNullOrWhiteSpace(imdbId)) + { + list = list + .Where(i => !string.Equals(imdbId, i.GetProviderId(MetadataProviders.Imdb), StringComparison.OrdinalIgnoreCase)) + .ToList(); + } + } + var items = SimilarItemsHelper.GetSimilaritems(item, list, getSimilarityScore).ToList(); IEnumerable returnItems = items; @@ -208,7 +221,7 @@ namespace MediaBrowser.Api.Movies { returnItems = returnItems.Take(request.Limit.Value); } - + var result = new ItemsResult { Items = returnItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(), diff --git a/MediaBrowser.Api/Movies/TrailersService.cs b/MediaBrowser.Api/Movies/TrailersService.cs index a6024d4610..8e1704af73 100644 --- a/MediaBrowser.Api/Movies/TrailersService.cs +++ b/MediaBrowser.Api/Movies/TrailersService.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Api.Movies Logger, // Strip out secondary versions - request, item => (item is Movie || item is Trailer) && !((Video)item).PrimaryVersionId.HasValue, + request, item => (item is Movie) && !((Video)item).PrimaryVersionId.HasValue, SimilarItemsHelper.GetSimiliarityScore); diff --git a/MediaBrowser.Api/Music/InstantMixService.cs b/MediaBrowser.Api/Music/InstantMixService.cs index f342422426..43fd0894b9 100644 --- a/MediaBrowser.Api/Music/InstantMixService.cs +++ b/MediaBrowser.Api/Music/InstantMixService.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Net; +using MediaBrowser.Controller.Playlists; using MediaBrowser.Model.Querying; using ServiceStack; using System.Collections.Generic; @@ -20,6 +21,11 @@ namespace MediaBrowser.Api.Music { } + [Route("/Playlists/{Id}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given playlist")] + public class GetInstantMixFromPlaylist : BaseGetSimilarItemsFromItem + { + } + [Route("/Artists/{Name}/InstantMix", "GET", Summary = "Creates an instant playlist based on a given artist")] public class GetInstantMixFromArtist : BaseGetSimilarItems { @@ -109,6 +115,17 @@ namespace MediaBrowser.Api.Music return GetResult(items, user, request); } + public object Get(GetInstantMixFromPlaylist request) + { + var playlist = (Playlist)_libraryManager.GetItemById(request.Id); + + var user = _userManager.GetUserById(request.UserId.Value); + + var items = _musicManager.GetInstantMixFromPlaylist(playlist, user); + + return GetResult(items, user, request); + } + public object Get(GetInstantMixFromMusicGenre request) { var user = _userManager.GetUserById(request.UserId.Value); diff --git a/MediaBrowser.Api/PackageReviewService.cs b/MediaBrowser.Api/PackageReviewService.cs index 112a2c5cea..ce366ccd4c 100644 --- a/MediaBrowser.Api/PackageReviewService.cs +++ b/MediaBrowser.Api/PackageReviewService.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.Constants; -using MediaBrowser.Common.Net; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Serialization; @@ -103,6 +102,7 @@ namespace MediaBrowser.Api private readonly IHttpClient _httpClient; private readonly INetworkManager _netManager; private readonly IJsonSerializer _serializer; + private const string MbAdminUrl = "https://www.mb3admin.com/admin/"; public PackageReviewService(IHttpClient client, INetworkManager net, IJsonSerializer serializer) { @@ -132,7 +132,7 @@ namespace MediaBrowser.Api parms += "&title=true"; } - var result = _httpClient.Get(Constants.MbAdminUrl + "/service/packageReview/retrieve" + parms, CancellationToken.None).Result; + var result = _httpClient.Get(MbAdminUrl + "/service/packageReview/retrieve" + parms, CancellationToken.None).Result; var reviews = _serializer.DeserializeFromStream>(result); @@ -153,7 +153,7 @@ namespace MediaBrowser.Api { "review", reviewText }, }; - Task.WaitAll(_httpClient.Post(Constants.MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None)); + Task.WaitAll(_httpClient.Post(MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None)); } } } diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index cf87b42e8e..136969b170 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -173,9 +173,10 @@ namespace MediaBrowser.Api public object Get(GetPackage request) { var packages = _installationManager.GetAvailablePackages(CancellationToken.None, applicationVersion: _appHost.ApplicationVersion).Result; + var list = packages.ToList(); - var result = packages.FirstOrDefault(p => string.Equals(p.guid, request.AssemblyGuid ?? "none", StringComparison.OrdinalIgnoreCase)) - ?? packages.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); + var result = list.FirstOrDefault(p => string.Equals(p.guid, request.AssemblyGuid ?? "none", StringComparison.OrdinalIgnoreCase)) + ?? list.FirstOrDefault(p => p.name.Equals(request.Name, StringComparison.OrdinalIgnoreCase)); return ToOptimizedResult(result); } @@ -243,4 +244,4 @@ namespace MediaBrowser.Api } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 21c4a3dffe..12ccfb6b1d 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -2011,11 +2011,6 @@ namespace MediaBrowser.Api.Playback state.EstimateContentLength = transcodingProfile.EstimateContentLength; state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode; state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; - - if (state.VideoRequest != null && string.IsNullOrWhiteSpace(state.VideoRequest.Profile)) - { - state.VideoRequest.Profile = transcodingProfile.VideoProfile; - } } } diff --git a/MediaBrowser.Api/PlaylistService.cs b/MediaBrowser.Api/PlaylistService.cs index 5325e9c448..7f7717f71b 100644 --- a/MediaBrowser.Api/PlaylistService.cs +++ b/MediaBrowser.Api/PlaylistService.cs @@ -151,7 +151,7 @@ namespace MediaBrowser.Api { items = items.Take(request.Limit.Value).ToArray(); } - + var dtos = items .Select(i => _dtoService.GetBaseItemDto(i.Item2, request.GetItemFields().ToList(), user)) .ToArray(); diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs index 7721107942..df50255abb 100644 --- a/MediaBrowser.Api/Session/SessionsService.cs +++ b/MediaBrowser.Api/Session/SessionsService.cs @@ -238,6 +238,12 @@ namespace MediaBrowser.Api.Session [ApiMember(Name = "SupportsContentUploading", Description = "Determines whether camera upload is supported.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] public bool SupportsContentUploading { get; set; } + + [ApiMember(Name = "SupportsSync", Description = "Determines whether sync is supported.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] + public bool SupportsSync { get; set; } + + [ApiMember(Name = "SupportsUniqueIdentifier", Description = "Determines whether the device supports a unique identifier.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")] + public bool SupportsUniqueIdentifier { get; set; } } [Route("/Sessions/Logout", "POST", Summary = "Reports that a session has ended")] @@ -516,7 +522,11 @@ namespace MediaBrowser.Api.Session MessageCallbackUrl = request.MessageCallbackUrl, - SupportsContentUploading = request.SupportsContentUploading + SupportsContentUploading = request.SupportsContentUploading, + + SupportsSync = request.SupportsSync, + + SupportsUniqueIdentifier = request.SupportsUniqueIdentifier }); } } diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index fd50191264..4443b2a2bc 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -61,6 +61,7 @@ namespace MediaBrowser.Api public void Post(ReportStartupWizardComplete request) { _config.Configuration.IsStartupWizardCompleted = true; + _config.Configuration.EnableLocalizedGuids = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 2f9bbca476..d1464cd262 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -19,7 +19,7 @@ namespace MediaBrowser.Api /// Class GetNextUpEpisodes /// [Route("/Shows/NextUp", "GET", Summary = "Gets a list of next up episodes")] - public class GetNextUpEpisodes : IReturn, IHasItemFields + public class GetNextUpEpisodes : IReturn, IHasDtoOptions { /// /// Gets or sets the user id. @@ -58,10 +58,19 @@ namespace MediaBrowser.Api /// The parent id. [ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ParentId { get; set; } + + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } } [Route("/Shows/Upcoming", "GET", Summary = "Gets a list of upcoming episodes")] - public class GetUpcomingEpisodes : IReturn, IHasItemFields + public class GetUpcomingEpisodes : IReturn, IHasDtoOptions { /// /// Gets or sets the user id. @@ -97,6 +106,15 @@ namespace MediaBrowser.Api /// The parent id. [ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ParentId { get; set; } + + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } } [Route("/Shows/{Id}/Similar", "GET", Summary = "Finds tv shows similar to a given one.")] @@ -252,9 +270,9 @@ namespace MediaBrowser.Api var pagedItems = ApplyPaging(previousEpisodes, request.StartIndex, request.Limit); - var fields = request.GetItemFields().ToList(); + var options = request.GetDtoOptions(); - var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); + var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, options, user)).ToArray(); var result = new ItemsResult { @@ -283,9 +301,9 @@ namespace MediaBrowser.Api var user = _userManager.GetUserById(request.UserId); - var fields = request.GetItemFields().ToList(); + var options = request.GetDtoOptions(); - var returnItems = result.Items.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); + var returnItems = result.Items.Select(i => _dtoService.GetBaseItemDto(i, options, user)).ToArray(); return ToOptimizedSerializedResultUsingCache(new ItemsResult { diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs index 07015ecae2..2299b2b1aa 100644 --- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs +++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Api.UserLibrary if (request.UserId.HasValue) { var user = UserManager.GetUserById(request.UserId.Value); - + return DtoService.GetBaseItemDto(item, fields.ToList(), user); } diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 3ae53daf88..9d211a4199 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -127,11 +127,11 @@ namespace MediaBrowser.Api.UserLibrary } - var fields = request.GetItemFields().ToList(); - var tuples = ibnItems.Select(i => new Tuple>(i, i.GetTaggedItems(libraryItems).ToList())); - var dtos = tuples.Select(i => GetDto(i.Item1, user, fields, i.Item2)); + var dtoOptions = request.GetDtoOptions(); + + var dtos = tuples.Select(i => GetDto(i.Item1, user, dtoOptions, i.Item2)); result.Items = dtos.Where(i => i != null).ToArray(); @@ -332,12 +332,12 @@ namespace MediaBrowser.Api.UserLibrary /// /// The item. /// The user. - /// The fields. + /// The options. /// The library items. /// Task{DtoBaseItem}. - private BaseItemDto GetDto(TItemType item, User user, List fields, List libraryItems) + private BaseItemDto GetDto(TItemType item, User user, DtoOptions options, List libraryItems) { - var dto = DtoService.GetItemByNameDto(item, fields, libraryItems, user); + var dto = DtoService.GetItemByNameDto(item, options, libraryItems, user); return dto; } diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index 6b0c64b797..fffc11d68f 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -7,8 +7,13 @@ using System.Linq; namespace MediaBrowser.Api.UserLibrary { - public abstract class BaseItemsRequest : IHasItemFields + public abstract class BaseItemsRequest : IHasDtoOptions { + protected BaseItemsRequest() + { + EnableImages = true; + } + /// /// Skips over a given number of items within the results. Use for paging. /// @@ -116,6 +121,15 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "Years", Description = "Optional. If specified, results will be filtered based on production year. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string Years { get; set; } + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } + public string[] GetGenres() { return (Genres ?? string.Empty).Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index b87ee895af..cf9b0b4387 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -321,15 +321,14 @@ namespace MediaBrowser.Api.UserLibrary var result = await GetItemsToSerialize(request, user, parentItem).ConfigureAwait(false); var isFiltered = result.Item2; + var dtoOptions = request.GetDtoOptions(); if (isFiltered) { - var currentFields = request.GetItemFields().ToList(); - return new ItemsResult { TotalRecordCount = result.Item1.TotalRecordCount, - Items = result.Item1.Items.Select(i => _dtoService.GetBaseItemDto(i, currentFields, user)).ToArray() + Items = result.Item1.Items.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray() }; } @@ -363,9 +362,7 @@ namespace MediaBrowser.Api.UserLibrary var pagedItems = ApplyPaging(request, itemsArray); - var fields = request.GetItemFields().ToList(); - - var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, fields, user)).ToArray(); + var returnItems = pagedItems.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user)).ToArray(); return new ItemsResult { @@ -880,7 +877,7 @@ namespace MediaBrowser.Api.UserLibrary var hasTrailers = i as IHasTrailers; if (hasTrailers != null) { - trailerCount = hasTrailers.LocalTrailerIds.Count; + trailerCount = hasTrailers.GetTrailerIds().Count; } var ok = val ? trailerCount > 0 : trailerCount == 0; diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index fd0e79a217..040cad436e 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -221,7 +221,7 @@ namespace MediaBrowser.Api.UserLibrary } [Route("/Users/{UserId}/Items/Latest", "GET", Summary = "Gets latest media")] - public class GetLatestMedia : IReturn>, IHasItemFields + public class GetLatestMedia : IReturn>, IHasDtoOptions { /// /// Gets or sets the user id. @@ -251,6 +251,15 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "GroupItems", Description = "Whether or not to group items into a parent container.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool GroupItems { get; set; } + [ApiMember(Name = "EnableImages", Description = "Optional, include image information in output", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "GET")] + public bool? EnableImages { get; set; } + + [ApiMember(Name = "ImageTypeLimit", Description = "Optional, the max number of images to return, per image type", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] + public int? ImageTypeLimit { get; set; } + + [ApiMember(Name = "EnableImageTypes", Description = "Optional. The image types to include in the output.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string EnableImageTypes { get; set; } + public GetLatestMedia() { Limit = 20; @@ -362,7 +371,7 @@ namespace MediaBrowser.Api.UserLibrary } } - var fields = request.GetItemFields().ToList(); + var options = request.GetDtoOptions(); var dtos = list.Select(i => { @@ -375,7 +384,7 @@ namespace MediaBrowser.Api.UserLibrary childCount = i.Item2.Count; } - var dto = _dtoService.GetBaseItemDto(item, fields, user); + var dto = _dtoService.GetBaseItemDto(item, options, user); dto.ChildCount = childCount; @@ -506,7 +515,7 @@ namespace MediaBrowser.Api.UserLibrary var hasTrailers = item as IHasTrailers; if (hasTrailers != null) { - trailerIds = hasTrailers.LocalTrailerIds; + trailerIds = hasTrailers.GetTrailerIds(); } var dtos = trailerIds diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 900009a238..89d00b87dc 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Configuration; +using System.Net.Sockets; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; @@ -134,9 +135,22 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager request.Referer = options.Referer; } + //request.ServicePoint.BindIPEndPointDelegate = BindIPEndPointCallback; + return request; } + private static IPEndPoint BindIPEndPointCallback(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount) + { + // Prefer local ipv4 + if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6) + { + return new IPEndPoint(IPAddress.IPv6Any, 0); + } + + return new IPEndPoint(IPAddress.Any, 0); + } + private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options) { foreach (var header in options.RequestHeaders.ToList()) diff --git a/MediaBrowser.Common.Implementations/Logging/LogHelper.cs b/MediaBrowser.Common.Implementations/Logging/LogHelper.cs index 91e937ca7c..8080c2111c 100644 --- a/MediaBrowser.Common.Implementations/Logging/LogHelper.cs +++ b/MediaBrowser.Common.Implementations/Logging/LogHelper.cs @@ -15,6 +15,11 @@ namespace MediaBrowser.Common.Implementations.Logging /// StringBuilder. public static StringBuilder GetLogMessage(Exception exception) { + if (exception == null) + { + throw new ArgumentNullException("exception"); + } + var messageText = new StringBuilder(); messageText.AppendLine(exception.Message); diff --git a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs index 2a1c5dfe68..bf6ebf7ef7 100644 --- a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs +++ b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs @@ -24,14 +24,28 @@ namespace MediaBrowser.Common.Implementations.Networking /// IPAddress. public IEnumerable GetLocalIpAddresses() { - var list = GetIPsDefault().Where(i => !IPAddress.IsLoopback(i)).Select(i => i.ToString()).ToList(); + var list = GetIPsDefault() + .Where(i => !IPAddress.IsLoopback(i)) + .Select(i => i.ToString()) + .Where(FilterIpAddress) + .ToList(); if (list.Count > 0) { return list; } - return GetLocalIpAddressesFallback(); + return GetLocalIpAddressesFallback().Where(FilterIpAddress); + } + + private bool FilterIpAddress(string address) + { + if (address.StartsWith("169.", StringComparison.OrdinalIgnoreCase)) + { + return false; + } + + return true; } private bool IsInPrivateAddressSpace(string endpoint) diff --git a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs index 2c387a4ddf..dfdf61016e 100644 --- a/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs +++ b/MediaBrowser.Common.Implementations/Security/PluginSecurityManager.cs @@ -17,7 +17,9 @@ namespace MediaBrowser.Common.Implementations.Security /// public class PluginSecurityManager : ISecurityManager { - private const string MBValidateUrl = Constants.Constants.MbAdminUrl + "service/registration/validate"; + private const string MbAdminUrl = "https://www.mb3admin.com/admin/"; + + private const string MBValidateUrl = MbAdminUrl + "service/registration/validate"; /// /// The _is MB supporter @@ -160,7 +162,7 @@ namespace MediaBrowser.Common.Implementations.Security return new SupporterInfo(); } - var url = Constants.Constants.MbAdminUrl + "/service/supporter/retrieve?key=" + key; + var url = MbAdminUrl + "/service/supporter/retrieve?key=" + key; using (var stream = await _httpClient.Get(url, CancellationToken.None).ConfigureAwait(false)) { diff --git a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs index b022dc6719..0a8ce012f2 100644 --- a/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs +++ b/MediaBrowser.Common.Implementations/Updates/InstallationManager.cs @@ -161,7 +161,7 @@ namespace MediaBrowser.Common.Implementations.Updates { "systemid", _applicationHost.SystemId } }; - using (var json = await _httpClient.Post(Constants.Constants.MbAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false)) + using (var json = await _httpClient.Post(MbAdminUrl + "service/package/retrieveall", data, cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); @@ -172,6 +172,7 @@ namespace MediaBrowser.Common.Implementations.Updates } private Tuple, DateTime> _lastPackageListResult; + private const string MbAdminUrl = "https://www.mb3admin.com/admin/"; /// /// Gets all available packages. @@ -203,7 +204,7 @@ namespace MediaBrowser.Common.Implementations.Updates } } - using (var json = await _httpClient.Get(Constants.Constants.MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) + using (var json = await _httpClient.Get(MbAdminUrl + "service/MB3Packages.json", cancellationToken).ConfigureAwait(false)) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/MediaBrowser.Common/Constants/Constants.cs b/MediaBrowser.Common/Constants/Constants.cs deleted file mode 100644 index d569fd8eae..0000000000 --- a/MediaBrowser.Common/Constants/Constants.cs +++ /dev/null @@ -1,8 +0,0 @@ - -namespace MediaBrowser.Common.Constants -{ - public static class Constants - { - public const string MbAdminUrl = "http://www.mb3admin.com/admin/"; - } -} diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index be2fbffc64..8e96373f44 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; @@ -55,28 +54,6 @@ namespace MediaBrowser.Common.Extensions return sb.ToString(); } - /// - /// Removes the accent. - /// - /// The text. - /// System.String. - public static string RemoveAccent(this string text) - { - var normalizedString = text.Normalize(NormalizationForm.FormD); - var stringBuilder = new StringBuilder(); - - foreach (var c in normalizedString) - { - var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c); - if (unicodeCategory != UnicodeCategory.NonSpacingMark) - { - stringBuilder.Append(c); - } - } - - return stringBuilder.ToString().Normalize(NormalizationForm.FormC); - } - /// /// Gets the M d5. /// @@ -96,6 +73,8 @@ namespace MediaBrowser.Common.Extensions /// The STR. /// The type. /// Guid. + /// type + [Obsolete("Use LibraryManager.GetNewItemId")] public static Guid GetMBId(this string str, Type type) { if (type == null) @@ -107,35 +86,5 @@ namespace MediaBrowser.Common.Extensions return key.GetMD5(); } - - /// - /// Gets the attribute value. - /// - /// The STR. - /// The attrib. - /// System.String. - /// attrib - public static string GetAttributeValue(this string str, string attrib) - { - if (string.IsNullOrEmpty(str)) - { - throw new ArgumentNullException("str"); - } - - if (string.IsNullOrEmpty(attrib)) - { - throw new ArgumentNullException("attrib"); - } - - string srch = "[" + attrib + "="; - int start = str.IndexOf(srch, StringComparison.OrdinalIgnoreCase); - if (start > -1) - { - start += srch.Length; - int end = str.IndexOf(']', start); - return str.Substring(start, end - start); - } - return null; - } } } diff --git a/MediaBrowser.Common/IO/FileSystemRepository.cs b/MediaBrowser.Common/IO/FileSystemRepository.cs deleted file mode 100644 index 07328d72d9..0000000000 --- a/MediaBrowser.Common/IO/FileSystemRepository.cs +++ /dev/null @@ -1,122 +0,0 @@ -using MediaBrowser.Common.Extensions; -using System; -using System.IO; - -namespace MediaBrowser.Common.IO -{ - /// - /// This is a wrapper for storing large numbers of files within a directory on a file system. - /// Simply pass a filename into GetResourcePath and it will return a full path location of where the file should be stored. - /// - public class FileSystemRepository - { - /// - /// Gets or sets the path. - /// - /// The path. - protected string Path { get; set; } - - /// - /// Initializes a new instance of the class. - /// - /// The path. - /// - public FileSystemRepository(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException(); - } - - Path = path; - } - - /// - /// Gets the full path of where a resource should be stored within the repository - /// - /// Name of the unique. - /// The file extension. - /// System.String. - /// - /// - public string GetResourcePath(string uniqueName, string fileExtension) - { - if (string.IsNullOrEmpty(uniqueName)) - { - throw new ArgumentNullException("uniqueName"); - } - - if (string.IsNullOrEmpty(fileExtension)) - { - throw new ArgumentNullException("fileExtension"); - } - - var filename = uniqueName.GetMD5() + fileExtension; - - return GetResourcePath(filename); - } - - /// - /// Gets the resource path. - /// - /// The filename. - /// System.String. - /// - public string GetResourcePath(string filename) - { - if (string.IsNullOrEmpty(filename)) - { - throw new ArgumentNullException("filename"); - } - - var prefix = filename.Substring(0, 1); - - var path = System.IO.Path.Combine(Path, prefix); - - return System.IO.Path.Combine(path, filename); - } - - /// - /// Determines if a resource is present in the repository - /// - /// Name of the unique. - /// The file extension. - /// true if the specified unique name contains resource; otherwise, false. - public bool ContainsResource(string uniqueName, string fileExtension) - { - return ContainsFilePath(GetResourcePath(uniqueName, fileExtension)); - } - - /// - /// Determines if a file with a given name is present in the repository - /// - /// The filename. - /// true if the specified filename contains filename; otherwise, false. - /// - public bool ContainsFilename(string filename) - { - if (string.IsNullOrEmpty(filename)) - { - throw new ArgumentNullException(); - } - - return ContainsFilePath(GetResourcePath(filename)); - } - - /// - /// Determines if a file is present in the repository - /// - /// The path. - /// true if [contains file path] [the specified path]; otherwise, false. - /// - public bool ContainsFilePath(string path) - { - if (string.IsNullOrEmpty(path)) - { - throw new ArgumentNullException(); - } - - return File.Exists(path); - } - } -} diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index 6e96feed3a..9fdfccaaf6 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -57,12 +57,10 @@ - - diff --git a/MediaBrowser.Controller/Collections/CollectionCreationOptions.cs b/MediaBrowser.Controller/Collections/CollectionCreationOptions.cs index 74ae420950..4a2d390662 100644 --- a/MediaBrowser.Controller/Collections/CollectionCreationOptions.cs +++ b/MediaBrowser.Controller/Collections/CollectionCreationOptions.cs @@ -15,11 +15,13 @@ namespace MediaBrowser.Controller.Collections public Dictionary ProviderIds { get; set; } public List ItemIdList { get; set; } + public List UserIds { get; set; } public CollectionCreationOptions() { ProviderIds = new Dictionary(StringComparer.OrdinalIgnoreCase); ItemIdList = new List(); + UserIds = new List(); } } } diff --git a/MediaBrowser.Controller/Devices/IDeviceManager.cs b/MediaBrowser.Controller/Devices/IDeviceManager.cs index af184e6e93..efd24336af 100644 --- a/MediaBrowser.Controller/Devices/IDeviceManager.cs +++ b/MediaBrowser.Controller/Devices/IDeviceManager.cs @@ -1,5 +1,6 @@ using MediaBrowser.Model.Devices; using MediaBrowser.Model.Events; +using MediaBrowser.Model.Querying; using MediaBrowser.Model.Session; using System; using System.Collections.Generic; @@ -58,8 +59,9 @@ namespace MediaBrowser.Controller.Devices /// /// Gets the devices. /// + /// The query. /// IEnumerable<DeviceInfo>. - IEnumerable GetDevices(); + QueryResult GetDevices(DeviceQuery query); /// /// Deletes the device. diff --git a/MediaBrowser.Controller/Dlna/DlnaIconResponse.cs b/MediaBrowser.Controller/Dlna/DlnaIconResponse.cs deleted file mode 100644 index 04d8e88b97..0000000000 --- a/MediaBrowser.Controller/Dlna/DlnaIconResponse.cs +++ /dev/null @@ -1,22 +0,0 @@ -using MediaBrowser.Controller.Drawing; -using System; -using System.IO; - -namespace MediaBrowser.Controller.Dlna -{ - public class DlnaIconResponse : IDisposable - { - public Stream Stream { get; set; } - - public ImageFormat Format { get; set; } - - public void Dispose() - { - if (Stream != null) - { - Stream.Dispose(); - Stream = null; - } - } - } -} diff --git a/MediaBrowser.Controller/Dlna/IDlnaManager.cs b/MediaBrowser.Controller/Dlna/IDlnaManager.cs index b7a06b368b..34464f6a2d 100644 --- a/MediaBrowser.Controller/Dlna/IDlnaManager.cs +++ b/MediaBrowser.Controller/Dlna/IDlnaManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Dlna; +using MediaBrowser.Controller.Drawing; +using MediaBrowser.Model.Dlna; using System.Collections.Generic; namespace MediaBrowser.Controller.Dlna @@ -69,6 +70,6 @@ namespace MediaBrowser.Controller.Dlna /// /// The filename. /// DlnaIconResponse. - DlnaIconResponse GetIcon(string filename); + ImageStream GetIcon(string filename); } } diff --git a/MediaBrowser.Controller/Drawing/IImageProcessor.cs b/MediaBrowser.Controller/Drawing/IImageProcessor.cs index 3bd3335276..8ac7d56d29 100644 --- a/MediaBrowser.Controller/Drawing/IImageProcessor.cs +++ b/MediaBrowser.Controller/Drawing/IImageProcessor.cs @@ -94,6 +94,6 @@ namespace MediaBrowser.Controller.Drawing /// Gets the supported image output formats. /// /// ImageOutputFormat[]. - ImageOutputFormat[] GetSupportedImageOutputFormats(); + ImageFormat[] GetSupportedImageOutputFormats(); } } diff --git a/MediaBrowser.Controller/Drawing/ImageFormat.cs b/MediaBrowser.Controller/Drawing/ImageFormat.cs deleted file mode 100644 index f785625567..0000000000 --- a/MediaBrowser.Controller/Drawing/ImageFormat.cs +++ /dev/null @@ -1,11 +0,0 @@ - -namespace MediaBrowser.Controller.Drawing -{ - public enum ImageFormat - { - Jpg, - Png, - Gif, - Bmp - } -} diff --git a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs index b99186f37f..d8f5d52c3b 100644 --- a/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs +++ b/MediaBrowser.Controller/Drawing/ImageProcessingOptions.cs @@ -29,7 +29,7 @@ namespace MediaBrowser.Controller.Drawing public List Enhancers { get; set; } - public ImageOutputFormat OutputFormat { get; set; } + public ImageFormat OutputFormat { get; set; } public bool AddPlayedIndicator { get; set; } diff --git a/MediaBrowser.Controller/Drawing/ImageStream.cs b/MediaBrowser.Controller/Drawing/ImageStream.cs new file mode 100644 index 0000000000..353abaca33 --- /dev/null +++ b/MediaBrowser.Controller/Drawing/ImageStream.cs @@ -0,0 +1,28 @@ +using MediaBrowser.Model.Drawing; +using System; +using System.IO; + +namespace MediaBrowser.Controller.Drawing +{ + public class ImageStream : IDisposable + { + /// + /// Gets or sets the stream. + /// + /// The stream. + public Stream Stream { get; set; } + /// + /// Gets or sets the format. + /// + /// The format. + public ImageFormat Format { get; set; } + + public void Dispose() + { + if (Stream != null) + { + Stream.Dispose(); + } + } + } +} diff --git a/MediaBrowser.Controller/Dto/IDtoService.cs b/MediaBrowser.Controller/Dto/IDtoService.cs index 61b2caec0d..7c7ec56d50 100644 --- a/MediaBrowser.Controller/Dto/IDtoService.cs +++ b/MediaBrowser.Controller/Dto/IDtoService.cs @@ -22,7 +22,8 @@ namespace MediaBrowser.Controller.Dto /// /// The dto. /// The item. - void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item); + /// The fields. + void AttachPrimaryImageAspectRatio(IItemDto dto, IHasImages item, List fields); /// /// Gets the base item dto. @@ -34,6 +35,16 @@ namespace MediaBrowser.Controller.Dto /// Task{BaseItemDto}. BaseItemDto GetBaseItemDto(BaseItem item, List fields, User user = null, BaseItem owner = null); + /// + /// Gets the base item dto. + /// + /// The item. + /// The options. + /// The user. + /// The owner. + /// BaseItemDto. + BaseItemDto GetBaseItemDto(BaseItem item, DtoOptions options, User user = null, BaseItem owner = null); + /// /// Gets the chapter information dto. /// @@ -51,12 +62,13 @@ namespace MediaBrowser.Controller.Dto /// /// Gets the item by name dto. /// + /// /// The item. - /// The fields. + /// The options. /// The tagged items. /// The user. /// BaseItemDto. - BaseItemDto GetItemByNameDto(T item, List fields, List taggedItems, User user = null) + BaseItemDto GetItemByNameDto(T item, DtoOptions options, List taggedItems, User user = null) where T : BaseItem, IItemByName; } } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 990ea49f67..e01b8857f6 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -53,16 +53,6 @@ namespace MediaBrowser.Controller.Entities public static string ThemeSongFilename = "theme"; public static string ThemeVideosFolderName = "backdrops"; - public static List> ExtraSuffixes = new List> - { - new KeyValuePair("-trailer", ExtraType.Trailer), - new KeyValuePair("-deleted", ExtraType.DeletedScene), - new KeyValuePair("-behindthescenes", ExtraType.BehindTheScenes), - new KeyValuePair("-interview", ExtraType.Interview), - new KeyValuePair("-scene", ExtraType.Scene), - new KeyValuePair("-sample", ExtraType.Sample) - }; - public List ImageInfos { get; set; } [IgnoreDataMember] @@ -222,6 +212,20 @@ namespace MediaBrowser.Controller.Entities } } + [IgnoreDataMember] + public virtual string FileNameWithoutExtension + { + get + { + if (LocationType == LocationType.FileSystem) + { + return System.IO.Path.GetFileNameWithoutExtension(Path); + } + + return null; + } + } + /// /// This is just a helper for convenience /// @@ -361,6 +365,15 @@ namespace MediaBrowser.Controller.Entities } } + public bool ContainsPerson(string name) + { + if (string.IsNullOrWhiteSpace(name)) + { + throw new ArgumentNullException("name"); + } + return People.Any(i => string.Equals(i.Name, name, StringComparison.OrdinalIgnoreCase)); + } + public string GetInternalMetadataPath() { return GetInternalMetadataPath(ConfigurationManager.ApplicationPaths.InternalMetadataPath); @@ -593,118 +606,6 @@ namespace MediaBrowser.Controller.Entities return PlayAccess.Full; } - /// - /// Loads local trailers from the file system - /// - /// List{Video}. - private IEnumerable LoadLocalTrailers(List fileSystemChildren, IDirectoryService directoryService) - { - var files = fileSystemChildren.OfType() - .Where(i => string.Equals(i.Name, TrailerFolderName, StringComparison.OrdinalIgnoreCase)) - .SelectMany(i => i.EnumerateFiles("*", SearchOption.TopDirectoryOnly)) - .ToList(); - - var extraTypes = new List { ExtraType.Trailer }; - var suffixes = ExtraSuffixes.Where(i => extraTypes.Contains(i.Value)) - .Select(i => i.Key) - .ToList(); - - files.AddRange(fileSystemChildren.OfType() - .Where(i => - { - var nameEithoutExtension = FileSystem.GetFileNameWithoutExtension(i); - - if (!suffixes.Any(s => nameEithoutExtension.EndsWith(s, StringComparison.OrdinalIgnoreCase))) - { - return false; - } - - return !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase); - })); - - return LibraryManager.ResolvePaths(files, directoryService, null).Select(video => - { - // Try to retrieve it from the db. If we don't find it, use the resolved version - var dbItem = LibraryManager.GetItemById(video.Id) as Trailer; - - if (dbItem != null) - { - video = dbItem; - } - - if (video != null) - { - video.ExtraType = ExtraType.Trailer; - } - - return video; - - // Sort them so that the list can be easily compared for changes - }).OrderBy(i => i.Path).ToList(); - } - - protected IEnumerable