From 4892fb4e95f982527769620595e924c364204310 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 28 Nov 2013 13:27:29 -0500 Subject: [PATCH] add specialized get seasons method --- .../BaseProgressiveStreamingService.cs | 82 ++++++++--------- MediaBrowser.Api/TvShowsService.cs | 90 ++++++++++++++++++- MediaBrowser.Controller/Entities/TV/Season.cs | 10 ++- MediaBrowser.Model/ApiClient/IApiClient.cs | 7 ++ MediaBrowser.Model/Querying/EpisodeQuery.cs | 19 ++++ .../MediaBrowser.Providers.csproj | 1 + .../UserRootFolderNameProvider.cs | 42 +++++++++ MediaBrowser.WebDashboard/ApiClient.js | 11 +++ MediaBrowser.WebDashboard/packages.config | 2 +- 9 files changed, 218 insertions(+), 46 deletions(-) create mode 100644 MediaBrowser.Providers/UserRootFolderNameProvider.cs diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index 0b7b48f47e..1f0853e08b 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -127,44 +127,44 @@ namespace MediaBrowser.Api.Playback.Progressive const string dlnaflags = ";DLNA.ORG_FLAGS=01500000000000000000000000000000"; - if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=MP3"; - } - else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=AAC_ISO"; - } - else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=WMABASE"; - } - else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=AVI"; - } - else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC"; - } - else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL"; - } - else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase)) - { - contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; - } - else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase)) - { - // ?? - contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; - } - else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase)) - { - // ?? - contentFeatures = ""; - } + //if (string.Equals(extension, ".mp3", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=MP3"; + //} + //else if (string.Equals(extension, ".aac", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=AAC_ISO"; + //} + //else if (string.Equals(extension, ".wma", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=WMABASE"; + //} + //else if (string.Equals(extension, ".avi", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=AVI"; + //} + //else if (string.Equals(extension, ".mp4", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=MPEG4_P2_SP_AAC"; + //} + //else if (string.Equals(extension, ".mpeg", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=MPEG_PS_PAL"; + //} + //else if (string.Equals(extension, ".wmv", StringComparison.OrdinalIgnoreCase)) + //{ + // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; + //} + //else if (string.Equals(extension, ".asf", StringComparison.OrdinalIgnoreCase)) + //{ + // // ?? + // contentFeatures = "DLNA.ORG_PN=WMVHIGH_BASE"; + //} + //else if (string.Equals(extension, ".mkv", StringComparison.OrdinalIgnoreCase)) + //{ + // // ?? + // contentFeatures = ""; + //} if (!string.IsNullOrEmpty(contentFeatures)) { @@ -206,10 +206,10 @@ namespace MediaBrowser.Api.Playback.Progressive var outputPath = GetOutputFilePath(state); var outputPathExists = File.Exists(outputPath); - //var isStatic = request.Static || - // (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive)); + var isStatic = request.Static || + (outputPathExists && !ApiEntryPoint.Instance.HasActiveTranscodingJob(outputPath, TranscodingJobType.Progressive)); - //AddDlnaHeaders(state, responseHeaders, isStatic); + AddDlnaHeaders(state, responseHeaders, isStatic); if (request.Static) { diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index b36005c1aa..95bde2d283 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -58,7 +58,7 @@ namespace MediaBrowser.Api } [Route("/Shows/{Id}/Episodes", "GET")] - [Api(Description = "Finds tv shows similar to a given one.")] + [Api(Description = "Gets episodes for a tv season")] public class GetEpisodes : IReturn, IHasItemFields { /// @@ -85,6 +85,34 @@ namespace MediaBrowser.Api public string ExcludeLocationTypes { get; set; } } + [Route("/Shows/{Id}/Seasons", "GET")] + [Api(Description = "Gets seasons for a tv series")] + public class GetSeasons : IReturn, IHasItemFields + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid UserId { get; set; } + + /// + /// Fields to return within the items, in addition to basic information + /// + /// The fields. + [ApiMember(Name = "Fields", Description = "Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimeted. Options: Budget, Chapters, CriticRatingSummary, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, OverviewHtml, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines, TrailerUrls", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string Fields { get; set; } + + [ApiMember(Name = "Id", Description = "The series id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid Id { get; set; } + + [ApiMember(Name = "ExcludeLocationTypes", Description = "Optional. If specified, results will be filtered based on LocationType. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string ExcludeLocationTypes { get; set; } + + [ApiMember(Name = "IsSpecialSeason", Description = "Optional. Filter by special season.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] + public bool? IsSpecialSeason { get; set; } + } + /// /// Class TvShowsService /// @@ -314,6 +342,64 @@ namespace MediaBrowser.Api return items; } + public object Get(GetSeasons request) + { + var user = _userManager.GetUserById(request.UserId); + + var series = _libraryManager.GetItemById(request.Id) as Series; + + var fields = request.GetItemFields().ToList(); + + var seasons = series.GetChildren(user, true) + .OfType(); + + var sortOrder = ItemSortBy.SortName; + + if (request.IsSpecialSeason.HasValue) + { + var val = request.IsSpecialSeason.Value; + + seasons = seasons.Where(i => i.IsSpecialSeason == val); + } + + var config = user.Configuration; + + if (!config.DisplayMissingEpisodes && !config.DisplayUnairedEpisodes) + { + seasons = seasons.Where(i => !i.IsMissingOrVirtualUnaired); + } + else + { + if (!config.DisplayMissingEpisodes) + { + seasons = seasons.Where(i => !i.IsMissingSeason); + } + if (!config.DisplayUnairedEpisodes) + { + seasons = seasons.Where(i => !i.IsVirtualUnaired); + } + } + + // ExcludeLocationTypes + if (!string.IsNullOrEmpty(request.ExcludeLocationTypes)) + { + var vals = request.ExcludeLocationTypes.Split(','); + seasons = seasons.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase)); + } + + seasons = _libraryManager.Sort(seasons, user, new[] { sortOrder }, SortOrder.Ascending) + .Cast(); + + var returnItems = seasons.Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToArray(); + + return new ItemsResult + { + TotalRecordCount = returnItems.Length, + Items = returnItems + }; + } + public object Get(GetEpisodes request) { var user = _userManager.GetUserById(request.UserId); @@ -351,7 +437,7 @@ namespace MediaBrowser.Api var vals = request.ExcludeLocationTypes.Split(','); episodes = episodes.Where(f => !vals.Contains(f.LocationType.ToString(), StringComparer.OrdinalIgnoreCase)); } - + episodes = _libraryManager.Sort(episodes, user, new[] { sortOrder }, SortOrder.Ascending) .Cast(); diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs index 97a09b7b55..218c9fa5b6 100644 --- a/MediaBrowser.Controller/Entities/TV/Season.cs +++ b/MediaBrowser.Controller/Entities/TV/Season.cs @@ -1,9 +1,9 @@ -using System.Linq; -using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities.TV @@ -172,5 +172,11 @@ namespace MediaBrowser.Controller.Entities.TV { get { return LocationType == Model.Entities.LocationType.Virtual && Children.OfType().All(i => i.IsVirtualUnaired || i.IsMissingEpisode); } } + + [IgnoreDataMember] + public bool IsSpecialSeason + { + get { return (IndexNumber ?? -1) == 0; } + } } } diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index ad82966048..16b3543ebd 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -231,6 +231,13 @@ namespace MediaBrowser.Model.ApiClient /// The query. /// Task{ItemsResult}. Task GetEpisodesAsync(EpisodeQuery query); + + /// + /// Gets the seasons asynchronous. + /// + /// The query. + /// Task{ItemsResult}. + Task GetSeasonsAsync(SeasonQuery query); /// /// Queries for items diff --git a/MediaBrowser.Model/Querying/EpisodeQuery.cs b/MediaBrowser.Model/Querying/EpisodeQuery.cs index ab9b246c8c..406ac9844f 100644 --- a/MediaBrowser.Model/Querying/EpisodeQuery.cs +++ b/MediaBrowser.Model/Querying/EpisodeQuery.cs @@ -20,4 +20,23 @@ namespace MediaBrowser.Model.Querying ExcludeLocationTypes = new LocationType[] { }; } } + + public class SeasonQuery + { + public string UserId { get; set; } + + public string SeriesId { get; set; } + + public LocationType[] ExcludeLocationTypes { get; set; } + + public ItemFields[] Fields { get; set; } + + public bool? IsSpecialSeason { get; set; } + + public SeasonQuery() + { + Fields = new ItemFields[] { }; + ExcludeLocationTypes = new LocationType[] { }; + } + } } diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 83e0246c53..c7298b4622 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -135,6 +135,7 @@ + diff --git a/MediaBrowser.Providers/UserRootFolderNameProvider.cs b/MediaBrowser.Providers/UserRootFolderNameProvider.cs new file mode 100644 index 0000000000..5130202139 --- /dev/null +++ b/MediaBrowser.Providers/UserRootFolderNameProvider.cs @@ -0,0 +1,42 @@ +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Logging; +using System; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Providers +{ + public class UserRootFolderNameProvider : BaseMetadataProvider + { + public UserRootFolderNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager) + : base(logManager, configurationManager) + { + } + + public override bool Supports(BaseItem item) + { + return item is UserRootFolder; + } + + public override Task FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) + { + var parentName = Path.GetFileNameWithoutExtension(item.Path); + + if (string.Equals(parentName, "default", StringComparison.OrdinalIgnoreCase)) + { + item.Name = "Media Library"; + } + + SetLastRefreshed(item, DateTime.UtcNow); + return TrueTaskResult; + } + + public override MetadataProviderPriority Priority + { + get { return MetadataProviderPriority.First; } + } + } +} diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 69f3f020cf..36476511ec 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -575,6 +575,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi }); }; + self.getSeasons = function (itemId, options) { + + var url = self.getUrl("Shows/" + itemId + "/Seasons", options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + self.getSimilarMovies = function (itemId, options) { var url = self.getUrl("Movies/" + itemId + "/Similar", options); diff --git a/MediaBrowser.WebDashboard/packages.config b/MediaBrowser.WebDashboard/packages.config index 35511052f4..25938a358a 100644 --- a/MediaBrowser.WebDashboard/packages.config +++ b/MediaBrowser.WebDashboard/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file